From 675fa4b45b8e40de53ed256df73a304966e73620 Mon Sep 17 00:00:00 2001 From: jingfangliu Date: Mon, 22 Jul 2019 13:42:56 -0700 Subject: [PATCH] fix lint errors --- internal/pkg/apply/apply_test.go | 2 +- internal/pkg/client/unstructured/helpers.go | 4 ---- internal/pkg/client/unstructured/helpers_test.go | 1 - internal/pkg/delete/delete_test.go | 1 + internal/pkg/resourceconfig/resourceconfig.go | 14 ++++++++++++-- internal/pkg/resourceconfig/resourceconfig_test.go | 5 ++++- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/internal/pkg/apply/apply_test.go b/internal/pkg/apply/apply_test.go index bc855bf..053a33c 100644 --- a/internal/pkg/apply/apply_test.go +++ b/internal/pkg/apply/apply_test.go @@ -281,7 +281,7 @@ func TestApplyWithPresenceAnnotation(t *testing.T) { assert.NoError(t, err) assert.Equal(t, false, exist) - r, err = a.Do() + _, err = a.Do() assert.NoError(t, err) exist, err = util.ObjectExist(a.DynamicClient, context.Background(), liveService) assert.NoError(t, err) diff --git a/internal/pkg/client/unstructured/helpers.go b/internal/pkg/client/unstructured/helpers.go index 9001b1b..a1e6fb1 100644 --- a/internal/pkg/client/unstructured/helpers.go +++ b/internal/pkg/client/unstructured/helpers.go @@ -21,10 +21,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -func jsonPath(fields []string) string { - return "." + strings.Join(fields, ".") -} - // ObjWithConditions Represent meta object with status.condition array type ObjWithConditions struct { // Status as expected to be present in most compliant kubernetes resources diff --git a/internal/pkg/client/unstructured/helpers_test.go b/internal/pkg/client/unstructured/helpers_test.go index 601437a..8bf657f 100644 --- a/internal/pkg/client/unstructured/helpers_test.go +++ b/internal/pkg/client/unstructured/helpers_test.go @@ -20,7 +20,6 @@ import ( helperu "sigs.k8s.io/cli-experimental/internal/pkg/client/unstructured" ) -var emptyObj = map[string]interface{}{} var testObj = map[string]interface{}{ "f1": map[string]interface{}{ "f2": map[string]interface{}{ diff --git a/internal/pkg/delete/delete_test.go b/internal/pkg/delete/delete_test.go index c55c318..72d9735 100644 --- a/internal/pkg/delete/delete_test.go +++ b/internal/pkg/delete/delete_test.go @@ -519,6 +519,7 @@ func TestDeleteWithPresenceNoInventory(t *testing.T) { // Then run delete // Confirm that the service is deleted _, err = d.Do() + assert.NoError(t, err) exist, err = util.ObjectExist(a.DynamicClient, context.Background(), liveService) assert.NoError(t, err) assert.Equal(t, false, exist) diff --git a/internal/pkg/resourceconfig/resourceconfig.go b/internal/pkg/resourceconfig/resourceconfig.go index 11ca698..539471a 100644 --- a/internal/pkg/resourceconfig/resourceconfig.go +++ b/internal/pkg/resourceconfig/resourceconfig.go @@ -16,6 +16,7 @@ package resourceconfig import ( "bytes" "io/ioutil" + "log" "os" "path/filepath" "sigs.k8s.io/kustomize/k8sdeps/validator" @@ -68,7 +69,11 @@ func (p *KustomizeProvider) getKustTarget(path string) (ifc.Loader, *target.Kust // IsSupported checks if the path is supported by KustomizeProvider func (p *KustomizeProvider) IsSupported(path string) bool { ldr, _, err := p.getKustTarget(path) - defer ldr.Cleanup() + defer func() { + if err := ldr.Cleanup(); err != nil { + log.Fatal("failed to clean up the loader") + } + }() if err != nil { return false @@ -82,7 +87,12 @@ func (p *KustomizeProvider) GetConfig(path string) ([]*unstructured.Unstructured if err != nil { return nil, err } - defer ldr.Cleanup() + defer func() { + if err := ldr.Cleanup(); err != nil { + log.Fatal("failed to clean up the loader") + } + }() + rm, err := kt.MakeCustomizedResMap() if err != nil { return nil, err diff --git a/internal/pkg/resourceconfig/resourceconfig_test.go b/internal/pkg/resourceconfig/resourceconfig_test.go index e24d9be..7418662 100644 --- a/internal/pkg/resourceconfig/resourceconfig_test.go +++ b/internal/pkg/resourceconfig/resourceconfig_test.go @@ -63,7 +63,8 @@ func TestKustomizeProvider2(t *testing.T) { assert.NotEmpty(t, pobject) assert.NotNil(t, pobject) inv := inventory.NewInventory() - inv.LoadFromAnnotation(pobject[1].GetAnnotations()) + err = inv.LoadFromAnnotation(pobject[1].GetAnnotations()) + assert.NoError(t, err) assert.Equal(t, len(inv.Current), 1) } @@ -189,6 +190,8 @@ func TestRawConfigFileProvider(t *testing.T) { assert.Equal(t, expected[0], resources[0]) b = cp.IsSupported(subdir) + assert.Equal(t, b, true) + assert.Equal(t, b, true) resources, err = cp.GetConfig(subdir) assert.NoError(t, err) assert.Equal(t, len(resources), 2)