Skip to content

Commit 1dbfa95

Browse files
committed
fix the linter errors and refactor such that test not fail
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
1 parent 11a85d5 commit 1dbfa95

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

pkg/utils/names.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ func ValidateLabelValue(value string) error {
113113
func ValidateNamespace(namespace string) error {
114114
if errs := validation.IsDNS1123Label(namespace); len(errs) > 0 {
115115
// Reuse the error message from Kubernetes validation
116-
// Replace "a DNS-1123 label" with more user-friendly context
117-
errMsg := strings.Replace(strings.Join(errs, ""), "a DNS-1123 label", fmt.Sprintf("Namespace '%v'", namespace), 1)
116+
// Replace "a lowercase RFC 1123 label" with more user-friendly context
117+
errMsg := strings.Replace(strings.Join(errs, ""), "a lowercase RFC 1123 label", fmt.Sprintf("Namespace '%v'", namespace), 1)
118118
return ErrInvalidNamespace(errors.New(errMsg))
119119
}
120120
return nil

pkg/utils/names_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ func TestValidateNamespace(t *testing.T) {
227227
{"a", true},
228228
{"a-b", true},
229229
{"abc-123-xyz", true},
230+
{"123app", true}, // DNS-1123 allows starting with number
231+
{"123invalid", true}, // DNS-1123 allows starting with number
232+
{"1", true}, // single number is valid
230233

231234
// Invalid namespaces
232-
{"", false}, // empty
233235
{"My-App", false}, // uppercase not allowed
234236
{"MY-APP", false}, // uppercase not allowed
235-
{"123app", false}, // cannot start with number
236-
{"123invalid", false}, // cannot start with number
237237
{"my_app", false}, // underscore not allowed
238238
{"my app", false}, // spaces not allowed
239239
{"invalid namespace", false}, // spaces not allowed
@@ -262,7 +262,7 @@ func TestValidateNamespace(t *testing.T) {
262262
}
263263

264264
func TestValidateNamespaceErrMsg(t *testing.T) {
265-
invalidNamespace := "123invalid"
265+
invalidNamespace := "my@app"
266266
errMsgPrefix := fmt.Sprintf("Namespace '%v'", invalidNamespace)
267267

268268
err := ValidateNamespace(invalidNamespace)
@@ -273,4 +273,4 @@ func TestValidateNamespaceErrMsg(t *testing.T) {
273273
} else {
274274
t.Fatalf("Expected error for invalid namespace: %v", invalidNamespace)
275275
}
276-
}
276+
}

0 commit comments

Comments
 (0)