Avoid repetitions

This commit is contained in:
2024-04-23 15:45:31 +02:00
parent a3e7435544
commit e0c18ec2ad
7 changed files with 10 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ services:
output := _compile_test(t, "-s", "templates/web/configmap.yaml") output := _compile_test(t, "-s", "templates/web/configmap.yaml")
configMap := v1.ConfigMap{} configMap := v1.ConfigMap{}
if err := yaml.Unmarshal([]byte(output), &configMap); err != nil { if err := yaml.Unmarshal([]byte(output), &configMap); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
data := configMap.Data data := configMap.Data
if len(data) != 2 { if len(data) != 2 {

View File

@@ -26,7 +26,7 @@ services:
// dt := DeploymentTest{} // dt := DeploymentTest{}
dt := v1.Deployment{} dt := v1.Deployment{}
if err := yaml.Unmarshal([]byte(output), &dt); err != nil { if err := yaml.Unmarshal([]byte(output), &dt); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
if *dt.Spec.Replicas != 1 { if *dt.Spec.Replicas != 1 {

View File

@@ -33,7 +33,7 @@ services:
output := _compile_test(t, "-s", "templates/web/ingress.yaml", "--set", "web.ingress.enabled=true") output := _compile_test(t, "-s", "templates/web/ingress.yaml", "--set", "web.ingress.enabled=true")
ingress := v1.Ingress{} ingress := v1.Ingress{}
if err := yaml.Unmarshal([]byte(output), &ingress); err != nil { if err := yaml.Unmarshal([]byte(output), &ingress); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
if len(ingress.Spec.Rules) != 1 { if len(ingress.Spec.Rules) != 1 {
t.Errorf("Expected 1 rule, got %d", len(ingress.Spec.Rules)) t.Errorf("Expected 1 rule, got %d", len(ingress.Spec.Rules))

View File

@@ -32,7 +32,7 @@ services:
output := _compile_test(t, "-s", "templates/web/secret.yaml") output := _compile_test(t, "-s", "templates/web/secret.yaml")
secret := v1.Secret{} secret := v1.Secret{}
if err := yaml.Unmarshal([]byte(output), &secret); err != nil { if err := yaml.Unmarshal([]byte(output), &secret); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
data := secret.Data data := secret.Data
if len(data) != 1 { if len(data) != 1 {

View File

@@ -27,7 +27,7 @@ services:
output := _compile_test(t, "-s", "templates/web/service.yaml") output := _compile_test(t, "-s", "templates/web/service.yaml")
service := v1.Service{} service := v1.Service{}
if err := yaml.Unmarshal([]byte(output), &service); err != nil { if err := yaml.Unmarshal([]byte(output), &service); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
if len(service.Spec.Ports) != 2 { if len(service.Spec.Ports) != 2 {

View File

@@ -9,6 +9,8 @@ import (
"katenary/parser" "katenary/parser"
) )
const unmarshalError = "Failed to unmarshal the output: %s"
func setup(content string) string { func setup(content string) string {
// write the _compose_file in temporary directory // write the _compose_file in temporary directory
tmpDir, err := os.MkdirTemp("", "katenary") tmpDir, err := os.MkdirTemp("", "katenary")

View File

@@ -31,7 +31,7 @@ volumes:
dt := v1.Deployment{} dt := v1.Deployment{}
if err := yaml.Unmarshal([]byte(output), &dt); err != nil { if err := yaml.Unmarshal([]byte(output), &dt); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
if dt.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name != "data" { if dt.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name != "data" {
@@ -71,7 +71,7 @@ services:
output := _compile_test(t, "-s", "templates/web/deployment.yaml") output := _compile_test(t, "-s", "templates/web/deployment.yaml")
dt := v1.Deployment{} dt := v1.Deployment{}
if err := yaml.Unmarshal([]byte(output), &dt); err != nil { if err := yaml.Unmarshal([]byte(output), &dt); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
// get the volume mount path // get the volume mount path
volumeMountPath := dt.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath volumeMountPath := dt.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath
@@ -88,7 +88,7 @@ services:
} }
configMap := corev1.ConfigMap{} configMap := corev1.ConfigMap{}
if err := yaml.Unmarshal([]byte(output), &configMap); err != nil { if err := yaml.Unmarshal([]byte(output), &configMap); err != nil {
t.Errorf("Failed to unmarshal the output: %s", err) t.Errorf(unmarshalError, err)
} }
data := configMap.Data data := configMap.Data
if len(data) != 1 { if len(data) != 1 {