From 89c27784d7f7766570ebf4a38922a4701eb33e3c Mon Sep 17 00:00:00 2001 From: "terry.hung" Date: Sat, 19 Oct 2024 12:46:58 +0800 Subject: [PATCH] fix: the helm lint error and add more unit test Signed-off-by: terry.hung --- charts/flyte-binary/values.yaml | 2 +- .../pkg/repositories/config/seed_data_test.go | 104 ++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/charts/flyte-binary/values.yaml b/charts/flyte-binary/values.yaml index d4c210e9e6c..2cd7255282c 100644 --- a/charts/flyte-binary/values.yaml +++ b/charts/flyte-binary/values.yaml @@ -21,7 +21,7 @@ flyte-core-components: seedProjects: - flytesnacks # seedProjectsWithDetails flyte projects to create by default with description - # If there is an overlap between seedProjects and seedProjectsWithDetails, + # If there is an overlap between seedProjects and seedProjectsWithDetails, # the description provided in seedProjectsWithDetails will take precedence. # For seedProjects without a corresponding description in seedProjectsWithDetails, # a default description will be auto-generated for the project. diff --git a/flyteadmin/pkg/repositories/config/seed_data_test.go b/flyteadmin/pkg/repositories/config/seed_data_test.go index 3f077dc866d..af910f8fb21 100644 --- a/flyteadmin/pkg/repositories/config/seed_data_test.go +++ b/flyteadmin/pkg/repositories/config/seed_data_test.go @@ -143,3 +143,107 @@ func TestMergeSeedProjectsWithUniqueNames(t *testing.T) { }) } } + +func TestUniqueProjectsFromNames(t *testing.T) { + tests := []struct { + name string + names []string + want []SeedProject + }{ + { + name: "Empty input", + names: []string{}, + want: []SeedProject{}, + }, + { + name: "Single name", + names: []string{"project1"}, + want: []SeedProject{ + { + Name: "project1", + Description: "project1 description", + }, + }, + }, + { + name: "Multiple unique names", + names: []string{"project1", "project2", "project3"}, + want: []SeedProject{ + { + Name: "project1", + Description: "project1 description", + }, + { + Name: "project2", + Description: "project2 description", + }, + { + Name: "project3", + Description: "project3 description", + }, + }, + }, + { + name: "Duplicate names", + names: []string{"project1", "project1", "project2", "project2", "project3"}, + want: []SeedProject{ + { + Name: "project1", + Description: "project1 description", + }, + { + Name: "project2", + Description: "project2 description", + }, + { + Name: "project3", + Description: "project3 description", + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := UniqueProjectsFromNames(tt.names) + + if len(got) != len(tt.want) { + t.Errorf("length mismatch: got %d projects, want %d projects", len(got), len(tt.want)) + return + } + + gotMap := make(map[string]string) + for _, project := range got { + gotMap[project.Name] = project.Description + } + wantMap := make(map[string]string) + for _, project := range tt.want { + wantMap[project.Name] = project.Description + } + + // Compare contents + for name, wantDesc := range wantMap { + if gotDesc, exists := gotMap[name]; !exists { + t.Errorf("missing project %q in result", name) + } else if gotDesc != wantDesc { + t.Errorf("project %q description mismatch: got %q, want %q", name, gotDesc, wantDesc) + } + } + + for name := range gotMap { + if _, exists := wantMap[name]; !exists { + t.Errorf("unexpected project %q in result", name) + } + } + + uniqueNames := make([]string, 0) + seen := make(map[string]bool) + for _, name := range tt.names { + if !seen[name] { + seen[name] = true + uniqueNames = append(uniqueNames, name) + } + } + }) + } +}