From 2e6aff631fff86f6ecdda8d0692ee91dc78a9c45 Mon Sep 17 00:00:00 2001 From: Anubhav Aeron Date: Mon, 19 Sep 2022 15:51:09 -0700 Subject: [PATCH] add tests for isAnExcludedAsset --- admiral/pkg/clusters/types_test.go | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/admiral/pkg/clusters/types_test.go b/admiral/pkg/clusters/types_test.go index cd9ca0d87..f1fb18efd 100644 --- a/admiral/pkg/clusters/types_test.go +++ b/admiral/pkg/clusters/types_test.go @@ -461,5 +461,46 @@ func TestRoutingPolicyHandler(t *testing.T) { handler.Updated(ctx, routingPolicyFoo) assert.Nil(t, registry.AdmiralCache.RoutingPolicyFilterCache.Get("bar4stage")) assert.Nil(t, registry.AdmiralCache.RoutingPolicyFilterCache.Get("bar3stage")) +} +func TestIsAnExcludedAsset(t *testing.T) { + testCases := []struct { + name string + assetName string + excludedAssetList []string + expectedResult bool + }{ + { + name: "Given an asset is in the exclude list, " + + "When isAnExcludedAsset is called, " + + "Then, it should return true", + assetName: "excluded-asset1", + excludedAssetList: []string{"excluded-asset1"}, + expectedResult: true, + }, + { + name: "Given an asset is NOT in the exclude list, " + + "When isAnExcludedAsset is called, " + + "Then, it should return false", + assetName: "not-excluded-asset1", + excludedAssetList: []string{"excluded-asset1"}, + expectedResult: false, + }, + { + name: "Given an asset in the exclude list, " + + "When the asset name closely matches an excluded asset, " + + "And is different by one character, " + + "Then, it should return false", + assetName: "e1", + excludedAssetList: []string{"e2"}, + expectedResult: false, + }, + } + + for _, c := range testCases { + result := isAnExcludedAsset(c.assetName, c.excludedAssetList) + if result != c.expectedResult { + t.Fatalf("expected: %v, got: %v", c.expectedResult, result) + } + } }