Sonar complience
Use valid names and factorize some constants checks
This commit is contained in:
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -10,8 +10,10 @@ import (
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
const htmlContent = "<html><body><h1>Hello, World!</h1></body></html>"
|
||||
|
||||
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("<html><body><h1>Hello, World!</h1></body></html>")
|
||||
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"] != "<html><body><h1>Hello, World!</h1></body></html>" {
|
||||
t.Errorf("Expected index.html to be <html><body><h1>Hello, World!</h1></body></html>, 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("<html><body><h1>Hello, World!</h1></body></html>")
|
||||
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)
|
||||
|
Reference in New Issue
Block a user