Skip to content

Commit 428d85d

Browse files
authored
chore(cts): replace localhost at runtime (#3806)
1 parent aaae080 commit 428d85d

File tree

38 files changed

+617
-976
lines changed

38 files changed

+617
-976
lines changed

docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ services:
1313
- PHP_VERSION=${PHP_VERSION}
1414
- PYTHON_VERSION=${PYTHON_VERSION}
1515
command: tail -f /dev/null
16-
volumes: [./:/app]
16+
volumes: [ ./:/app ]
17+
1718
ruby:
1819
container_name: apic_ruby
1920
build:
@@ -24,7 +25,8 @@ services:
2425
- NODE_VERSION=${NODE_VERSION}
2526
- RUBY_VERSION=${RUBY_VERSION}
2627
command: tail -f /dev/null
27-
volumes: [./:/app]
28+
volumes: [ ./:/app ]
29+
2830
swift:
2931
container_name: apic_swift
3032
build:
@@ -35,4 +37,4 @@ services:
3537
- NODE_VERSION=${NODE_VERSION}
3638
- SWIFT_VERSION=${SWIFT_VERSION}
3739
command: tail -f /dev/null
38-
volumes: [./:/app]
40+
volumes: [ ./:/app ]

generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,11 @@ protected <T> Map<String, T[]> loadFullCTS(Class<T[]> jsonType) throws Exception
9595

9696
private String injectVariables(String json) {
9797
long threeDays = 3 * 24 * 60 * 60 * 1000;
98-
json = json
98+
return json
9999
.replace("${{language}}", language)
100100
.replace("${{languageCased}}", ctsManager.getLanguageCased())
101101
.replace("${{languageVersion}}", ctsManager.getVersion())
102102
.replace("${{clientPascalCase}}", Helpers.capitalize(Helpers.camelize(client)))
103103
.replace("\"${{nowRounded}}\"", String.valueOf(Math.round(System.currentTimeMillis() / threeDays) * threeDays));
104-
105-
if (!language.equals("javascript") && !"true".equals(System.getenv("CI"))) {
106-
// hack for docker on mac, the `network=host` does not work so we need to use
107-
// another local IP
108-
json = json.replace("${{localhost}}", "host.docker.internal");
109-
} else {
110-
json = json.replace("${{localhost}}", "localhost");
111-
}
112-
return json;
113104
}
114105
}

scripts/cts/testServer/timeout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function assertValidTimeouts(expectedCount: number): void {
4242
break;
4343
default:
4444
// the delay should be the same, because the `retryCount` is per host instead of global
45-
expect(state.duration[3 * i]).to.be.closeTo(state.duration[3 * i + 1], 100);
45+
expect(state.duration[3 * i]).to.be.closeTo(state.duration[3 * i + 1], 150);
4646
break;
4747
}
4848
}

