diff --git a/generator/configMap_test.go b/generator/configMap_test.go index 6a29373..5b0c192 100644 --- a/generator/configMap_test.go +++ b/generator/configMap_test.go @@ -24,7 +24,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/configmap.yaml") + output := internalCompileTest(t, "-s", "templates/web/configmap.yaml") configMap := v1.ConfigMap{} if err := yaml.Unmarshal([]byte(output), &configMap); err != nil { t.Errorf(unmarshalError, err) diff --git a/generator/cronJob_test.go b/generator/cronJob_test.go index b892726..dbe1bac 100644 --- a/generator/cronJob_test.go +++ b/generator/cronJob_test.go @@ -30,7 +30,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/cron/cronjob.yaml") + output := internalCompileTest(t, "-s", "templates/cron/cronjob.yaml") cronJob := batchv1.CronJob{} if err := yaml.Unmarshal([]byte(output), &cronJob); err != nil { t.Errorf(unmarshalError, err) @@ -83,7 +83,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/cron/cronjob.yaml") + output := internalCompileTest(t, "-s", "templates/cron/cronjob.yaml") cronJob := batchv1.CronJob{} if err := yaml.Unmarshal([]byte(output), &cronJob); err != nil { t.Errorf(unmarshalError, err) diff --git a/generator/deployment_test.go b/generator/deployment_test.go index 5c716c2..d20f187 100644 --- a/generator/deployment_test.go +++ b/generator/deployment_test.go @@ -25,7 +25,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", webTemplateOutput) + output := internalCompileTest(t, "-s", webTemplateOutput) // dt := DeploymentTest{} dt := v1.Deployment{} @@ -67,7 +67,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", webTemplateOutput) + output := internalCompileTest(t, "-s", webTemplateOutput) dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) @@ -125,7 +125,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", webTemplateOutput) + output := internalCompileTest(t, "-s", webTemplateOutput) dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) @@ -167,7 +167,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", webTemplateOutput) + output := internalCompileTest(t, "-s", webTemplateOutput) dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) @@ -220,7 +220,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", webTemplateOutput) + output := internalCompileTest(t, "-s", webTemplateOutput) dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) @@ -257,7 +257,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", webTemplateOutput) + output := internalCompileTest(t, "-s", webTemplateOutput) dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) @@ -303,7 +303,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", webTemplateOutput) + output := internalCompileTest(t, "-s", webTemplateOutput) dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) diff --git a/generator/ingress_test.go b/generator/ingress_test.go index 7a039e1..759145f 100644 --- a/generator/ingress_test.go +++ b/generator/ingress_test.go @@ -30,7 +30,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/ingress.yaml", "--set", "web.ingress.enabled=true") + output := internalCompileTest(t, "-s", "templates/web/ingress.yaml", "--set", "web.ingress.enabled=true") ingress := v1.Ingress{} if err := yaml.Unmarshal([]byte(output), &ingress); err != nil { t.Errorf(unmarshalError, err) diff --git a/generator/secret_test.go b/generator/secret_test.go index 93949b6..6f80fe7 100644 --- a/generator/secret_test.go +++ b/generator/secret_test.go @@ -29,7 +29,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/secret.yaml") + output := internalCompileTest(t, "-s", "templates/web/secret.yaml") secret := v1.Secret{} if err := yaml.Unmarshal([]byte(output), &secret); err != nil { t.Errorf(unmarshalError, err) diff --git a/generator/service_test.go b/generator/service_test.go index 1bc7a89..205c944 100644 --- a/generator/service_test.go +++ b/generator/service_test.go @@ -24,7 +24,7 @@ services: os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/service.yaml") + output := internalCompileTest(t, "-s", "templates/web/service.yaml") service := v1.Service{} if err := yaml.Unmarshal([]byte(output), &service); err != nil { t.Errorf(unmarshalError, err) diff --git a/generator/tools_test.go b/generator/tools_test.go index 6fbdd6b..9d1591e 100644 --- a/generator/tools_test.go +++ b/generator/tools_test.go @@ -1,12 +1,11 @@ package generator import ( + "katenary/parser" "log" "os" "os/exec" "testing" - - "katenary/parser" ) const unmarshalError = "Failed to unmarshal the output: %s" @@ -29,8 +28,8 @@ func teardown(tmpDir string) { } } -func _compile_test(t *testing.T, options ...string) string { - _, err := parser.Parse(nil, "compose.yml") +func internalCompileTest(t *testing.T, options ...string) string { + _, err := parser.Parse(nil, nil, "compose.yml") if err != nil { t.Fatalf("Failed to parse the project: %s", err) } diff --git a/generator/volume_test.go b/generator/volume_test.go index d2f49b9..2342535 100644 --- a/generator/volume_test.go +++ b/generator/volume_test.go @@ -10,8 +10,10 @@ import ( "sigs.k8s.io/yaml" ) +const htmlContent = "

