Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(kubernetes): Test TailContainer happy path #289

Merged
merged 3 commits into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions runtime/kubernetes/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,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) {
Expand Down