templates/csharp/tests/client/createClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
{{#customHosts}}new () {
66
Scheme = HttpScheme.Http,
7-
Url = "{{host}}",
7+
Url = Environment.GetEnvironmentVariable("CI") == "true" ? "localhost" : "host.docker.internal",
88
Port = {{port}},
99
Up = true,
1010
LastUse = DateTime.UtcNow,

templates/csharp/tests/e2e/e2e.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Algolia.Search.e2e;
1919

2020
public class {{client}}RequestTestsE2E
2121
{
22-
private readonly {{client}} client;
22+
private readonly {{client}} client;
2323

2424
public {{client}}RequestTestsE2E()
2525
{

templates/dart/tests/client/client.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import '{{{import}}}';
33
import 'package:algolia_test/algolia_test.dart';
44
import 'package:test/test.dart';
55
import 'package:test_api/hooks.dart';
6+
import 'dart:io' show Platform;
67

78
void main() {
89
{{#blocksClient}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{^autoCreateClient}}final client = {{/autoCreateClient}}{{client}}(appId : "{{parametersWithDataTypeMap.appId.value}}", apiKey : "{{parametersWithDataTypeMap.apiKey.value}}",{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}}region: '{{parametersWithDataTypeMap.region.value}}',{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}options: ClientOptions({{#useEchoRequester}}requester: requester{{/useEchoRequester}}{{#hasCustomHosts}}hosts:[{{#customHosts}}Host.create(url: '{{host}}:{{port}}', scheme: 'http'),{{/customHosts}}]{{/hasCustomHosts}}));
1+
{{^autoCreateClient}}final client = {{/autoCreateClient}}{{client}}(appId : "{{parametersWithDataTypeMap.appId.value}}", apiKey : "{{parametersWithDataTypeMap.apiKey.value}}",{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}}region: '{{parametersWithDataTypeMap.region.value}}',{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}options: ClientOptions({{#useEchoRequester}}requester: requester{{/useEchoRequester}}{{#hasCustomHosts}}hosts:[{{#customHosts}}Host.create(url: (Platform.environment['CI'] == 'true' ? 'localhost' : 'host.docker.internal') + ':{{port}}', scheme: 'http'),{{/customHosts}}]{{/hasCustomHosts}}));

templates/go/tests/client/createClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cfg = {{clientPrefix}}.{{clientName}}Configuration{
66
Requester: echo,
77
{{/useEchoRequester}}
88
{{#hasCustomHosts}}
9-
Hosts: []transport.StatefulHost{ {{#customHosts}}transport.NewStatefulHost("http", "{{host}}:{{port}}", call.IsReadWrite),{{/customHosts}} },
9+
Hosts: []transport.StatefulHost{ {{#customHosts}}transport.NewStatefulHost("http", tests.GetLocalhost() + ":{{port}}", call.IsReadWrite),{{/customHosts}} },
1010
{{/hasCustomHosts}}
1111
{{#gzipEncoding}}
1212
Compression: compression.GZIP,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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}}{{#hasCustomHosts}},withCustomHosts(Arrays.asList({{#customHosts}}new Host("{{host}}", EnumSet.of(CallType.READ, CallType.WRITE), "http", {{port}}){{^-last}},{{/-last}}{{/customHosts}}), {{gzipEncoding}}){{/hasCustomHosts}});
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}}{{#hasCustomHosts}},withCustomHosts(Arrays.asList({{#customHosts}}new Host("true".equals(System.getenv("CI")) ? "localhost" : "host.docker.internal", EnumSet.of(CallType.READ, CallType.WRITE), "http", {{port}}){{^-last}},{{/-last}}{{/customHosts}}), {{gzipEncoding}}){{/hasCustomHosts}});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{^autoCreateClient}}const client = {{/autoCreateClient}}{{client}}('{{parametersWithDataTypeMap.appId.value}}','{{parametersWithDataTypeMap.apiKey.value}}',{{#hasRegionalHost}}'{{parametersWithDataTypeMap.region.value}}',{{/hasRegionalHost}}{ {{#useEchoRequester}}requester: nodeEchoRequester(),{{/useEchoRequester}}{{#hasCustomHosts}}hosts:[{{#customHosts}}{ url: '{{host}}', port: {{port}}, accept: 'readWrite', protocol: 'http' },{{/customHosts}}]{{/hasCustomHosts}} });
1+
{{^autoCreateClient}}const client = {{/autoCreateClient}}{{client}}('{{parametersWithDataTypeMap.appId.value}}','{{parametersWithDataTypeMap.apiKey.value}}',{{#hasRegionalHost}}'{{parametersWithDataTypeMap.region.value}}',{{/hasRegionalHost}}{ {{#useEchoRequester}}requester: nodeEchoRequester(),{{/useEchoRequester}}{{#hasCustomHosts}}hosts:[{{#customHosts}}{ url: 'localhost', port: {{port}}, accept: 'readWrite', protocol: 'http' },{{/customHosts}}]{{/hasCustomHosts}} });

0 commit comments

Comments
 (0)