From a52f5678dc4d82f09acb5791655df19bc005d022 Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Mon, 23 Dec 2024 17:02:17 -0800 Subject: [PATCH 1/5] Tech-Debt: Increase coverage - 100% coverage for clientdiscovery_handler Signed-off-by: Adil Fulara --- .../clusters/clientdiscovery_handler_test.go | 407 ++++++++++++------ admiral/pkg/clusters/handler_test.go | 44 ++ admiral/pkg/test/mock.go | 23 +- 3 files changed, 342 insertions(+), 132 deletions(-) diff --git a/admiral/pkg/clusters/clientdiscovery_handler_test.go b/admiral/pkg/clusters/clientdiscovery_handler_test.go index 55e047e14..44f967228 100644 --- a/admiral/pkg/clusters/clientdiscovery_handler_test.go +++ b/admiral/pkg/clusters/clientdiscovery_handler_test.go @@ -2,19 +2,21 @@ package clusters import ( "context" + "errors" + argo "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/model" "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/v1alpha1" + commonUtil "github.com/istio-ecosystem/admiral/admiral/pkg/util" "github.com/stretchr/testify/assert" + coreV1 "k8s.io/api/core/v1" + metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" "testing" "time" - argo "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" "github.com/istio-ecosystem/admiral/admiral/pkg/client/loader" "github.com/istio-ecosystem/admiral/admiral/pkg/controller/admiral" "github.com/istio-ecosystem/admiral/admiral/pkg/controller/common" "github.com/istio-ecosystem/admiral/admiral/pkg/test" - coreV1 "k8s.io/api/core/v1" - metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/rest" ) @@ -22,157 +24,304 @@ func TestClientDiscoveryHandler_Added(t *testing.T) { //Struct of test case info. Name is required. const ( namespace = "namespace" - namespace_no_deps = "namespace-no-deps" + namespaceNoDeps = "namespace-no-deps" namespaceForRollout = "rollout-namespace" cluster1 = "cluster1" cluster2 = "cluster2" - cluster3 = "cluster3" identity1 = "identity1" identity2 = "identity2" - identity3 = "identity3" identity4 = "identity4" ) var ( - stop = make(chan struct{}) - config = rest.Config{ - Host: "localhost", - } - matchLabel = map[string]string{ - "app": "test", - } - labelSelector = metaV1.LabelSelector{ - MatchLabels: matchLabel, - } - dep = v1alpha1.Dependency{ - Spec: model.Dependency{ - Source: identity1, - Destinations: []string{identity2}, - }, - } - rollout = argo.Rollout{ - Spec: argo.RolloutSpec{ - Selector: &labelSelector, - Strategy: argo.RolloutStrategy{ - BlueGreen: &argo.BlueGreenStrategy{}, - }, - Template: coreV1.PodTemplateSpec{ - ObjectMeta: metaV1.ObjectMeta{Annotations: map[string]string{ - "sidecar.istio.io/inject": "true", - "identity": identity1, - }, Labels: map[string]string{ - "env": "stage", - }}, - }, - }, - ObjectMeta: metaV1.ObjectMeta{ - Namespace: namespaceForRollout, - }, - } - objRolloutNamespace = &common.K8sObject{ - Namespace: namespaceForRollout, - Name: "obj-rollout-namespace", - Annotations: map[string]string{"identity": identity1}, - } - objValid = &common.K8sObject{ - Namespace: namespace, - Name: "obj", - Annotations: map[string]string{"identity": identity1}, - } - objValidWithNoDeps = &common.K8sObject{ - Namespace: namespace_no_deps, - Name: "obj-no-deps", - Annotations: map[string]string{"identity": identity4}, - } + stop = make(chan struct{}) ) - setupForHandlerTests(true) - - depController, err := admiral.NewDependencyController(stop, &test.MockDependencyHandler{}, loader.FakeKubeconfigPath, "", time.Second*time.Duration(300), loader.GetFakeClientLoader()) - if err != nil { - t.Fatalf("failed to initialize dependency controller, err: %v", err) - } - r, err := admiral.NewRolloutsController(stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300), loader.GetFakeClientLoader()) - if err != nil { - t.Fatalf("failed to initialize rollout controller, err: %v", err) - } - d, err := admiral.NewDeploymentController(stop, &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300), loader.GetFakeClientLoader()) - if err != nil { - t.Fatalf("failed to initialize rollout controller, err: %v", err) - } - - rcCluster1 := &RemoteController{ - RolloutController: r, - DeploymentController: d, + type args struct { + obj *common.K8sObject + options []Option + rollout *argo.Rollout + dep *v1alpha1.Dependency + readOnly bool + disableCache bool + admiralReadyOnly bool + depCtrlAddErr error } - rcCluster2 := &RemoteController{ - RolloutController: r, - DeploymentController: d, + type want struct { + identityClusterNSCacheLen int + partitionIdentityCacheLen int + err error + depCtrlAddCalled int } - ctx := context.Background() - - remoteRegistry := NewRemoteRegistry(context.TODO(), common.AdmiralParams{}) - remoteRegistry.DependencyController = depController - remoteRegistry.remoteControllers[cluster1] = rcCluster1 - remoteRegistry.remoteControllers[cluster2] = rcCluster2 - - remoteRegistry.AdmiralCache = &AdmiralCache{ - IdentityClusterCache: common.NewMapOfMaps(), - IdentityClusterNamespaceCache: common.NewMapOfMapOfMaps(), - PartitionIdentityCache: common.NewMap(), - } - - err = r.Added(ctx, &rollout) - assert.NoError(t, err) - rolloutFromCache := r.Cache.Get(identity1, "stage") - assert.NotNil(t, rolloutFromCache) - err = depController.Added(ctx, &dep) - assert.NoError(t, err) - depFromCache := depController.Cache.Get(identity1) - assert.NotNil(t, depFromCache) - testCases := []struct { - name string - obj *common.K8sObject - rr *RemoteRegistry - clusterName string - expectedError error + name string + args args + want want }{ { - name: "No global identifier on obj results in no errors", - obj: &common.K8sObject{Annotations: map[string]string{}, Labels: map[string]string{}}, - rr: remoteRegistry, - clusterName: cluster1, - expectedError: nil, - }, { + name: "No global identifier on obj results in no errors", + args: args{ + obj: &common.K8sObject{Annotations: map[string]string{}, Labels: map[string]string{}}, + }, + want: want{}, + }, + { + name: "Admiral Cache is not initialized returns error", + args: args{ + obj: &common.K8sObject{ + Namespace: namespaceForRollout, + Name: "obj-rollout-namespace", + Annotations: map[string]string{"identity": identity1}, + Labels: map[string]string{ + "admiral.io/identityPartition": "test", + }, + }, + disableCache: true, + }, + want: want{ + err: errors.New("op=Add type=Job name=obj-rollout-namespace cluster=cluster1 error=task=Add name=obj-rollout-namespace namespace=rollout-namespace cluster=cluster1 message=processing skipped as Admiral cache is not initialized for identity=identity1"), + }, + }, + { + name: "Admiral in Read Only mode updates SW aware caches", + args: args{ + obj: &common.K8sObject{ + Namespace: namespaceForRollout, + Name: "obj-rollout-namespace", + Annotations: map[string]string{"identity": identity1}, + Labels: map[string]string{ + "admiral.io/identityPartition": "test", + }, + }, + options: []Option{argoEnabled(true), swAwareNsCache(true)}, + readOnly: true, + }, + want: want{ + identityClusterNSCacheLen: 1, + partitionIdentityCacheLen: 1, + }, + }, + { + name: "Admiral during cache warmup returns early", + args: args{ + obj: &common.K8sObject{ + Namespace: namespaceForRollout, + Name: "obj-rollout-namespace", + Annotations: map[string]string{"identity": identity1}, + Labels: map[string]string{ + "admiral.io/identityPartition": "test", + }, + }, + options: []Option{ + argoEnabled(true), + swAwareNsCache(true), + cacheWarmupTime(1 * time.Minute), + }, + }, + want: want{ + identityClusterNSCacheLen: 1, + partitionIdentityCacheLen: 1, + }, + }, + { name: "Rollout with same identifier present in the namespace should " + "return without processing and no errors", - obj: objRolloutNamespace, - rr: remoteRegistry, - clusterName: cluster1, - expectedError: nil, - }, { - name: "Valid client with no dependency record returns without processing", - obj: objValidWithNoDeps, - rr: remoteRegistry, - clusterName: cluster1, - expectedError: nil, - }, { - name: "Valid client with valid dependency record results in writing all dependencies endpoints to this cluster", - obj: objValid, - rr: remoteRegistry, - clusterName: cluster1, - expectedError: nil, + args: args{ + obj: &common.K8sObject{ + Namespace: namespaceForRollout, + Name: "obj-rollout-namespace", + Annotations: map[string]string{"identity": identity1}, + Labels: map[string]string{ + "admiral.io/identityPartition": "test", + }, + }, + rollout: &argo.Rollout{ + Spec: argo.RolloutSpec{ + Selector: &metaV1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "test", + }, + }, + Strategy: argo.RolloutStrategy{ + BlueGreen: &argo.BlueGreenStrategy{}, + }, + Template: coreV1.PodTemplateSpec{ + ObjectMeta: metaV1.ObjectMeta{Annotations: map[string]string{ + "sidecar.istio.io/inject": "true", + "identity": identity1, + }, Labels: map[string]string{ + "env": "stage", + }}, + }, + }, + ObjectMeta: metaV1.ObjectMeta{ + Namespace: namespaceForRollout, + }, + }, + options: []Option{argoEnabled(true), swAwareNsCache(true), dependencyProcessing(true)}, + }, + want: want{ + identityClusterNSCacheLen: 1, + partitionIdentityCacheLen: 1, + }, + }, + { + name: "Valid client with no dependency record returns without processing", + args: args{ + obj: &common.K8sObject{ + Namespace: namespaceNoDeps, + Name: "obj-no-deps", + Annotations: map[string]string{"identity": identity4}, + Labels: map[string]string{ + "admiral.io/identityPartition": "test", + }, + }, + options: []Option{ + argoEnabled(true), + swAwareNsCache(true)}, + }, + want: want{ + identityClusterNSCacheLen: 1, + partitionIdentityCacheLen: 1, + }, + }, + { + name: "Valid client with valid dependency record results in calling depHandler Added()", + args: args{ + obj: &common.K8sObject{ + Namespace: namespace, + Name: "obj", + Annotations: map[string]string{"identity": identity1}, + Labels: map[string]string{ + "admiral.io/identityPartition": "test", + }, + }, + options: []Option{ + argoEnabled(true), + }, + dep: &v1alpha1.Dependency{ + Spec: model.Dependency{ + Source: identity1, + Destinations: []string{identity2}, + }, + }, + }, + want: want{ + depCtrlAddCalled: 1, + }, + }, + { + name: "Valid client with valid dependency record with error in calling depHandler Added() returns error", + args: args{ + obj: &common.K8sObject{ + Namespace: namespace, + Name: "obj", + Annotations: map[string]string{"identity": identity1}, + Labels: map[string]string{ + "admiral.io/identityPartition": "test", + }, + }, + options: []Option{ + argoEnabled(true), + }, + dep: &v1alpha1.Dependency{ + Spec: model.Dependency{ + Source: identity1, + Destinations: []string{identity2}, + }, + }, + depCtrlAddErr: errors.New("oops"), + }, + want: want{ + depCtrlAddCalled: 1, + err: errors.New("op=Add type=Job name=obj cluster=cluster1 error=op=Process type= name=obj namespace=namespace cluster=cluster1 message=Error processing client discovery"), + }, }, } //Run the test for every provided case for _, c := range testCases { t.Run(c.name, func(t *testing.T) { - result := HandleEventForClientDiscovery(ctx, admiral.Add, c.obj, remoteRegistry, c.clusterName) - if c.expectedError == nil && result != nil { - t.Fatalf("Expected error %v got %v", c.expectedError, result) + + // Given + ctx := context.Background() + InitAdmiralForTesting(c.args.options...) + + mockDepCtrl := test.NewMockDependencyHandler(c.args.depCtrlAddErr, nil, nil) + depController, err := admiral.NewDependencyController(stop, mockDepCtrl, loader.FakeKubeconfigPath, "", time.Second*time.Duration(300), loader.GetFakeClientLoader()) + if err != nil { + t.Fatalf("failed to initialize dependency controller, err: %v", err) + } + config := rest.Config{ + Host: "localhost", + } + r, err := admiral.NewRolloutsController(stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300), loader.GetFakeClientLoader()) + if err != nil { + t.Fatalf("failed to initialize rollout controller, err: %v", err) + } + if c.args.rollout != nil { + entry := &admiral.RolloutClusterEntry{ + Identity: "test." + identity1, + Rollouts: map[string]*admiral.RolloutItem{identity1: {Rollout: c.args.rollout}}, + } + r.Cache.Put(entry) + err = r.Added(ctx, c.args.rollout) + assert.NoError(t, err) + } + if c.args.dep != nil { + depController.Cache.Put(c.args.dep) + } + d, err := admiral.NewDeploymentController(stop, &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300), loader.GetFakeClientLoader()) + if err != nil { + t.Fatalf("failed to initialize rollout controller, err: %v", err) + } + + rcCluster1 := &RemoteController{ + RolloutController: r, + DeploymentController: d, + } + + rcCluster2 := &RemoteController{ + RolloutController: r, + DeploymentController: d, + } + + rr := NewRemoteRegistry(context.TODO(), common.AdmiralParams{}) + rr.DependencyController = depController + rr.remoteControllers[cluster1] = rcCluster1 + rr.remoteControllers[cluster2] = rcCluster2 + + rr.AdmiralCache = &AdmiralCache{ + IdentityClusterCache: common.NewMapOfMaps(), + IdentityClusterNamespaceCache: common.NewMapOfMapOfMaps(), + PartitionIdentityCache: common.NewMap(), + } + + commonUtil.CurrentAdmiralState.ReadOnly = c.args.readOnly + if c.args.disableCache { + rr.AdmiralCache = nil + } + + h := &ClientDiscoveryHandler{ClusterID: cluster1, RemoteRegistry: rr} + // When + result := h.Added(ctx, c.args.obj) + + // Then + if c.want.err != nil && assert.Error(t, result) { + // error validation + assert.Equal(t, result, c.want.err) + } else { + assert.Equal(t, c.want.partitionIdentityCacheLen, rr.AdmiralCache.PartitionIdentityCache.Len()) + assert.Equal(t, c.want.identityClusterNSCacheLen, rr.AdmiralCache.IdentityClusterNamespaceCache.Len()) + if c.args.rollout != nil { + rolloutFromCache := r.Cache.Get(identity1, "stage") + assert.NotNil(t, rolloutFromCache) + } + } + + if c.want.depCtrlAddCalled > 0 { + assert.Equal(t, c.want.depCtrlAddCalled, mockDepCtrl.AddedCnt) } }) } diff --git a/admiral/pkg/clusters/handler_test.go b/admiral/pkg/clusters/handler_test.go index ab817f8e4..5056ec229 100644 --- a/admiral/pkg/clusters/handler_test.go +++ b/admiral/pkg/clusters/handler_test.go @@ -21,6 +21,50 @@ import ( "k8s.io/client-go/rest" ) +type Option func(params *common.AdmiralParams) + +func argoEnabled(enabled bool) Option { + return func(params *common.AdmiralParams) { + params.ArgoRolloutsEnabled = enabled + } +} + +func swAwareNsCache(enabled bool) Option { + return func(params *common.AdmiralParams) { + params.EnableSWAwareNSCaches = enabled + } +} + +func dependencyProcessing(enabled bool) Option { + return func(params *common.AdmiralParams) { + params.EnableDependencyProcessing = enabled + } +} + +func cacheWarmupTime(duration time.Duration) Option { + return func(params *common.AdmiralParams) { + params.CacheReconcileDuration = duration + } +} + +func InitAdmiralForTesting(options ...Option) { + common.ResetSync() + params := common.AdmiralParams{ + LabelSet: &common.LabelSet{ + WorkloadIdentityKey: "identity", + EnvKey: "admiral.io/env", + AdmiralCRDIdentityLabel: "identity", + DeploymentAnnotation: "sidecar.istio.io/inject", + AdmiralIgnoreLabel: "admiral-ignore", + IdentityPartitionKey: "admiral.io/identityPartition", + }, + } + for _, option := range options { + option(¶ms) + } + common.InitializeConfig(params) +} + func admiralParamsForHandlerTests(argoEnabled bool) common.AdmiralParams { return common.AdmiralParams{ ArgoRolloutsEnabled: argoEnabled, diff --git a/admiral/pkg/test/mock.go b/admiral/pkg/test/mock.go index 95ee2b516..9a2de6aba 100644 --- a/admiral/pkg/test/mock.go +++ b/admiral/pkg/test/mock.go @@ -139,18 +139,35 @@ func (m *MockNodeHandler) Deleted(obj *k8sCoreV1.Node) { } type MockDependencyHandler struct { + AddedCnt int + UpdatedCnt int + DeletedCnt int + addedErr error + updatedErr error + deletedErr error +} + +func NewMockDependencyHandler(addErr error, updateErr error, deleteError error) *MockDependencyHandler { + return &MockDependencyHandler{ + addedErr: addErr, + updatedErr: updateErr, + deletedErr: deleteError, + } } func (m *MockDependencyHandler) Added(ctx context.Context, obj *admiralV1.Dependency) error { - return nil + m.AddedCnt++ + return m.addedErr } func (m *MockDependencyHandler) Updated(ctx context.Context, obj *admiralV1.Dependency) error { - return nil + m.UpdatedCnt++ + return m.updatedErr } func (m *MockDependencyHandler) Deleted(ctx context.Context, obj *admiralV1.Dependency) error { - return nil + m.DeletedCnt++ + return m.deletedErr } type MockGlobalTrafficHandler struct { From 640ebff9f1a45d755689c4c939556c6d5760881f Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Thu, 2 Jan 2025 10:32:22 -0800 Subject: [PATCH 2/5] Tech-Debt: Increase coverage - Coverage for ShardController_Get Signed-off-by: Adil Fulara --- admiral/pkg/controller/admiral/shard_test.go | 82 ++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/admiral/pkg/controller/admiral/shard_test.go b/admiral/pkg/controller/admiral/shard_test.go index 52818a39d..4265e147c 100644 --- a/admiral/pkg/controller/admiral/shard_test.go +++ b/admiral/pkg/controller/admiral/shard_test.go @@ -5,13 +5,16 @@ import ( "errors" "fmt" admiralapiv1 "github.com/istio-ecosystem/admiral-api/pkg/apis/admiral/v1" + fake2 "github.com/istio-ecosystem/admiral-api/pkg/client/clientset/versioned/typed/admiral/v1/fake" "github.com/istio-ecosystem/admiral/admiral/pkg/client/loader" "github.com/istio-ecosystem/admiral/admiral/pkg/controller/common" "github.com/istio-ecosystem/admiral/admiral/pkg/test" "github.com/stretchr/testify/assert" coreV1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/fake" + k8stesting "k8s.io/client-go/testing" "testing" ) @@ -103,6 +106,85 @@ func TestShardController_Deleted(t *testing.T) { } } +func TestShardController_Get(t *testing.T) { + + type args struct { + obj interface{} + retry bool + cacheItems map[string]*admiralapiv1.Shard + fakeClientResponse *admiralapiv1.Shard + } + + type want struct { + obj interface{} + err error + } + testCases := []struct { + name string + args args + want want + }{ + { + name: "K8s client not initialized returns error", + args: args{ + obj: nil, + }, + want: want{ + err: fmt.Errorf("kubernetes client is not initialized, txId=test"), + }, + }, + { + name: "lookup with retry", + args: args{ + obj: &admiralapiv1.Shard{ObjectMeta: v1.ObjectMeta{Name: "test"}}, + retry: true, + cacheItems: map[string]*admiralapiv1.Shard{ + "test": {ObjectMeta: v1.ObjectMeta{Name: "test"}}, + }, + }, + want: want{ + obj: &admiralapiv1.Shard{ObjectMeta: v1.ObjectMeta{Name: "test"}}, + }, + }, + { + name: "lookup without retry", + args: args{ + obj: &admiralapiv1.Shard{ObjectMeta: v1.ObjectMeta{Name: "test"}}, + cacheItems: map[string]*admiralapiv1.Shard{ + "test": {ObjectMeta: v1.ObjectMeta{Name: "test"}}, + }, + fakeClientResponse: &admiralapiv1.Shard{ObjectMeta: v1.ObjectMeta{Name: "test"}}, + }, + want: want{ + obj: &admiralapiv1.Shard{ObjectMeta: v1.ObjectMeta{Name: "test"}}, + }, + }, + } + for _, c := range testCases { + t.Run(c.name, func(t *testing.T) { + sCtrl, _ := getNewMockShardController() + if c.args.fakeClientResponse != nil { + sCtrl.CrdClient.AdmiralV1().(*fake2.FakeAdmiralV1).PrependReactor("get", "*", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) { + return true, c.args.fakeClientResponse, nil + }) + } + for _, shard := range c.args.cacheItems { + sCtrl.Cache.UpdateShardToClusterCache("test", shard) + } + ctx := context.WithValue(context.Background(), "txId", "test") + r, err := sCtrl.Get(ctx, c.args.retry, c.args.obj) + if c.want.err == nil { + assert.Nil(t, err) + } + if c.want.err != nil && assert.Error(t, err) { + assert.Equal(t, c.want.err, err) + } + assert.Equal(t, c.want.obj, r) + }) + } + +} + func getNewMockShardController() (*ShardController, error) { shardHandler := test.MockShardHandler{} shardController, err := NewShardController(context.Background().Done(), &shardHandler, "../../test/resources/admins@fake-cluster.k8s.local", "test-ns", 0, loader.GetFakeClientLoader()) From b1f0920ffcf271f8bb0b0787adf3a99ea0e2ac73 Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Thu, 2 Jan 2025 11:27:40 -0800 Subject: [PATCH 3/5] Tech-Debt: Increase coverage - Refine coverage task to ignore generate file test coverage Signed-off-by: Adil Fulara --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 065ced559..b9dd0e448 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,8 @@ build-mac: $(GOBUILD) -o $(BINARY_DARWIN) -v $(MAIN_PATH_ADMIRAL) test: - $(GOTEST) -v -failfast -race -timeout 0 `go list ./... | grep -v client | grep -v fmeatests | grep -v tests` -coverprofile=c.out + $(GOTEST) -v -failfast -race -timeout 0 `go list ./... | grep -v client | grep -v fmeatests | grep -v tests` -coverprofile=c.out.tmp + cat c.out.tmp | grep -v "pb.go" | grep -v "root.go" | grep -v "_generated.deepcopy.go" > c.out $(GOCMD) install github.com/boumenot/gocover-cobertura@latest $(GOPATH)/bin/gocover-cobertura < c.out > cobertura-coverage.xml From e3bb1942e09df0b1a8f7ada369cf920a0f222707 Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Thu, 2 Jan 2025 12:04:54 -0800 Subject: [PATCH 4/5] Tech-Debt: Increase coverage - Refine coverage task to ignore generate file test coverage Signed-off-by: Adil Fulara --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b9dd0e448..9e574f7b4 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ build-mac: $(GOBUILD) -o $(BINARY_DARWIN) -v $(MAIN_PATH_ADMIRAL) test: - $(GOTEST) -v -failfast -race -timeout 0 `go list ./... | grep -v client | grep -v fmeatests | grep -v tests` -coverprofile=c.out.tmp + $(GOTEST) -v -failfast -race -timeout 0 `go list ./... | grep -v client | grep -v fmeatests | grep -v tests | grep -v test` -coverprofile=c.out.tmp cat c.out.tmp | grep -v "pb.go" | grep -v "root.go" | grep -v "_generated.deepcopy.go" > c.out $(GOCMD) install github.com/boumenot/gocover-cobertura@latest $(GOPATH)/bin/gocover-cobertura < c.out > cobertura-coverage.xml From a1122b33d42653c73e57c6cae61475c1af59f891 Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Thu, 2 Jan 2025 12:46:02 -0800 Subject: [PATCH 5/5] Tech-Debt: Increase coverage - Refine coverage task to ignore generate file test coverage Signed-off-by: Adil Fulara --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9e574f7b4..648f222e2 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ build-mac: test: $(GOTEST) -v -failfast -race -timeout 0 `go list ./... | grep -v client | grep -v fmeatests | grep -v tests | grep -v test` -coverprofile=c.out.tmp - cat c.out.tmp | grep -v "pb.go" | grep -v "root.go" | grep -v "_generated.deepcopy.go" > c.out + cat c.out.tmp | grep -v "pb.go" | grep -v "root.go" | grep -v "_generated.deepcopy.go" | grep -v "registry/mocks" | grep -v "mocks/ConfigWriter.go"> c.out $(GOCMD) install github.com/boumenot/gocover-cobertura@latest $(GOPATH)/bin/gocover-cobertura < c.out > cobertura-coverage.xml