Hello, World!

" + func TestGenerateWithBoundVolume(t *testing.T) { - compose_file := ` + composeFile := ` services: web: image: nginx:1.29 @@ -20,14 +22,14 @@ services: volumes: data: ` - tmpDir := setup(compose_file) + tmpDir := setup(composeFile) defer teardown(tmpDir) currentDir, _ := os.Getwd() os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/deployment.yaml") + output := internalCompileTest(t, "-s", "templates/web/deployment.yaml") dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { @@ -40,7 +42,7 @@ volumes: } func TestWithStaticFiles(t *testing.T) { - compose_file := ` + composeFile := ` services: web: image: nginx:1.29 @@ -50,8 +52,8 @@ services: %s/configmap-files: |- - ./static ` - compose_file = fmt.Sprintf(compose_file, katenaryLabelPrefix) - tmpDir := setup(compose_file) + composeFile = fmt.Sprintf(composeFile, katenaryLabelPrefix) + tmpDir := setup(composeFile) defer teardown(tmpDir) // create a static directory with an index.html file @@ -61,14 +63,14 @@ services: if err != nil { t.Errorf("Failed to create index.html: %s", err) } - indexFile.WriteString("

Hello, World!

") + indexFile.WriteString(htmlContent) indexFile.Close() currentDir, _ := os.Getwd() os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/deployment.yaml") + output := internalCompileTest(t, "-s", "templates/web/deployment.yaml") dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) @@ -94,13 +96,13 @@ services: if len(data) != 1 { t.Errorf("Expected 1 data, got %d", len(data)) } - if data["index.html"] != "

Hello, World!

" { - t.Errorf("Expected index.html to be

Hello, World!

, got %s", data["index.html"]) + if data["index.html"] != htmlContent { + t.Errorf("Expected index.html to be "+htmlContent+", got %s", data["index.html"]) } } func TestWithFileMapping(t *testing.T) { - compose_file := ` + composeFile := ` services: web: image: nginx:1.29 @@ -110,8 +112,8 @@ services: %s/configmap-files: |- - ./static/index.html ` - compose_file = fmt.Sprintf(compose_file, katenaryLabelPrefix) - tmpDir := setup(compose_file) + composeFile = fmt.Sprintf(composeFile, katenaryLabelPrefix) + tmpDir := setup(composeFile) defer teardown(tmpDir) // create a static directory with an index.html file @@ -121,14 +123,14 @@ services: if err != nil { t.Errorf("Failed to create index.html: %s", err) } - indexFile.WriteString("

Hello, World!

") + indexFile.WriteString(htmlContent) indexFile.Close() currentDir, _ := os.Getwd() os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/deployment.yaml") + output := internalCompileTest(t, "-s", "templates/web/deployment.yaml") dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err) @@ -147,7 +149,7 @@ services: } func TestBindFrom(t *testing.T) { - compose_file := ` + composeFile := ` services: web: image: nginx:1.29 @@ -167,15 +169,15 @@ volumes: data: ` - compose_file = fmt.Sprintf(compose_file, katenaryLabelPrefix) - tmpDir := setup(compose_file) + composeFile = fmt.Sprintf(composeFile, katenaryLabelPrefix) + tmpDir := setup(composeFile) defer teardown(tmpDir) currentDir, _ := os.Getwd() os.Chdir(tmpDir) defer os.Chdir(currentDir) - output := _compile_test(t, "-s", "templates/web/deployment.yaml") + output := internalCompileTest(t, "-s", "templates/web/deployment.yaml") dt := v1.Deployment{} if err := yaml.Unmarshal([]byte(output), &dt); err != nil { t.Errorf(unmarshalError, err)