Skip to content

Commit

Permalink
fix tovalidappname
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamero committed Nov 19, 2024
1 parent c5c4a04 commit b994d34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/setupgh.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ func toValidAppName(name string) (string, error) {
// remove all characters except alphanumeric, '-', '.'
var builder strings.Builder
for _, r := range cleanedName {
if unicode.IsLetter(r) || unicode.IsNumber(r) || r == '-' || r == '.' {
if unicode.IsLetter(r) || unicode.IsNumber(r) || r == '-' {
builder.WriteRune(r)
}
}

// lowercase the name
cleanedName = strings.ToLower(builder.String())
if ValidateAppName(cleanedName) != nil {
return "", fmt.Errorf("app name '%s' could not be converted to a valid name", name)
if err := ValidateAppName(cleanedName);err != nil {
return "", fmt.Errorf("app name '%s' could not be converted to a valid name: %w", name, err)
}
return cleanedName, nil
}
Expand Down
13 changes: 10 additions & 3 deletions cmd/setupgh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ func TestToValidAppName(t *testing.T) {
shouldError: true,
},
{
testCaseName: "dots and hypens allowed in the middle",
nameInput: "name.-.name",
expected: "name.-.name",
testCaseName: "hypens allowed in the middle",
nameInput: "name-name-name-name",
expected: "name-name-name-name",
}, {
testCaseName: "remove dots in the middle",
nameInput: "name.name-name-name",
expected: "namename-name-name",
},
{
testCaseName: "no capital letters",
Expand All @@ -85,6 +89,9 @@ func TestToValidAppName(t *testing.T) {
assert.Error(t, err)
} else {
assert.Equal(t, tc.expected, result)
if err != nil {
t.Errorf("expected no error, got %s", err)
}
}
})
}
Expand Down

0 comments on commit b994d34

Please sign in to comment.