From 154a13ecfcda3eb1ad83b6fb597ec307f666c801 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Sun, 12 Jun 2022 22:06:07 +0200 Subject: [PATCH] tests: Replace struct with closure --- logs/pod_watcher_test.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/logs/pod_watcher_test.go b/logs/pod_watcher_test.go index fa7bf26..c4e09a7 100644 --- a/logs/pod_watcher_test.go +++ b/logs/pod_watcher_test.go @@ -90,25 +90,22 @@ func TestPodWatcherClose(t *testing.T) { assert.Equal(t, "[foo] it worked\n", buf.String()) } -type logReaderIterator struct { - rcs []io.ReadCloser -} - -func (f *logReaderIterator) next() io.ReadCloser { - var rc io.ReadCloser - rc, f.rcs = f.rcs[0], f.rcs[1:] - return rc +// makeReadCloserIterator returns a function which returns a function which +// iterates through each provided ReadCloser. +func makeReadCloserIterator(rcs ...io.ReadCloser) func() io.ReadCloser { + return func() (rc io.ReadCloser) { + rc, rcs = rcs[0], rcs[1:] + return + } } func TestPodWatcherRemovedPod(t *testing.T) { podsWatcher := watch.NewFake() - r1, w1 := io.Pipe() r2, w2 := io.Pipe() - it := logReaderIterator{[]io.ReadCloser{r1, r2}} clientset := mockClientset{ - getLogsReaderFunc: it.next, + getLogsReaderFunc: makeReadCloserIterator(r1, r2), getLogsStatusCode: http.StatusOK, podsWatcher: podsWatcher, }