Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion validator/schema/platformsh.application.json
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@
]
}
},
"oneOf": [
"anyOf": [
{
"required": [
"name",
Expand All @@ -927,6 +927,7 @@
{
"required": [
"name",
"type",
"stack"
]
}
Expand Down
62 changes: 62 additions & 0 deletions validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package validator

import (
"io/fs"
"os"
"path/filepath"
"testing"
"testing/fstest"
)
Expand Down Expand Up @@ -306,3 +308,63 @@ applications:
})
}
}

func Test_validatePlatformConfig(t *testing.T) {
tests := []struct {
name string
appYAML string
wantErr bool
}{
{
name: "simple",
appYAML: `
name: app1
type: "python:3.11"
`,
wantErr: false,
},
{
name: "missing name and type",
appYAML: `
web:
commands:
start: echo "start"
`,
wantErr: true,
},
{
name: "stack with type",
appYAML: `
name: app1
type: "composable:25.05"
stack:
- "php@8.3"
- "nodejs@20"
`,
wantErr: false,
},
{
name: "stack without type",
appYAML: `
name: app1
stack:
- "php@8.3"
- "nodejs@20"
`,
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dir := t.TempDir()
appFile := filepath.Join(dir, ".platform.app.yaml")
if err := os.WriteFile(appFile, []byte(tt.appYAML), 0o600); err != nil {
t.Fatalf("failed to write .platform.app.yaml: %v", err)
}
if err := validatePlatformConfig(dir); (err != nil) != tt.wantErr {
t.Errorf("validatePlatformConfig() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
Loading