From 3916717ed71fabbbc88c1061113383a6d4672abf Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 11 Mar 2022 23:18:00 -0600 Subject: [PATCH] Test kubernetes TailContainer happy path We can't really test failed responses, but this is a bit better. --- runtime/kubernetes/container_test.go | 53 +++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/runtime/kubernetes/container_test.go b/runtime/kubernetes/container_test.go index 07728893..fc911699 100644 --- a/runtime/kubernetes/container_test.go +++ b/runtime/kubernetes/container_test.go @@ -211,17 +211,54 @@ func TestKubernetes_SetupContainer(t *testing.T) { } } -// TODO: implement this once they resolve the bug -// -// https://github.com/kubernetes/kubernetes/issues/84203 func TestKubernetes_TailContainer(t *testing.T) { - // Unfortunately, we can't implement this test using - // the native Kubernetes fake. This is because there - // is a bug in that code where an "empty" request is - // always returned when calling the GetLogs function. + // Unfortunately, we can't test failures using the native Kubernetes fake. + // k8s.client-go v0.19.0 added a mock GetLogs() response so that + // it no longer panics with an "empty" request, but now it always returns + // a successful response with Body: "fake logs". // // https://github.com/kubernetes/kubernetes/issues/84203 - // fixed in k8s.io/client-go v0.19.0; we already have v0.22.2 + // https://github.com/kubernetes/kubernetes/pulls/91485 + // + // setup types + _engine, err := NewMock(_pod) + if err != nil { + t.Errorf("unable to create runtime engine: %v", err) + } + + // setup tests + tests := []struct { + failure bool + container *pipeline.Container + }{ + { + failure: false, + container: _container, + }, + // We cannot test failures, because the mock GetLogs() always + // returns a successful response with logs body: "fake logs" + //{ + // failure: true, + // container: new(pipeline.Container), + //}, + } + + // run tests + for _, test := range tests { + _, err = _engine.TailContainer(context.Background(), test.container) + + if test.failure { + if err == nil { + t.Errorf("TailContainer should have returned err") + } + + continue + } + + if err != nil { + t.Errorf("TailContainer returned err: %v", err) + } + } } func TestKubernetes_WaitContainer(t *testing.T) {