diff --git a/conformance/conformance.go b/conformance/conformance.go index ce264a9441..d524a31829 100644 --- a/conformance/conformance.go +++ b/conformance/conformance.go @@ -68,13 +68,14 @@ func DefaultOptions(t *testing.T) suite.ConformanceOptions { namespaceAnnotations := suite.ParseKeyValuePairs(*flags.NamespaceAnnotations) conformanceProfiles := suite.ParseConformanceProfiles(*flags.ConformanceProfiles) - implementation := suite.ParseImplementation( + implementation, err := suite.ParseImplementation( *flags.ImplementationOrganization, *flags.ImplementationProject, *flags.ImplementationURL, *flags.ImplementationVersion, *flags.ImplementationContact, ) + require.NoError(t, err, "error parsing implementation details") return suite.ConformanceOptions{ AllowCRDsMismatch: *flags.AllowCRDsMismatch, @@ -88,7 +89,7 @@ func DefaultOptions(t *testing.T) suite.ConformanceOptions { ExemptFeatures: exemptFeatures, ManifestFS: []fs.FS{&Manifests}, GatewayClassName: *flags.GatewayClassName, - Implementation: implementation, + Implementation: *implementation, Mode: *flags.Mode, NamespaceAnnotations: namespaceAnnotations, NamespaceLabels: namespaceLabels, diff --git a/conformance/utils/suite/suite.go b/conformance/utils/suite/suite.go index 81599a8d4c..0f00ac4c36 100644 --- a/conformance/utils/suite/suite.go +++ b/conformance/utils/suite/suite.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "io/fs" + neturl "net/url" "slices" "sort" "strings" @@ -539,14 +540,33 @@ func (suite *ConformanceTestSuite) Report() (*confv1.ConformanceReport, error) { // ParseImplementation parses implementation-specific flag arguments and // creates a *confv1a1.Implementation. -func ParseImplementation(org, project, url, version, contact string) confv1.Implementation { - return confv1.Implementation{ +func ParseImplementation(org, project, url, version, contact string) (*confv1.Implementation, error) { + if org == "" { + return nil, errors.New("organization must be set") + } + if project == "" { + return nil, errors.New("project must be set") + } + if url == "" { + return nil, errors.New("url must be set") + } + if version == "" { + return nil, errors.New("version must be set") + } + if contact == "" { + return nil, errors.New("contact must be set") + } + if _, err := neturl.ParseRequestURI(url); err != nil { + return nil, errors.New("url is malformed") + } + + return &confv1.Implementation{ Organization: org, Project: project, URL: url, Version: version, Contact: strings.Split(contact, ","), - } + }, nil } // ParseConformanceProfiles parses flag arguments and converts the string to diff --git a/conformance/utils/suite/suite_test.go b/conformance/utils/suite/suite_test.go index 951571f7aa..1fca273bbf 100644 --- a/conformance/utils/suite/suite_test.go +++ b/conformance/utils/suite/suite_test.go @@ -407,3 +407,89 @@ func TestSuiteReport(t *testing.T) { }) } } + +func TestParseImplementation(t *testing.T) { + testCases := []struct { + name string + org string + project string + url string + version string + contact string + expected *confv1.Implementation + expectedErr error + }{ + { + name: "missing organization", + project: "test-project", + url: "https://example.com", + version: "v1.0.0", + contact: "test@example.com", + expectedErr: errors.New("organization must be set"), + }, + { + name: "missing project", + org: "test-org", + url: "https://example.com", + version: "v1.0.0", + contact: "test@example.com", + expectedErr: errors.New("project must be set"), + }, + { + name: "missing url", + org: "test-org", + project: "test-project", + version: "v1.0.0", + contact: "test@example.com", + expectedErr: errors.New("url must be set"), + }, + { + name: "missing version", + org: "test-org", + project: "test-project", + url: "https://example.com", + contact: "test@example.com", + expectedErr: errors.New("version must be set"), + }, + { + name: "missing contact", + org: "test-org", + project: "test-project", + url: "https://example.com", + version: "v1.0.0", + expectedErr: errors.New("contact must be set"), + }, + { + name: "malformed url", + org: "test-org", + project: "test-project", + url: "invalid-url", + version: "v1.0.0", + contact: "test@example.com", + expectedErr: errors.New("url is malformed"), + }, + { + name: "valid input", + org: "test-org", + project: "test-project", + url: "https://example.com", + version: "v1.0.0", + contact: "test@example.com,test2@example.com", + expected: &confv1.Implementation{ + Organization: "test-org", + Project: "test-project", + URL: "https://example.com", + Version: "v1.0.0", + Contact: []string{"test@example.com", "test2@example.com"}, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + result, err := ParseImplementation(tc.org, tc.project, tc.url, tc.version, tc.contact) + assert.Equal(t, tc.expected, result) + assert.Equal(t, tc.expectedErr, err) + }) + } +} diff --git a/pkg/test/cel/grpcroute_test.go b/pkg/test/cel/grpcroute_test.go index 628de66ae9..2940ce3291 100644 --- a/pkg/test/cel/grpcroute_test.go +++ b/pkg/test/cel/grpcroute_test.go @@ -341,7 +341,8 @@ func TestGRPCRouteRule(t *testing.T) { } return rules }(), - }} + }, + } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) {