From dc34d32c5cf49a135a3365edde880d35a752e78c Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Mon, 25 Nov 2024 11:54:38 +0100 Subject: [PATCH] test(secrets): add tests --- generator/secret_test.go | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/generator/secret_test.go b/generator/secret_test.go index 607b5ba..fdefdaf 100644 --- a/generator/secret_test.go +++ b/generator/secret_test.go @@ -1,6 +1,7 @@ package generator import ( + "bytes" "fmt" "katenary/generator/labels" "os" @@ -44,3 +45,49 @@ services: t.Errorf("Expected BAR to be baz, got %s", data["BAR"]) } } + +func TestCreateSecretFromEnvironmentWithValue(t *testing.T) { + composeFile := ` +services: + web: + image: nginx:1.29 + environment: + - FOO=bar + - BAR=baz + labels: + %[1]s/secrets: |- + - BAR + %[1]s/values: |- + - BAR +` + composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix) + tmpDir := setup(composeFile) + defer teardown(tmpDir) + + currentDir, _ := os.Getwd() + os.Chdir(tmpDir) + defer os.Chdir(currentDir) + + force := false + outputDir := "./chart" + profiles := make([]string, 0) + helmdepUpdate := true + var appVersion *string + chartVersion := "0.1.0" + convertOptions := ConvertOptions{ + Force: force, + OutputDir: outputDir, + Profiles: profiles, + HelmUpdate: helmdepUpdate, + AppVersion: appVersion, + ChartVersion: chartVersion, + } + Convert(convertOptions, "compose.yml") + c, err := os.ReadFile("chart/values.yaml") + if err != nil { + t.Fatal(err) + } + if !bytes.Contains(c, []byte("BAR: baz")) { + t.Errorf("Expected BAR to be baz, got %s", c) + } +}