From d3a92dd1da19d9e4593f929ff9e82bc800d73d5c Mon Sep 17 00:00:00 2001 From: Benjamen Keroack Date: Tue, 27 Nov 2018 13:55:21 -0800 Subject: [PATCH] fix unit tests Signed-off-by: Benjamen Keroack --- pkg/releasetesting/test_suite_test.go | 4 +++- pkg/tiller/release_content_test.go | 3 ++- pkg/tiller/release_history_test.go | 5 +++-- pkg/tiller/release_install_test.go | 31 +++++++++++++------------- pkg/tiller/release_rollback_test.go | 13 ++++++----- pkg/tiller/release_server_test.go | 6 +++-- pkg/tiller/release_status_test.go | 5 +++-- pkg/tiller/release_uninstall_test.go | 17 +++++++------- pkg/tiller/release_update_test.go | 32 ++++++++++++++------------- 9 files changed, 64 insertions(+), 52 deletions(-) diff --git a/pkg/releasetesting/test_suite_test.go b/pkg/releasetesting/test_suite_test.go index bf85e4207..624d8463f 100644 --- a/pkg/releasetesting/test_suite_test.go +++ b/pkg/releasetesting/test_suite_test.go @@ -312,7 +312,9 @@ func (rs mockStream) SendHeader(m metadata.MD) error { return nil } func (rs mockStream) SetTrailer(m metadata.MD) {} func (rs mockStream) SendMsg(v interface{}) error { return nil } func (rs mockStream) RecvMsg(v interface{}) error { return nil } -func (rs mockStream) Context() context.Context { return helm.NewContext() } +func (rs mockStream) Context() context.Context { + return helm.NewContext(context.Background()) +} type podSucceededKubeClient struct { tillerEnv.PrintingKubeClient diff --git a/pkg/tiller/release_content_test.go b/pkg/tiller/release_content_test.go index 4a29c5d3e..5a1a72031 100644 --- a/pkg/tiller/release_content_test.go +++ b/pkg/tiller/release_content_test.go @@ -19,12 +19,13 @@ package tiller import ( "testing" + "golang.org/x/net/context" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/proto/hapi/services" ) func TestGetReleaseContent(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() if err := rs.env.Releases.Create(rel); err != nil { diff --git a/pkg/tiller/release_history_test.go b/pkg/tiller/release_history_test.go index 58b7fad9a..7ac306dcb 100644 --- a/pkg/tiller/release_history_test.go +++ b/pkg/tiller/release_history_test.go @@ -20,6 +20,7 @@ import ( "reflect" "testing" + "golang.org/x/net/context" "k8s.io/helm/pkg/helm" rpb "k8s.io/helm/pkg/proto/hapi/release" tpb "k8s.io/helm/pkg/proto/hapi/services" @@ -77,7 +78,7 @@ func TestGetHistory_WithRevisions(t *testing.T) { // run tests for _, tt := range tests { - res, err := srv.GetHistory(helm.NewContext(), tt.req) + res, err := srv.GetHistory(helm.NewContext(context.Background()), tt.req) if err != nil { t.Fatalf("%s:\nFailed to get History of %q: %s", tt.desc, tt.req.Name, err) } @@ -104,7 +105,7 @@ func TestGetHistory_WithNoRevisions(t *testing.T) { srv.env.Releases.Create(rls) for _, tt := range tests { - res, err := srv.GetHistory(helm.NewContext(), tt.req) + res, err := srv.GetHistory(helm.NewContext(context.Background()), tt.req) if err != nil { t.Fatalf("%s:\nFailed to get History of %q: %s", tt.desc, tt.req.Name, err) } diff --git a/pkg/tiller/release_install_test.go b/pkg/tiller/release_install_test.go index f5e84d870..76a32a748 100644 --- a/pkg/tiller/release_install_test.go +++ b/pkg/tiller/release_install_test.go @@ -21,6 +21,7 @@ import ( "strings" "testing" + "golang.org/x/net/context" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/release" @@ -61,7 +62,7 @@ func TestHasCRDHook(t *testing.T) { } func TestInstallRelease(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest() @@ -115,7 +116,7 @@ func TestInstallRelease(t *testing.T) { } func TestInstallRelease_WithNotes(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest( @@ -175,7 +176,7 @@ func TestInstallRelease_WithNotes(t *testing.T) { } func TestInstallRelease_WithNotesRendered(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest( @@ -237,7 +238,7 @@ func TestInstallRelease_WithNotesRendered(t *testing.T) { func TestInstallRelease_TillerVersion(t *testing.T) { version.Version = "2.2.0" - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest( @@ -251,7 +252,7 @@ func TestInstallRelease_TillerVersion(t *testing.T) { func TestInstallRelease_WrongTillerVersion(t *testing.T) { version.Version = "2.2.0" - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest( @@ -269,7 +270,7 @@ func TestInstallRelease_WrongTillerVersion(t *testing.T) { } func TestInstallRelease_WithChartAndDependencyNotes(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest(withChart( @@ -301,7 +302,7 @@ func TestInstallRelease_WithChartAndDependencyNotes(t *testing.T) { } func TestInstallRelease_DryRun(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest(withDryRun(), @@ -353,7 +354,7 @@ func TestInstallRelease_DryRun(t *testing.T) { } func TestInstallRelease_NoHooks(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) @@ -369,7 +370,7 @@ func TestInstallRelease_NoHooks(t *testing.T) { } func TestInstallRelease_CRDInstallHook(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) @@ -396,7 +397,7 @@ func TestInstallRelease_CRDInstallHook(t *testing.T) { } func TestInstallRelease_DryRunCRDInstallHook(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) @@ -418,7 +419,7 @@ func TestInstallRelease_DryRunCRDInstallHook(t *testing.T) { } func TestInstallRelease_FailedHooks(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) rs.env.KubeClient = newHookFailingKubeClient() @@ -435,7 +436,7 @@ func TestInstallRelease_FailedHooks(t *testing.T) { } func TestInstallRelease_ReuseName(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rel.Info.Status.Code = release.Status_DELETED @@ -465,7 +466,7 @@ func TestInstallRelease_ReuseName(t *testing.T) { } func TestInstallRelease_KubeVersion(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest( @@ -478,7 +479,7 @@ func TestInstallRelease_KubeVersion(t *testing.T) { } func TestInstallRelease_WrongKubeVersion(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() req := installRequest( @@ -497,7 +498,7 @@ func TestInstallRelease_WrongKubeVersion(t *testing.T) { } func TestInstallRelease_Description(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) diff --git a/pkg/tiller/release_rollback_test.go b/pkg/tiller/release_rollback_test.go index 6aa895a63..d81b3cc19 100644 --- a/pkg/tiller/release_rollback_test.go +++ b/pkg/tiller/release_rollback_test.go @@ -20,13 +20,14 @@ import ( "strings" "testing" + "golang.org/x/net/context" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/proto/hapi/services" ) func TestRollbackRelease(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -137,7 +138,7 @@ func TestRollbackRelease(t *testing.T) { } func TestRollbackWithReleaseVersion(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.Log = t.Logf rs.env.Releases.Log = t.Logf @@ -185,7 +186,7 @@ func TestRollbackWithReleaseVersion(t *testing.T) { } func TestRollbackDeleted(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.Log = t.Logf rs.env.Releases.Log = t.Logf @@ -251,7 +252,7 @@ func TestRollbackDeleted(t *testing.T) { } func TestRollbackReleaseNoHooks(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rel.Hooks = []*release.Hook{ @@ -287,7 +288,7 @@ func TestRollbackReleaseNoHooks(t *testing.T) { } func TestRollbackReleaseFailure(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -320,7 +321,7 @@ func TestRollbackReleaseFailure(t *testing.T) { } func TestRollbackReleaseWithCustomDescription(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) diff --git a/pkg/tiller/release_server_test.go b/pkg/tiller/release_server_test.go index d94ea2eeb..2f6e26081 100644 --- a/pkg/tiller/release_server_test.go +++ b/pkg/tiller/release_server_test.go @@ -521,7 +521,7 @@ func (l *mockListServer) Send(res *services.ListReleasesResponse) error { return nil } -func (l *mockListServer) Context() context.Context { return helm.NewContext() } +func (l *mockListServer) Context() context.Context { return helm.NewContext(context.Background()) } func (l *mockListServer) SendMsg(v interface{}) error { return nil } func (l *mockListServer) RecvMsg(v interface{}) error { return nil } func (l *mockListServer) SendHeader(m metadata.MD) error { return nil } @@ -538,7 +538,9 @@ func (rs mockRunReleaseTestServer) SendHeader(m metadata.MD) error { return nil func (rs mockRunReleaseTestServer) SetTrailer(m metadata.MD) {} func (rs mockRunReleaseTestServer) SendMsg(v interface{}) error { return nil } func (rs mockRunReleaseTestServer) RecvMsg(v interface{}) error { return nil } -func (rs mockRunReleaseTestServer) Context() context.Context { return helm.NewContext() } +func (rs mockRunReleaseTestServer) Context() context.Context { + return helm.NewContext(context.Background()) +} type mockHooksManifest struct { Metadata struct { diff --git a/pkg/tiller/release_status_test.go b/pkg/tiller/release_status_test.go index 69a710143..80cd6614a 100644 --- a/pkg/tiller/release_status_test.go +++ b/pkg/tiller/release_status_test.go @@ -19,13 +19,14 @@ package tiller import ( "testing" + "golang.org/x/net/context" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/proto/hapi/services" ) func TestGetReleaseStatus(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() if err := rs.env.Releases.Create(rel); err != nil { @@ -46,7 +47,7 @@ func TestGetReleaseStatus(t *testing.T) { } func TestGetReleaseStatusDeleted(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rel.Info.Status.Code = release.Status_DELETED diff --git a/pkg/tiller/release_uninstall_test.go b/pkg/tiller/release_uninstall_test.go index cb59b6bf5..5c52a0dd3 100644 --- a/pkg/tiller/release_uninstall_test.go +++ b/pkg/tiller/release_uninstall_test.go @@ -20,13 +20,14 @@ import ( "strings" "testing" + "golang.org/x/net/context" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/proto/hapi/services" ) func TestUninstallRelease(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) @@ -61,7 +62,7 @@ func TestUninstallRelease(t *testing.T) { } func TestUninstallPurgeRelease(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -90,7 +91,7 @@ func TestUninstallPurgeRelease(t *testing.T) { if res.Release.Info.Deleted.Seconds <= 0 { t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds) } - rels, err := rs.GetHistory(helm.NewContext(), &services.GetHistoryRequest{Name: "angry-panda"}) + rels, err := rs.GetHistory(helm.NewContext(context.Background()), &services.GetHistoryRequest{Name: "angry-panda"}) if err != nil { t.Fatal(err) } @@ -100,7 +101,7 @@ func TestUninstallPurgeRelease(t *testing.T) { } func TestUninstallPurgeDeleteRelease(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) @@ -125,7 +126,7 @@ func TestUninstallPurgeDeleteRelease(t *testing.T) { } func TestUninstallReleaseWithKeepPolicy(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() name := "angry-bunny" rs.env.Releases.Create(releaseWithKeepStub(name)) @@ -157,7 +158,7 @@ func TestUninstallReleaseWithKeepPolicy(t *testing.T) { } func TestUninstallReleaseNoHooks(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) @@ -178,7 +179,7 @@ func TestUninstallReleaseNoHooks(t *testing.T) { } func TestUninstallReleaseCustomDescription(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rs.env.Releases.Create(releaseStub()) @@ -199,7 +200,7 @@ func TestUninstallReleaseCustomDescription(t *testing.T) { } func TestUninstallReleaseObjectNotFoundError(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() manifest := `kind: ConfigMap diff --git a/pkg/tiller/release_update_test.go b/pkg/tiller/release_update_test.go index ea1c88f62..02a5a914a 100644 --- a/pkg/tiller/release_update_test.go +++ b/pkg/tiller/release_update_test.go @@ -22,17 +22,19 @@ import ( "testing" "github.com/golang/protobuf/proto" + "golang.org/x/net/context" + + "reflect" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/proto/hapi/services" - "reflect" ) func TestUpdateRelease(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -105,7 +107,7 @@ func TestUpdateRelease(t *testing.T) { } } func TestUpdateRelease_ResetValues(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -132,7 +134,7 @@ func TestUpdateRelease_ResetValues(t *testing.T) { } func TestUpdateRelease_ReuseValuesWithNoValues(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() installReq := &services.InstallReleaseRequest{ @@ -171,7 +173,7 @@ func TestUpdateRelease_ReuseValuesWithNoValues(t *testing.T) { } func TestUpdateRelease_NestedReuseValues(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() installReq := &services.InstallReleaseRequest{ @@ -237,7 +239,7 @@ root: // This is a regression test for bug found in issue #3655 func TestUpdateRelease_ComplexReuseValues(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() installReq := &services.InstallReleaseRequest{ @@ -337,7 +339,7 @@ func TestUpdateRelease_ComplexReuseValues(t *testing.T) { } func TestUpdateRelease_ReuseValues(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -375,7 +377,7 @@ func TestUpdateRelease_ReuseValues(t *testing.T) { func TestUpdateRelease_ResetReuseValues(t *testing.T) { // This verifies that when both reset and reuse are set, reset wins. - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -404,7 +406,7 @@ func TestUpdateRelease_ResetReuseValues(t *testing.T) { } func TestUpdateReleaseFailure(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -448,7 +450,7 @@ func TestUpdateReleaseFailure(t *testing.T) { } func TestUpdateReleaseFailure_Force(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := namedReleaseStub("forceful-luke", release.Status_FAILED) rs.env.Releases.Create(rel) @@ -492,7 +494,7 @@ func TestUpdateReleaseFailure_Force(t *testing.T) { } func TestUpdateReleaseNoHooks(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -521,7 +523,7 @@ func TestUpdateReleaseNoHooks(t *testing.T) { } func TestUpdateReleaseNoChanges(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -539,7 +541,7 @@ func TestUpdateReleaseNoChanges(t *testing.T) { } func TestUpdateReleaseCustomDescription(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -563,7 +565,7 @@ func TestUpdateReleaseCustomDescription(t *testing.T) { } func TestUpdateReleaseCustomDescription_Force(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := releaseStub() rs.env.Releases.Create(rel) @@ -588,7 +590,7 @@ func TestUpdateReleaseCustomDescription_Force(t *testing.T) { } func TestUpdateReleasePendingInstall_Force(t *testing.T) { - c := helm.NewContext() + c := helm.NewContext(context.Background()) rs := rsFixture() rel := namedReleaseStub("forceful-luke", release.Status_PENDING_INSTALL) rs.env.Releases.Create(rel)