fix(test): finish fixing organisation refactoring tests failures

This commit is contained in:
Richard Robert Reitz 2025-10-07 17:19:52 +02:00
parent f32479aaf8
commit 921822239b
2 changed files with 30 additions and 8 deletions

View file

@ -152,6 +152,7 @@ kind: edgeconnect-deployment
metadata:
name: "test-app"
appVersion: "1.0.0"
organization: "testorg"
spec:
dockerApp:
image: "nginx:latest"
@ -385,42 +386,60 @@ func TestMetadata_Validate(t *testing.T) {
}{
{
name: "valid metadata",
metadata: Metadata{Name: "test-app", AppVersion: "1.0.0"},
metadata: Metadata{Name: "test-app", AppVersion: "1.0.0", Organization: "testorg"},
wantErr: false,
},
{
name: "empty name",
metadata: Metadata{Name: "", AppVersion: "1.0.0"},
metadata: Metadata{Name: "", AppVersion: "1.0.0", Organization: "testorg"},
wantErr: true,
errMsg: "metadata.name is required",
},
{
name: "name with leading whitespace",
metadata: Metadata{Name: " test-app", AppVersion: "1.0.0"},
metadata: Metadata{Name: " test-app", AppVersion: "1.0.0", Organization: "testorg"},
wantErr: true,
errMsg: "cannot have leading/trailing whitespace",
},
{
name: "name with trailing whitespace",
metadata: Metadata{Name: "test-app ", AppVersion: "1.0.0"},
metadata: Metadata{Name: "test-app ", AppVersion: "1.0.0", Organization: "testorg"},
wantErr: true,
errMsg: "cannot have leading/trailing whitespace",
},
{
name: "empty app version",
metadata: Metadata{Name: "test-app", AppVersion: ""},
metadata: Metadata{Name: "test-app", AppVersion: "", Organization: "testorg"},
wantErr: true,
errMsg: "metadata.appVersion is required",
},
{
name: "app version with leading whitespace",
metadata: Metadata{Name: "test-app", AppVersion: " 1.0.0"},
metadata: Metadata{Name: "test-app", AppVersion: " 1.0.0", Organization: "testorg"},
wantErr: true,
errMsg: "cannot have leading/trailing whitespace",
},
{
name: "app version with trailing whitespace",
metadata: Metadata{Name: "test-app", AppVersion: "1.0.0 "},
metadata: Metadata{Name: "test-app", AppVersion: "1.0.0 ", Organization: "testorg"},
wantErr: true,
errMsg: "cannot have leading/trailing whitespace",
},
{
name: "empty organization",
metadata: Metadata{Name: "test-app", AppVersion: "1.0.0", Organization: ""},
wantErr: true,
errMsg: "metadata.organization is required",
},
{
name: "organization with leading whitespace",
metadata: Metadata{Name: "test-app", AppVersion: "1.0.0", Organization: " testorg"},
wantErr: true,
errMsg: "cannot have leading/trailing whitespace",
},
{
name: "organization with trailing whitespace",
metadata: Metadata{Name: "test-app", AppVersion: "1.0.0", Organization: "testorg "},
wantErr: true,
errMsg: "cannot have leading/trailing whitespace",
},

View file

@ -122,9 +122,12 @@ func (m *Metadata) Validate() error {
}
if m.Organization == "" {
return fmt.Errorf("organization is required")
return fmt.Errorf("metadata.organization is required")
}
if strings.TrimSpace(m.Organization) != m.Organization {
return fmt.Errorf("metadata.Organization cannot have leading/trailing whitespace")
}
return nil
}