fix(generation): Fix container name
Container names were built using the service name. We didn't checked the name and leave underscores inside. This commit does: - fix all service and rename containers (`container_name`) - use `ContainerName` everywhere we need to get the container by name See #106
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"katenary/generator/labels"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
yaml3 "gopkg.in/yaml.v3"
|
||||
@@ -343,6 +344,38 @@ services:
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithUnderscoreInContainerName(t *testing.T) {
|
||||
composeFile := `
|
||||
services:
|
||||
web-app:
|
||||
image: nginx:1.29
|
||||
container_name: web_app_container
|
||||
environment:
|
||||
FOO: BAR
|
||||
labels:
|
||||
%s/values: |
|
||||
- FOO
|
||||
`
|
||||
composeFile = fmt.Sprintf(composeFile, labels.Prefix())
|
||||
tmpDir := setup(composeFile)
|
||||
defer teardown(tmpDir)
|
||||
|
||||
currentDir, _ := os.Getwd()
|
||||
os.Chdir(tmpDir)
|
||||
defer os.Chdir(currentDir)
|
||||
|
||||
output := internalCompileTest(t, "-s", "templates/web_app/deployment.yaml")
|
||||
dt := v1.Deployment{}
|
||||
if err := yaml.Unmarshal([]byte(output), &dt); err != nil {
|
||||
t.Errorf(unmarshalError, err)
|
||||
}
|
||||
// find container.name
|
||||
containerName := dt.Spec.Template.Spec.Containers[0].Name
|
||||
if strings.Contains(containerName, "_") {
|
||||
t.Errorf("Expected container name to not contain underscores, got %s", containerName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithDashes(t *testing.T) {
|
||||
composeFile := `
|
||||
services:
|
||||
|
Reference in New Issue
Block a user