-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cts): split requests and e2e tests (#3339)
- Loading branch information
Showing
28 changed files
with
1,711 additions
and
1,072 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// {{generationBanner}} | ||
using Algolia.Search.Http; | ||
using Algolia.Search.Clients; | ||
using Algolia.Search.Models.{{clientPrefix}}; | ||
using Algolia.Search.Serializer; | ||
using Algolia.Search.Tests.Utils; | ||
using Xunit; | ||
using System.Text.Json; | ||
using Quibble.Xunit; | ||
using dotenv.net; | ||
using Action = Algolia.Search.Models.Search.Action; | ||
|
||
public class {{client}}RequestTestsE2E | ||
{ | ||
private readonly {{client}} _client; | ||
|
||
public {{client}}RequestTestsE2E() | ||
{ | ||
DotEnv.Load(options: new DotEnvOptions(ignoreExceptions: true, probeForEnv: true, probeLevelsToSearch: 8, envFilePaths: new[] { ".env" })); | ||
|
||
var appId = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID"); | ||
if (appId == null) | ||
{ | ||
throw new Exception("please provide an `ALGOLIA_APPLICATION_ID` env var for e2e tests"); | ||
} | ||
|
||
var apiKey = Environment.GetEnvironmentVariable("{{e2eApiKey}}"); | ||
if (apiKey == null) | ||
{ | ||
throw new Exception("please provide an `{{e2eApiKey}}` env var for e2e tests"); | ||
} | ||
|
||
_client = new {{client}}(new {{clientPrefix}}Config(appId, apiKey{{#hasRegionalHost}},"{{defaultRegion}}"{{/hasRegionalHost}})); | ||
} | ||
|
||
[Fact] | ||
public void Dispose() | ||
{ | ||
} | ||
|
||
{{#blocksE2E}} | ||
{{#tests}} | ||
[Fact(DisplayName = "{{{testName}}}")] | ||
public async Task {{#lambda.pascalcase}}{{method}}Test{{testIndex}}{{/lambda.pascalcase}}() | ||
{ | ||
try { | ||
var resp = await _client.{{#lambda.pascalcase}}{{method}}{{/lambda.pascalcase}}Async{{#isGeneric}}<Hit>{{/isGeneric}}({{#parametersWithDataType}}{{> tests/generateParams}}{{^-last}},{{/-last}}{{/parametersWithDataType}}{{#hasRequestOptions}}, new RequestOptions(){ | ||
{{#requestOptions.queryParameters}} | ||
QueryParameters = new Dictionary<string, object>(){ {{#parametersWithDataType}} {"{{{key}}}", {{> tests/requests/requestOptionsParams}} } {{^-last}},{{/-last}}{{/parametersWithDataType}} }, | ||
{{/requestOptions.queryParameters}} | ||
{{#requestOptions.headers}} | ||
Headers = new Dictionary<string, string>(){ {{#parametersWithDataType}} {"{{{key}}}", "{{{value}}}" } {{^-last}},{{/-last}}{{/parametersWithDataType}} }, | ||
{{/requestOptions.headers}} | ||
}{{/hasRequestOptions}}); | ||
{{#response}} | ||
{{#statusCode}} | ||
// Check status code {{statusCode}} | ||
Assert.NotNull(resp); | ||
{{/statusCode}} | ||
|
||
{{#body}} | ||
JsonAssert.EqualOverrideDefault("{{#lambda.escapeQuotes}}{{{.}}}{{/lambda.escapeQuotes}}", JsonSerializer.Serialize(resp, JsonConfig.Options), new JsonDiffConfig(true)); | ||
{{/body}} | ||
} catch (Exception e) | ||
{ | ||
Assert.Fail("An exception was thrown: " + e.Message); | ||
} | ||
{{/response}} | ||
} | ||
{{/tests}} | ||
{{/blocksE2E}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// {{generationBanner}} | ||
package requestse2e | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/joho/godotenv" | ||
|
||
"github.com/algolia/algoliasearch-client-go/v4/algolia/{{clientImport}}" | ||
) | ||
|
||
func createE2E{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}Client(t *testing.T) *{{clientPrefix}}.APIClient { | ||
t.Helper() | ||
appID := os.Getenv("ALGOLIA_APPLICATION_ID") | ||
if appID == "" && os.Getenv("CI") != "true" { | ||
err := godotenv.Load("../../../../.env") | ||
require.NoError(t, err) | ||
appID = os.Getenv("ALGOLIA_APPLICATION_ID") | ||
} | ||
apiKey := os.Getenv("{{e2eApiKey}}") | ||
client, err := {{clientPrefix}}.NewClient(appID, apiKey, {{#hasRegionalHost}}{{clientPrefix}}.{{#lambda.uppercase}}{{defaultRegion}}{{/lambda.uppercase}},{{/hasRegionalHost}}) | ||
require.NoError(t, err) | ||
|
||
return client | ||
} | ||
|
||
{{#blocksE2E}} | ||
func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}E2E_{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}(t *testing.T) { | ||
{{#tests}} | ||
t.Run("{{{testName}}}", func(t *testing.T) { | ||
client := createE2E{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}Client(t) | ||
res, err := client.{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}({{#hasOperationParams}}client.NewApi{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}Request( | ||
{{#parametersWithDataType}}{{#required}}{{> tests/generateParams}},{{/required}}{{/parametersWithDataType}} | ||
){{#parametersWithDataType}}{{^required}}.With{{#lambda.pascalcase}}{{{key}}}{{/lambda.pascalcase}}({{> tests/generateParams}}){{/required}}{{/parametersWithDataType}}{{/hasOperationParams}}{{#requestOptions}}{{#hasOperationParams}},{{/hasOperationParams}} | ||
{{#queryParameters.parametersWithDataType}}{{clientPrefix}}.QueryParamOption("{{{key}}}", {{> tests/generateInnerParams}}),{{/queryParameters.parametersWithDataType}}{{#headers.parametersWithDataType}}{{clientPrefix}}.HeaderParamOption("{{{key}}}", {{> tests/generateInnerParams}}),{{/headers.parametersWithDataType}} | ||
{{/requestOptions}}) | ||
require.NoError(t, err) | ||
_ = res | ||
|
||
{{#response}} | ||
{{#body}} | ||
rawBody, err := json.Marshal(res) | ||
require.NoError(t, err) | ||
|
||
var rawBodyMap any | ||
err = json.Unmarshal(rawBody, &rawBodyMap) | ||
require.NoError(t, err) | ||
|
||
expectedBodyRaw := `{{{.}}}` | ||
var expectedBody any | ||
err = json.Unmarshal([]byte(expectedBodyRaw), &expectedBody) | ||
require.NoError(t, err) | ||
|
||
unionBody := tests.Union(expectedBody, rawBodyMap) | ||
unionBodyRaw, err := json.Marshal(unionBody) | ||
require.NoError(t, err) | ||
|
||
jsonassert.New(t).Assertf(string(unionBodyRaw), expectedBodyRaw) | ||
{{/body}} | ||
{{/response}} | ||
}) | ||
{{/tests}} | ||
} | ||
|
||
{{/blocksE2E}} |
Oops, something went wrong.