diff --git a/config/clients.config.json b/config/clients.config.json index 0a3b6ee2c3b..7aaf4a39011 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -98,7 +98,12 @@ "snippets": { "extension": ".go", "outputFolder": "src" - } + }, + "supportedVersions": [ + "1.24.10", + "1.25.4", + "1.21.11" + ] }, "java": { "clients": [ diff --git a/config/generation.config.mjs b/config/generation.config.mjs index e8c48e38dc4..d7796dc9716 100644 --- a/config/generation.config.mjs +++ b/config/generation.config.mjs @@ -50,7 +50,7 @@ export const patterns = [ '!clients/algoliasearch-client-go/algolia/debug/*', '!clients/algoliasearch-client-go/algolia/utils/*', - '!tests/output/go/go.*', + 'tests/output/go/go.mod', // Java '!clients/algoliasearch-client-java/**', diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java index 45090a0da71..2ee3bc8cd15 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java @@ -35,6 +35,11 @@ public void addDataToBundle(Map bundle) throws GeneratorExceptio bundle.put("clientImport", clientPrefix); } + @Override + public void addTestsSupportingFiles(List supportingFiles) { + supportingFiles.add(new SupportingFile("tests/go.mod.mustache", "tests/output/go", "go.mod")); + } + @Override public void addSnippetsSupportingFiles(List supportingFiles, String output) { supportingFiles.add(new SupportingFile("snippets/.golangci.mustache", output + "/go/.golangci.yml")); diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index cbb20c25b6d..15d30f0c913 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -60,9 +60,7 @@ private String escapeBody(String body) { } switch (language) { - case "go": // jsonassert expect % to be formatted, we need to escape them - return body.replace("%", "%%"); - case "dart": // Same thing but for $ + case "dart": // Escape $ to avoid being used for string interpolation return body.replace("$", "\\$"); default: return body; diff --git a/templates/go/snippets/go.mod.mustache b/templates/go/snippets/go.mod.mustache index b86d5a2d26b..28d8b040091 100644 --- a/templates/go/snippets/go.mod.mustache +++ b/templates/go/snippets/go.mod.mustache @@ -1,6 +1,6 @@ module snippets -go 1.21.11 +go {{languageVersion}} replace github.com/algolia/algoliasearch-client-go/v4 => ../../../clients/algoliasearch-client-go diff --git a/templates/go/tests/e2e/e2e.mustache b/templates/go/tests/e2e/e2e.mustache index 23552e8e754..e096b848d6b 100644 --- a/templates/go/tests/e2e/e2e.mustache +++ b/templates/go/tests/e2e/e2e.mustache @@ -61,7 +61,7 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}E2E_{{#lambda unionBodyRaw, err := json.Marshal(unionBody) require.NoError(t, err) - jsonassert.New(t).Assertf(string(unionBodyRaw), expectedBodyRaw) + jsonassert.New(t).Assertf(string(unionBodyRaw), "%s", expectedBodyRaw) {{/body}} {{/response}} }) diff --git a/templates/go/tests/go.mod.mustache b/templates/go/tests/go.mod.mustache new file mode 100644 index 00000000000..3448f600ddf --- /dev/null +++ b/templates/go/tests/go.mod.mustache @@ -0,0 +1,18 @@ +module gotests + +go {{languageVersion}} + +replace github.com/algolia/algoliasearch-client-go/v4 => ../../../clients/algoliasearch-client-go + +require ( + github.com/algolia/algoliasearch-client-go/v4 v4.0.0 + github.com/joho/godotenv v1.5.1 + github.com/kinbiko/jsonassert v1.1.0 + github.com/stretchr/testify v1.11.1 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/templates/go/tests/requests/requests.mustache b/templates/go/tests/requests/requests.mustache index d1bb0c837b3..85d59bd274f 100644 --- a/templates/go/tests/requests/requests.mustache +++ b/templates/go/tests/requests/requests.mustache @@ -51,8 +51,7 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}_{{#lambda.ti require.Equal(t, "{{{method}}}", echo.Method) {{#body}} - ja := jsonassert.New(t) - ja.Assertf(*echo.Body, `{{{.}}}`) + jsonassert.New(t).Assertf(*echo.Body, "%s", `{{{.}}}`) {{/body}} {{^body}} {{#assertNullBody}}