Skip to content

Commit fc09ddc

Browse files
authored
fix: Fix unit test template to support different type path parameters (#112)
1 parent b67c0d0 commit fc09ddc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

templates/go/api_test.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
2828
{{#operation}}
2929
t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) {
3030
path := "{{{path}}}"{{#pathParams}}
31-
{{paramName}}Value := {{#isString}}"{{paramName}}"{{/isString}}{{#isInteger}}int32(12345){{/isInteger}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
31+
{{paramName}}Value := {{#isString}}"{{paramName}}"{{/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}}
3232
path = strings.Replace(path, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString({{paramName}}Value, "{{paramName}}")), -1){{/pathParams}}
3333

3434
test{{classname}}ServeMux := http.NewServeMux()
@@ -79,7 +79,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
7979
{{#allParams}}
8080
{{#required}}
8181
{{#isPathParam}}
82-
{{paramName}} := {{#isString}}"{{paramName}}"{{/isString}}{{#isInteger}}int32(12345){{/isInteger}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
82+
{{paramName}} := {{#isString}}"{{paramName}}"{{/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}}
8383
{{/isPathParam}}
8484
{{^isPathParam}}
8585
{{#isPrimitiveType}}

0 commit comments

Comments
 (0)