@@ -58,17 +58,90 @@ func TestInit(t *testing.T) {
58
58
}
59
59
}
60
60
61
- func funcNameValidation (name string , t * testing.T ) {
62
- err := commands .ValidateFuncName ("fooFunc" )
63
- if err == nil {
64
- t .Error ("Expected validation error for function name" )
61
+ func TestFuncNameValidation (t * testing.T ) {
62
+ tc := []struct {
63
+ name string
64
+ value string
65
+ errExpected bool
66
+ }{
67
+ {
68
+ name : "strings only" ,
69
+ value : "somename" ,
70
+ errExpected : false ,
71
+ },
72
+ {
73
+ name : "numbers only" ,
74
+ value : "12345" ,
75
+ errExpected : false ,
76
+ },
77
+ {
78
+ name : "uppercase letters" ,
79
+ value : "HelloFuncName" ,
80
+ errExpected : true ,
81
+ },
82
+ {
83
+ name : "starts with separator" ,
84
+ value : ".myfunc" ,
85
+ errExpected : true ,
86
+ },
87
+ {
88
+ name : "ends with separator" ,
89
+ value : "myfunc-" ,
90
+ errExpected : true ,
91
+ },
92
+ {
93
+ name : "contains spaces" ,
94
+ value : "my func blah" ,
95
+ errExpected : true ,
96
+ },
97
+ {
98
+ name : "hypen in name" ,
99
+ value : "my-func-blah" ,
100
+ errExpected : false ,
101
+ },
102
+ {
103
+ name : "underscore in name" ,
104
+ value : "my_funcblah" ,
105
+ errExpected : false ,
106
+ },
107
+ {
108
+ name : "dot in name" ,
109
+ value : "my.funcblah" ,
110
+ errExpected : false ,
111
+ },
112
+ {
113
+ name : "multiple separators in row" ,
114
+ value : "my___funcblah" ,
115
+ errExpected : true ,
116
+ },
117
+ {
118
+ name : "multiple different separators in row" ,
119
+ value : "my_.funcblah" ,
120
+ errExpected : true ,
121
+ },
122
+ {
123
+ name : "multiple separators in the name" ,
124
+ value : "my_func-blah.test" ,
125
+ errExpected : false ,
126
+ },
65
127
}
66
- }
67
-
68
- func TestFuncNameWithUpperCase (t * testing.T ) {
69
- funcNameValidation ("fooMyFunc" , t )
70
- }
71
128
72
- func TestFuncNameWithColon (t * testing.T ) {
73
- funcNameValidation ("foo:myfunc" , t )
129
+ t .Log ("Test func name validation" )
130
+ {
131
+ for i , tst := range tc {
132
+ t .Logf ("\t Test %d: \t %s" , i , tst .name )
133
+ {
134
+ err := commands .ValidateFuncName (tst .value )
135
+ if err != nil {
136
+ if ! tst .errExpected {
137
+ t .Fatalf ("\t ValidateFuncName failed : got unexpected error [%v]\n " , err )
138
+ }
139
+ } else {
140
+ if tst .errExpected {
141
+ t .Fatalf ("\t ValidateFuncName failed : error expected for value '%s' but was nil\n " , tst .value )
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
74
147
}
0 commit comments