From 921822239b397229a98b2861154d87eb678cb924 Mon Sep 17 00:00:00 2001 From: Richard Robert Reitz Date: Tue, 7 Oct 2025 17:19:52 +0200 Subject: [PATCH] fix(test): finish fixing organisation refactoring tests failures --- internal/config/parser_test.go | 33 ++++++++++++++++++++++++++------- internal/config/types.go | 5 ++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/internal/config/parser_test.go b/internal/config/parser_test.go index cb672ae..7e9cd61 100644 --- a/internal/config/parser_test.go +++ b/internal/config/parser_test.go @@ -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", }, diff --git a/internal/config/types.go b/internal/config/types.go index 05d84b7..665d873 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -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 }