tests: Replace struct with closure
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-06-12 22:06:07 +02:00
parent bf49105619
commit 154a13ecfc
1 changed files with 8 additions and 11 deletions

View File

@ -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,
}