diff --git a/languages/golang/templates/api_test.mustache b/languages/golang/templates/api_test.mustache deleted file mode 100644 index b731661..0000000 --- a/languages/golang/templates/api_test.mustache +++ /dev/null @@ -1,132 +0,0 @@ -/* -{{#appName}} -{{{.}}} -{{/appName}} - -Testing {{classname}}Service - -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); - -package {{packageName}} - -import ( - "context" - "encoding/json" - "net/http" - "net/http/httptest" - "net/url" - "strings" - "testing" - "github.com/stackitcloud/stackit-sdk-go/core/config" -) - -func Test_{{packageName}}_{{classname}}Service(t *testing.T) { - -{{#operations}} -{{#operation}} - t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) { - _apiUrlPath := "{{{path}}}"{{#pathParams}} - {{^minLength}} - {{^maxLength}} - {{paramName}}Value := {{#isEnumRef}}{{^isString}}{{dataType}}({{{defaultValue}}}){{/isString}}{{/isEnumRef}}{{#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}}{{^isEnumRef}}{{{defaultValue}}}{{/isEnumRef}}{{/isInteger}}{{/isString}} - {{/maxLength}} - {{/minLength}} - {{#minLength}} - {{paramName}}Value := randString({{minLength}}) - {{/minLength}} - {{#maxLength}} - {{^minLength}} - {{paramName}}Value := randString({{maxLength}}) - {{/minLength}} - {{/maxLength}} - _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString({{paramName}}Value, "{{paramName}}")), -1){{/pathParams}} - - test{{classname}}ServeMux := http.NewServeMux() - test{{classname}}ServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { - {{! Only binary data sets a ReturnFormat}} - {{#returnFormat}} - w.Header().Add("Content-Type", "application/octet-stream") - binaryData := []byte{0x42, 0x69} // Example binary data - w.Write(binaryData) - {{/returnFormat}} - {{^returnFormat}} - {{#returnType}} - {{#returnProperty.isPrimitiveType}} - {{! according to the model, freeform objects might be primitive...}} - {{#returnProperty.isFreeFormObject}} - data := {{{.}}}{} - {{/returnProperty.isFreeFormObject}} - {{^returnProperty.isFreeFormObject}} - var data {{{.}}} - {{/returnProperty.isFreeFormObject}} - {{/returnProperty.isPrimitiveType}} - {{^returnProperty.isPrimitiveType}} - data := {{{.}}}{} - {{/returnProperty.isPrimitiveType}} - w.Header().Add("Content-Type", "application/json") - json.NewEncoder(w).Encode(data) - {{/returnType}} - {{/returnFormat}} - }) - testServer := httptest.NewServer(test{{classname}}ServeMux) - defer testServer.Close() - - configuration := &config.Configuration{ - DefaultHeader: make(map[string]string), - UserAgent: "OpenAPI-Generator/1.0.0/go", - Debug: false, - Region: "test_region", - Servers: config.ServerConfigurations{ - { - URL: testServer.URL, - Description: "Localhost for {{packageName}}_{{classname}}", - Variables: map[string]config.ServerVariable{ - "region": { - DefaultValue: "test_region.", - EnumValues: []string{ - "test_region.", - }, - }, - }, - }, - }, - OperationServers: map[string]config.ServerConfigurations{}, - } - apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication()) - if err != nil { - t.Fatalf("creating API client: %v", err) - } - - {{#allParams}} - {{#required}} - {{#isPathParam}} - {{paramName}} := {{paramName}}Value - {{/isPathParam}} - {{^isPathParam}} - {{#isPrimitiveType}} - var {{paramName}} {{dataType}} - {{/isPrimitiveType}} - {{^isPrimitiveType}} - {{paramName}} := {{dataType}}{} - {{/isPrimitiveType}} - {{/isPathParam}} - {{/required}} - {{/allParams}} - - {{#returnType}}resp, {{/returnType}}reqErr := apiClient.{{operationId}}(context.Background(){{#pathParams}}, {{paramName}}{{/pathParams}}){{#allParams}}{{^isPathParam}}{{#required}}.{{vendorExtensions.x-export-param-name}}({{paramName}}){{/required}}{{/isPathParam}}{{/allParams}}.Execute() - - if reqErr != nil { - t.Fatalf("error in call: %v", reqErr) - } - {{#returnType}} - if IsNil(resp) { - t.Fatalf("response not present") - } - {{/returnType}} - }) - -{{/operation}} -{{/operations}} -} diff --git a/scripts/generate-sdk/languages/go.sh b/scripts/generate-sdk/languages/go.sh index 97c3eee..4c109f9 100644 --- a/scripts/generate-sdk/languages/go.sh +++ b/scripts/generate-sdk/languages/go.sh @@ -160,7 +160,7 @@ generate_go_sdk() { --git-host "${GIT_HOST}" \ --git-user-id "${GIT_USER_ID}" \ --git-repo-id "${GIT_REPO_ID}" \ - --global-property apis,models,modelTests=true,modelDocs=false,apiDocs=false,supportingFiles \ + --global-property apis,models,modelTests=true,modelDocs=false,apiDocs=false,supportingFiles,apiTests=false \ --additional-properties=isGoSubmodule=true,enumClassPrefix=true,generateInterfaces=true,$regional_api \ --http-user-agent "stackit-sdk-go/${service}" \ --reserved-words-mappings type=types \ @@ -182,10 +182,6 @@ generate_go_sdk() { fi fi - # Move tests to the service folder - cp "${SERVICES_FOLDER}"/"${service}"/test/* "${SERVICES_FOLDER}/${service}" - rm -r "${SERVICES_FOLDER}/${service}/test/" - # If the service has a wait package files, move them inside the service folder if [ -d "${sdk_services_backup_dir}/${service}/wait" ]; then echo "Found ${service} \"wait\" package"