Skip to content

Commit

Permalink
fix: Fix unit test template to support different type path parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopalet committed Nov 27, 2024
1 parent b67c0d0 commit d3c4cff
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions templates/go/api_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
{{#operation}}
t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) {
path := "{{{path}}}"{{#pathParams}}
{{paramName}}Value := {{#isString}}"{{paramName}}"{{/isString}}{{#isInteger}}int32(12345){{/isInteger}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
{{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}}
path = strings.Replace(path, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString({{paramName}}Value, "{{paramName}}")), -1){{/pathParams}}

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

0 comments on commit d3c4cff

Please sign in to comment.