Skip to content

Commit 3499a8d

Browse files
authored
fix: Correct openslosdk.Validate function (#16)
1 parent 531055e commit 3499a8d

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

pkg/openslosdk/validation.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package openslosdk
22

33
import (
4-
"fmt"
5-
64
"github.com/nobl9/govy/pkg/govy"
75

6+
"github.com/OpenSLO/go-sdk/internal"
87
"github.com/OpenSLO/go-sdk/pkg/openslo"
98
)
109

@@ -24,6 +23,4 @@ var objectsValidator = govy.New(
2423
}),
2524
),
2625
).
27-
WithNameFunc(func(o openslo.Object) string {
28-
return fmt.Sprintf("%s %s", o.GetVersion(), o.GetKind())
29-
})
26+
WithNameFunc(internal.GetObjectName)

pkg/openslosdk/validation_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ func TestValidate(t *testing.T) {
3838
assert.Require(t, assert.Error(t, err))
3939

4040
// nolint: lll
41-
expectedError := `Validation for openslo/v1alpha Service at index 0 has failed for the following properties:
41+
expectedError := `Validation for v1alpha.Service at index 0 has failed for the following properties:
4242
- 'metadata':
4343
- property is required but was empty
44-
Validation for openslo/v1 Service at index 1 has failed for the following properties:
44+
Validation for v1.Service 'service 1' at index 1 has failed for the following properties:
4545
- 'metadata.name' with value 'service 1':
4646
- string must match regular expression: '^[a-z0-9]([-a-z0-9]*[a-z0-9])?$' (e.g. 'my-name', '123-abc'); an RFC-1123 compliant label name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character
47-
Validation for openslo.com/v2alpha Service at index 2 has failed for the following properties:
47+
Validation for v2alpha.Service 'service2' at index 2 has failed for the following properties:
4848
- 'metadata.labels.invalid key' with key 'invalid key':
4949
- name part string must match regular expression: '^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$' (e.g. 'my.domain/MyName', 'MyName', 'my.name', '123-abc'); Kubernetes Qualified Name must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character with an optional DNS subdomain prefix and '/'`
5050
assert.Equal(t, expectedError, err.Error())

0 commit comments

Comments
 (0)