Skip to content

Commit 7d34c1d

Browse files
authored
fix: Generate allowed string length in testcases (#164)
1 parent 65d5830 commit 7d34c1d

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

blacklist.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Transitional file to disable generation for selected services
2-
#assumerole
2+
assumerole
33
#customer
44
#openstack
55
kms
66

77
airflow
8-
edge
98
customer
109
vpn
1110
privateendpoint

templates/go/api_test.mustache

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
2828
{{#operation}}
2929
t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) {
3030
_apiUrlPath := "{{{path}}}"{{#pathParams}}
31-
{{paramName}}Value := {{#isAnyType}}"unspecified type"{{/isAnyType}}{{#isString}}{{#isUuid}}uuid.NewString(){{/isUuid}}{{^isUuid}}"{{paramName}}-value"{{/isUuid}}{{/isString}}{{#isNumber}}123{{/isNumber}}{{#isFloat}}float32(123){{/isFloat}}{{#isDouble}}float64(123){{/isDouble}}{{#isInteger}}int32(123){{/isInteger}}{{#isLong}}int64(123){{/isLong}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
31+
{{^minLength}}
32+
{{^maxLength}}
33+
{{paramName}}Value := {{#isAnyType}}"unspecified type"{{/isAnyType}}{{#isString}}{{#isUuid}}uuid.NewString(){{/isUuid}}{{^isUuid}}"{{paramName}}-value"{{/isUuid}}{{/isString}}{{#isNumber}}123{{/isNumber}}{{#isFloat}}float32(123){{/isFloat}}{{#isDouble}}float64(123){{/isDouble}}{{#isInteger}}int32(123){{/isInteger}}{{#isLong}}int64(123){{/isLong}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
34+
{{/maxLength}}
35+
{{/minLength}}
36+
{{#minLength}}
37+
{{paramName}}Value := randString({{minLength}})
38+
{{/minLength}}
39+
{{#maxLength}}
40+
{{^minLength}}
41+
{{paramName}}Value := randString({{maxLength}})
42+
{{/minLength}}
43+
{{/maxLength}}
3244
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString({{paramName}}Value, "{{paramName}}")), -1){{/pathParams}}
3345

3446
test{{classname}}ServeMux := http.NewServeMux()

templates/go/utils.mustache

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,14 @@ func IsNil(i interface{}) bool {
362362
type MappedNullable interface {
363363
ToMap() (map[string]interface{}, error)
364364
}
365+
366+
const letterRunes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
367+
368+
// randString returns a random string with a specified length. It panics if n <= 0.
369+
func randString(n int) string {
370+
b := make([]byte, n)
371+
for i := range b {
372+
b[i] = letterRunes[rand.Intn(len(letterRunes))]
373+
}
374+
return string(b)
375+
}

0 commit comments

Comments
 (0)