From ed79c68fa9fd0a37f146a5c1e909332b44d5d813 Mon Sep 17 00:00:00 2001 From: "terry.hung" Date: Wed, 23 Oct 2024 17:50:26 +0800 Subject: [PATCH] feat: add more unitest and fix the helm diff Signed-off-by: terry.hung --- charts/flyte-binary/README.md | 4 +- charts/flyte-binary/values.yaml | 2 +- .../flyte_sandbox_binary_helm_generated.yaml | 6 +- .../pkg/repositories/config/seed_data_test.go | 61 ++++++++++++++++--- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/charts/flyte-binary/README.md b/charts/flyte-binary/README.md index 1d0cfd04c69..e7df1018db2 100644 --- a/charts/flyte-binary/README.md +++ b/charts/flyte-binary/README.md @@ -116,9 +116,9 @@ Chart for basic single Flyte executable deployment | flyte-core-components.admin.disableClusterResourceManager | bool | `false` | | | flyte-core-components.admin.disableScheduler | bool | `false` | | | flyte-core-components.admin.disabled | bool | `false` | | +| flyte-core-components.admin.seedProjectsWithDetails[0].description | string | `"Default project setup."` | | +| flyte-core-components.admin.seedProjectsWithDetails[0].name | string | `"flytesnacks"` | | | flyte-core-components.admin.seedProjects[0] | string | `"flytesnacks"` | | -| flyte-core-components.admin.seedProjectsWithDetails.name | string | `"flytesnacks"` | | -| flyte-core-components.admin.seedProjectsWithDetails.description | string | `"Default project setup"` | | | flyte-core-components.dataCatalog.disabled | bool | `false` | | | flyte-core-components.propeller.disableWebhook | bool | `false` | | | flyte-core-components.propeller.disabled | bool | `false` | | diff --git a/charts/flyte-binary/values.yaml b/charts/flyte-binary/values.yaml index 2cd7255282c..eee01d16c65 100644 --- a/charts/flyte-binary/values.yaml +++ b/charts/flyte-binary/values.yaml @@ -27,7 +27,7 @@ flyte-core-components: # a default description will be auto-generated for the project. seedProjectsWithDetails: - name: flytesnacks - description: Default project setup." + description: Default project setup. # propeller Configuration to disable propeller or any of its components propeller: # disabled Disables flytepropeller diff --git a/deployment/sandbox-binary/flyte_sandbox_binary_helm_generated.yaml b/deployment/sandbox-binary/flyte_sandbox_binary_helm_generated.yaml index 9d5165aa09b..6fafa61550f 100644 --- a/deployment/sandbox-binary/flyte_sandbox_binary_helm_generated.yaml +++ b/deployment/sandbox-binary/flyte_sandbox_binary_helm_generated.yaml @@ -93,8 +93,8 @@ data: seedProjects: - flytesnacks seedProjectsWithDetails: - - name: flytesnacks - description: Default project setup + - description: Default project setup. + name: flytesnacks dataCatalog: disabled: false propeller: @@ -363,7 +363,7 @@ spec: app.kubernetes.io/instance: flyte app.kubernetes.io/component: flyte-binary annotations: - checksum/configuration: faaefbd3b3b2ddfd4e718bd77c02c632c75e7111dad0a6e25dc415dc88add73f + checksum/configuration: 886440a42b3eeec802cfe60d37885f69e35ffd83e53e625b3c877da5e8c7eb38 checksum/configuration-secret: d5d93f4e67780b21593dc3799f0f6682aab0765e708e4020939975d14d44f929 checksum/cluster-resource-templates: 7dfa59f3d447e9c099b8f8ffad3af466fecbc9cf9f8c97295d9634254a55d4ae spec: diff --git a/flyteadmin/pkg/repositories/config/seed_data_test.go b/flyteadmin/pkg/repositories/config/seed_data_test.go index af910f8fb21..b937b305928 100644 --- a/flyteadmin/pkg/repositories/config/seed_data_test.go +++ b/flyteadmin/pkg/repositories/config/seed_data_test.go @@ -1,6 +1,12 @@ package config -import "testing" +import ( + "testing" + + mocket "github.com/Selvatico/go-mocket" + "github.com/stretchr/testify/assert" + "gorm.io/gorm" +) func TestMergeSeedProjectsWithUniqueNames(t *testing.T) { tests := []struct { @@ -235,15 +241,50 @@ func TestUniqueProjectsFromNames(t *testing.T) { 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) - } - } }) } } + +func TestSeedProjects(t *testing.T) { + gormDb := GetDbForTest(t) + defer mocket.Catcher.Reset() + + mocket.Catcher.Reset() + mocket.Catcher.NewMock().WithQuery(`SELECT * FROM "projects"`).WithReply([]map[string]interface{}{}) + + projects := []SeedProject{ + { + Name: "Project 1", + Description: "New Description", + }, + } + + // Execute + err := SeedProjects(gormDb, projects) + + // Assert + assert.NoError(t, err) +} + +func TestSeedProjectsWithDuplicateKey(t *testing.T) { + gormDb := GetDbForTest(t) + defer mocket.Catcher.Reset() + + // Mock the SELECT query for existence check + mocket.Catcher.Reset() + mocket.Catcher.NewMock().WithQuery(`INSERT INTO "projects"`).WithError(gorm.ErrDuplicatedKey) + + projects := []SeedProject{ + { + Name: "Project 1", + Description: "New Description", + }, + } + + // Execute + err := SeedProjects(gormDb, projects) + + // Assert + assert.Error(t, err) + +}