From 5e44291a37f9429d862df1397c074688b2780381 Mon Sep 17 00:00:00 2001 From: Lucas Medeiros Date: Mon, 28 Jun 2021 14:55:56 -0300 Subject: [PATCH] add test coverage for removeDuplicates function Signed-off-by: Lucas Medeiros --- pkg/downloader/manager_test.go | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pkg/downloader/manager_test.go b/pkg/downloader/manager_test.go index b8da42cd2..cd7476113 100644 --- a/pkg/downloader/manager_test.go +++ b/pkg/downloader/manager_test.go @@ -24,6 +24,7 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/getter" + "helm.sh/helm/v3/pkg/repo" "helm.sh/helm/v3/pkg/repo/repotest" ) @@ -521,3 +522,44 @@ func TestKey(t *testing.T) { } } } + +func TestRemoveDuplicates(t *testing.T) { + entries := []*repo.Entry{ + {Name: "helm-manager-sha123"}, + {Name: "helm-manager-sha456"}, + {Name: "helm-manager-sha123"}, + } + + tests := []struct { + input []*repo.Entry + expect []*repo.Entry + }{ + { + input: entries, + expect: entries[:2], + }, + { + input: entries[1:], + expect: entries[1:], + }, + } + + for _, tt := range tests { + output := removeDuplicates(tt.input) + + outSize := len(output) + expectedSize := len(tt.expect) + + if outSize != expectedSize { + t.Fatalf("duplication removal failed, expected %d but got %d", expectedSize, outSize) + } + + for i, o := range output { + if o != tt.expect[i] { + t.Errorf("duplication removal failed, expected %q but got %q", tt.expect[i], o) + } + + } + } + +}