Skip to content

Commit

Permalink
progress for go
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp committed Jan 30, 2024
1 parent 72383b8 commit f145701
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
stepOut.put("stepTemplate", "tests/client/createClient.mustache");
stepOut.put("isCreateClient", true); // TODO: remove once dart and kotlin are converted

stepOut.put("useEchoRequester", step.parameters == null || !step.parameters.containsKey("customHosts"));
if (step.parameters != null && step.parameters.containsKey("customHosts") && !"true".equals(System.getenv("CI"))) {
boolean hasCustomHosts = step.parameters != null && step.parameters.containsKey("customHosts");

stepOut.put("useEchoRequester", !hasCustomHosts);
stepOut.put("hasCustomHosts", hasCustomHosts);
if (hasCustomHosts && !"true".equals(System.getenv("CI"))) {
// hack for docker on mac, the `network=host` does not work so we need to use
// another local IP
step.parameters.put(
Expand Down
4 changes: 2 additions & 2 deletions scripts/cts/testServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function timeoutServer(): Promise<Server> {
timeoutCounter++;
// wait for 2.5 seconds before responding
setTimeout(() => {
res.send({ message: 'timeout test server response' });
res.json({ message: 'timeout test server response' });
}, 2500);
});

Expand All @@ -38,7 +38,7 @@ async function okServer(): Promise<Server> {
const app = express();
const port = 6678;
app.get('/1/test', (req, res) => {
res.send({ message: 'ok test server response' });
res.json({ message: 'ok test server response' });
});

const server = await new Promise<Server>((resolve) => {
Expand Down
5 changes: 5 additions & 0 deletions templates/go/tests/client/createClient.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ cfg = {{clientPrefix}}.Configuration{
Configuration: transport.Configuration{
AppID: "{{parametersWithDataTypeMap.appId.value}}",
ApiKey: "{{parametersWithDataTypeMap.apiKey.value}}",
{{#useEchoRequester}}
Requester: echo,
{{/useEchoRequester}}
{{#hasCustomHosts}}
Hosts: []transport.StatefulHost{ {{#parametersWithDataTypeMap.customHosts.value}}transport.NewStatefulHost("http", "{{value}}", call.IsReadWrite),{{/parametersWithDataTypeMap.customHosts.value}} },
{{/hasCustomHosts}}
},{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region.value}}
Region: {{clientPrefix}}.Region("{{parametersWithDataTypeMap.region.value}}"),{{/parametersWithDataTypeMap.region.value}}{{/hasRegionalHost}}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/go/tests/client/method.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_, err = client.{{#lambda.titlecase}}{{path}}{{/lambda.titlecase}}(client.NewApi{{#lambda.titlecase}}{{path}}{{/lambda.titlecase}}Request(
{{^useEchoRequester}}res, err := {{/useEchoRequester}}{{#useEchoRequester}}_, err = {{/useEchoRequester}}client.{{#lambda.titlecase}}{{path}}{{/lambda.titlecase}}(client.NewApi{{#lambda.titlecase}}{{path}}{{/lambda.titlecase}}Request(
{{#parametersWithDataType}}{{#required}}{{> tests/generateParams}},{{/required}}{{/parametersWithDataType}}
){{#parametersWithDataType}}{{^required}}.With{{#lambda.pascalcase}}{{{key}}}{{/lambda.pascalcase}}({{> tests/generateParams}}){{/required}}{{/parametersWithDataType}}{{#requestOptions}},
{{#queryParameters.parametersWithDataType}}{{clientPrefix}}.QueryParamOption("{{{key}}}", {{> tests/generateInnerParams}}),{{/queryParameters.parametersWithDataType}}{{#headers.parametersWithDataType}}{{clientPrefix}}.HeaderParamOption("{{{key}}}", {{> tests/generateInnerParams}}),{{/headers.parametersWithDataType}}
Expand Down
5 changes: 5 additions & 0 deletions templates/go/tests/client/suite.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{testType}}{{/lambda.titlecase}}{
{{#testHost}}
require.Equal(t, "{{{match}}}", echo.Host)
{{/testHost}}
{{#testResponse}}
rawBody, err := json.Marshal(res)
require.NoError(t, err)
require.JSONEq(t, `{{{match.parameters}}}`, string(rawBody))
{{/testResponse}}
{{/match}}
{{/isError}}
{{/steps}}
Expand Down
2 changes: 1 addition & 1 deletion templates/java/tests/client/createClient.mustache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{^autoCreateClient}}{{client}} client = {{/autoCreateClient}}new {{client}}("{{parametersWithDataTypeMap.appId.value}}","{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}},"{{parametersWithDataTypeMap.region.value}}"{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}{{#useEchoRequester}},withEchoRequester(){{/useEchoRequester}}{{#parametersWithDataTypeMap}}{{#customHosts}},withCustomHosts(Arrays.asList({{#customHosts.value}}new Host("{{value}}", EnumSet.of(CallType.READ, CallType.WRITE), "http"){{^-last}},{{/-last}}{{/customHosts.value}})){{/customHosts}}{{/parametersWithDataTypeMap}});
{{^autoCreateClient}}{{client}} client = {{/autoCreateClient}}new {{client}}("{{parametersWithDataTypeMap.appId.value}}","{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}},"{{parametersWithDataTypeMap.region.value}}"{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}{{#useEchoRequester}},withEchoRequester(){{/useEchoRequester}}{{#hasCustomHosts}},withCustomHosts(Arrays.asList({{#parametersWithDataTypeMap.customHosts.value}}new Host("{{value}}", EnumSet.of(CallType.READ, CallType.WRITE), "http"){{^-last}},{{/-last}}{{/parametersWithDataTypeMap.customHosts.value}})){{/hasCustomHosts}});
2 changes: 1 addition & 1 deletion templates/javascript/tests/client/createClient.mustache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{^autoCreateClient}}const $client = {{/autoCreateClient}}{{client}}('{{parametersWithDataTypeMap.appId.value}}','{{parametersWithDataTypeMap.apiKey.value}}',{{#hasRegionalHost}}'{{parametersWithDataTypeMap.region.value}}',{{/hasRegionalHost}}{ {{#useEchoRequester}}requester: echoRequester(),{{/useEchoRequester}}{{#parametersWithDataTypeMap}}{{#customHosts}}hosts:[{{#customHosts.value}}{ url: '{{value}}', accept: 'readWrite', protocol: 'http' },{{/customHosts.value}}]{{/customHosts}}{{/parametersWithDataTypeMap}}});
{{^autoCreateClient}}const $client = {{/autoCreateClient}}{{client}}('{{parametersWithDataTypeMap.appId.value}}','{{parametersWithDataTypeMap.apiKey.value}}',{{#hasRegionalHost}}'{{parametersWithDataTypeMap.region.value}}',{{/hasRegionalHost}}{ {{#useEchoRequester}}requester: echoRequester(),{{/useEchoRequester}}{{#hasCustomHosts}}hosts:[{{#parametersWithDataTypeMap.customHosts.value}}{ url: '{{value}}', accept: 'readWrite', protocol: 'http' },{{/parametersWithDataTypeMap.customHosts.value}}]{{/hasCustomHosts}}});

0 comments on commit f145701

Please sign in to comment.