Skip to content

Commit 9cdeda1

Browse files
committed
fixed some inconcistencies due to merge conflicts
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
1 parent 90dd3b6 commit 9cdeda1

4 files changed

Lines changed: 45 additions & 31 deletions

File tree

cmd/deploy.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,6 @@ Valid examples:
309309
func deploy --namespace myapp
310310
func deploy --namespace my-app-123
311311
312-
For more options, run 'func deploy --help'`, err)
313-
}
314-
315312
For more options, run 'func deploy --help'`, err)
316313
}
317314
if errors.Is(err, fn.ErrConflictingImageAndRegistry) {
@@ -786,8 +783,6 @@ func (c deployConfig) Validate(cmd *cobra.Command) (err error) {
786783
return fn.ErrInvalidNamespace
787784
}
788785
}
789-
}
790-
791786

792787
// Check Image Digest was included
793788
var digest bool

pkg/functions/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737

3838
// ErrInvalidDomain is returned when a domain name doesn't meet DNS subdomain requirements
3939
ErrInvalidDomain = errors.New("invalid domain")
40-
40+
4141
// ErrInvalidNamespace is returned when a namespace name doesn't meet Kubernetes naming requirements
4242
ErrInvalidNamespace = errors.New("invalid namespace")
4343
)

pkg/utils/names.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type ErrInvalidLabel error
2525

2626
// ErrInvalidDomain indicates the domain name did not pass DNS subdomain validation.
2727
type ErrInvalidDomain error
28+
2829
// ErrInvalidNamespace indicates the namespace name did not pass Kubernetes namespace validation.
2930
type ErrInvalidNamespace error
3031

@@ -125,6 +126,9 @@ func ValidateDomain(domain string) error {
125126
return ErrInvalidDomain(errors.New(errMsg))
126127
}
127128

129+
return nil
130+
}
131+
128132
// ValidateNamespace validates that the input name is a valid Kubernetes namespace name, ie. valid DNS-1123 label.
129133
// It must consist of lower case alphanumeric characters or '-',
130134
// start with an alphabetic character, and end with an alphanumeric character

pkg/utils/names_test.go

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ func TestValidateLabelValue(t *testing.T) {
212212

213213
// TestValidateDomain tests that only correct DNS subdomain names are accepted
214214
func TestValidateDomain(t *testing.T) {
215-
// TestValidateNamespace tests that only correct Kubernetes namespace names are accepted
216-
func TestValidateNamespace(t *testing.T) {
217215
cases := []struct {
218216
In string
219217
Valid bool
@@ -233,6 +231,7 @@ func TestValidateNamespace(t *testing.T) {
233231
{"example-app.com", true}, // hyphen in domain
234232
{"a.co", true}, // short domain
235233
{"123app.example.com", true}, // label starting with number
234+
236235
// Invalid domains
237236
{"Example.Com", false}, // uppercase not allowed
238237
{"MY-APP.COM", false}, // uppercase not allowed
@@ -264,6 +263,45 @@ func TestValidateNamespace(t *testing.T) {
264263
}
265264
if err == nil && !c.Valid {
266265
t.Fatalf("Expected error for invalid domain: '%v'", c.In)
266+
}
267+
}
268+
}
269+
270+
func TestValidateDomainErrMsg(t *testing.T) {
271+
invalidDomain := "my@app.com"
272+
errMsgPrefix := fmt.Sprintf("Domain '%v'", invalidDomain)
273+
274+
err := ValidateDomain(invalidDomain)
275+
if err != nil {
276+
if !strings.HasPrefix(err.Error(), errMsgPrefix) {
277+
t.Fatalf("Unexpected error message: %v, the message should start with '%v' string", err.Error(), errMsgPrefix)
278+
}
279+
} else {
280+
t.Fatalf("Expected error for invalid domain: %v", invalidDomain)
281+
}
282+
}
283+
284+
// TestValidateDomainEmptyString ensures empty string is handled specially
285+
func TestValidateDomainEmptyString(t *testing.T) {
286+
// Empty string should be valid (means use cluster default)
287+
err := ValidateDomain("")
288+
if err != nil {
289+
t.Fatalf("Empty string should be valid (means use default): %v", err)
290+
}
291+
292+
// String with only whitespace should error
293+
err = ValidateDomain(" ")
294+
if err == nil {
295+
t.Fatal("String with only whitespace should be invalid")
296+
}
297+
}
298+
299+
// TestValidateNamespace tests that only correct Kubernetes namespace names are accepted
300+
func TestValidateNamespace(t *testing.T) {
301+
cases := []struct {
302+
In string
303+
Valid bool
304+
}{
267305
// Valid namespaces
268306
{"default", true},
269307
{"kube-system", true},
@@ -309,11 +347,6 @@ func TestValidateNamespace(t *testing.T) {
309347
}
310348
}
311349

312-
func TestValidateDomainErrMsg(t *testing.T) {
313-
invalidDomain := "my@app.com"
314-
errMsgPrefix := fmt.Sprintf("Domain '%v'", invalidDomain)
315-
316-
err := ValidateDomain(invalidDomain)
317350
func TestValidateNamespaceErrMsg(t *testing.T) {
318351
invalidNamespace := "my@app"
319352
errMsgPrefix := fmt.Sprintf("Namespace '%v'", invalidNamespace)
@@ -324,24 +357,6 @@ func TestValidateNamespaceErrMsg(t *testing.T) {
324357
t.Fatalf("Unexpected error message: %v, the message should start with '%v' string", err.Error(), errMsgPrefix)
325358
}
326359
} else {
327-
t.Fatalf("Expected error for invalid domain: %v", invalidDomain)
328-
}
329-
}
330-
331-
// TestValidateDomainEmptyString ensures empty string is handled specially
332-
func TestValidateDomainEmptyString(t *testing.T) {
333-
// Empty string should be valid (means use cluster default)
334-
err := ValidateDomain("")
335-
if err != nil {
336-
t.Fatalf("Empty string should be valid (means use default): %v", err)
337-
}
338-
339-
// String with only whitespace should error
340-
err = ValidateDomain(" ")
341-
if err == nil {
342-
t.Fatal("String with only whitespace should be invalid")
343-
}
344-
}
345360
t.Fatalf("Expected error for invalid namespace: %v", invalidNamespace)
346361
}
347362
}

0 commit comments

Comments
 (0)