File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -94,13 +94,13 @@ func ValidateSAK(input string) error {
9494// ValidateProjectName validates Project Name field user input.
9595func ValidateProjectName (input string ) error {
9696 // the first 62 char out of base64 and -
97- var pName = regexp .MustCompile (`^[A-Za-z0-9-]{1,16}$` )
97+ var pName = regexp .MustCompile (`^[a-zA-Z][ A-Za-z0-9-]{1,16}$` )
9898 if ! pName .MatchString (input ) {
9999 // error if char len is greater than 16
100100 if len (input ) > constants .MaxPnameLength {
101101 return errors .New ("Invalid, Project Name: (cannot exceed a max length of 16)" )
102102 }
103- return errors .New ("Invalid , Project Name: (can only contain alphanumeric chars & '-')" )
103+ return errors .New ("invalid , Project Name: (can only contain alphanumeric chars & '-') and must start with a letter " )
104104 }
105105 return nil
106106}
Original file line number Diff line number Diff line change @@ -194,3 +194,20 @@ func TestGetParam(t *testing.T) {
194194 assert .Equal (t , "Unsupported custom prompt type random-type." , err .Error ())
195195 })
196196}
197+
198+ func TestValidateProjectNam (t * testing.T ) {
199+ t .Run ("Should return error upon invalid project name" , func (t * testing.T ) {
200+ err := initPrompts .ValidateProjectName ("0invalid" )
201+ assert .Error (t , err , "Project name should not start with a number" )
202+ })
203+
204+ t .Run ("Should return error upon invalid project name length" , func (t * testing.T ) {
205+ err := initPrompts .ValidateProjectName ("invalid name with more than 30 characters" )
206+ assert .Error (t , err , "Project name should not be longer than 30 characters" )
207+ })
208+
209+ t .Run ("Should return nil upon valid project name" , func (t * testing.T ) {
210+ err := initPrompts .ValidateProjectName ("valid-name" )
211+ assert .Nil (t , err )
212+ })
213+ }
You can’t perform that action at this time.
0 commit comments