Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/init/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func ValidateSAK(input string) error {
// ValidateProjectName validates Project Name field user input.
func ValidateProjectName(input string) error {
// the first 62 char out of base64 and -
var pName = regexp.MustCompile(`^[A-Za-z0-9-]{1,16}$`)
var pName = regexp.MustCompile(`^[a-zA-Z][A-Za-z0-9-]{1,16}$`)
if !pName.MatchString(input) {
// error if char len is greater than 16
if len(input) > constants.MaxPnameLength {
return errors.New("Invalid, Project Name: (cannot exceed a max length of 16)")
}
return errors.New("Invalid, Project Name: (can only contain alphanumeric chars & '-')")
return errors.New("invalid, Project Name: (can only contain alphanumeric chars & '-') and must start with a letter")
}
return nil
}
Expand Down
17 changes: 17 additions & 0 deletions internal/init/prompts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,20 @@ func TestGetParam(t *testing.T) {
assert.Equal(t, "Unsupported custom prompt type random-type.", err.Error())
})
}

func TestValidateProjectNam(t *testing.T) {
t.Run("Should return error upon invalid project name", func(t *testing.T) {
err := initPrompts.ValidateProjectName("0invalid")
assert.Error(t, err, "Project name should not start with a number")
})

t.Run("Should return error upon invalid project name length", func(t *testing.T) {
err := initPrompts.ValidateProjectName("invalid name with more than 30 characters")
assert.Error(t, err, "Project name should not be longer than 30 characters")
})

t.Run("Should return nil upon valid project name", func(t *testing.T) {
err := initPrompts.ValidateProjectName("valid-name")
assert.Nil(t, err)
})
}