Skip to content

Commit ecbbc96

Browse files
committed
additional test with readme update
1 parent 715c44b commit ecbbc96

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Major features:
88
- Parses `OpenAPI v3.0` Swagger files,
99
- swagger.json can be loaded from `disk` or from `URL`,
1010
- access swagger.json from URL, which is protected by `basic authentication`,
11-
- control which swagger endpoints are called by specifying `request filters` (check below)
11+
- control which swagger endpoints are returned by specifying `request filters` (check below)
1212

1313
## Sample
1414

@@ -45,7 +45,7 @@ The above code is quite simple, but it needs some explanation.
4545
If your Swagger.json files are protected by basic authentication, you can set those with `AddBasicAuthentication`.
4646

4747
#### 2. AddRequestFilters
48-
Filters comprise of different types. Those are `AuthenticationTypes`, `TestTypes` and `EndpointNameWhitelist`.
48+
Filters comprise of different types. Those are `AuthenticationTypes`, `TestTypes` and `EndpointNameWhitelist`. All are optional.
4949

5050
##### 2.1. AuthenticationTypes
5151
Here we specify a list of Authentication types, that will be filtered out from the whole swagger file. This is where QA Tool Kit presents a convention.
@@ -58,7 +58,7 @@ The built-in types are:
5858

5959
In order to apply filters, you need to tag your API endpoints with those strings.
6060

61-
We normally do it in Swagger endpoint description. An example might be: `Get categories from the system. @customer,@administrator,@oauth2.`
61+
We normally do that, by adding the tags in the Swagger endpoint description. An example might be: `Get categories from the system. @customer,@administrator,@oauth2.`
6262

6363
This is an example from swagger.json excerpt:
6464

@@ -76,13 +76,13 @@ This is an example from swagger.json excerpt:
7676
Parser then finds those string in the description field and populates the `RequestFilter` property.
7777

7878
##### 2.2 TestTypes
79-
Similarly as in the `AuthenticationTypes` you can filter out certain endpoints to be used in certain test scenarios. Currently libraray supports:
79+
Similarly as in the `AuthenticationTypes` you can filter out certain endpoints to be used in different test scenarios. Currently library supports:
8080

8181
- TestType.LoadTest which specifies a string `"@loadtest"`,
8282
- TestType.IntegrationTest which specifies a string `"@integrationtest"`,
8383
- TestType.SecurityTest which specifies a string `"@securitytest"`,
8484

85-
The same swagger-json excerpt which allows load and integration tests.
85+
The same swagger.json excerpt which support test type tags might look like this:
8686

8787
```json
8888
"/v{version}/categories?parent={parentId}": {
@@ -95,6 +95,8 @@ The same swagger-json excerpt which allows load and integration tests.
9595
"operationId": "GetCategories",
9696
```
9797

98+
If you feed the list of `HttpRequest` objects with load type tags to the library like `QAToolKit.Engine.Bombardier`, only those requests will be tested.
99+
98100
##### 2.3 EndpointNameWhitelist
99101
Final `RequestFilter` option is `EndpointNameWhitelist`. With it you can specify a list of endpoints that will be included in the results.
100102

src/QAToolKit.Source.Swagger.Test/SwaggerTests/PetApi/Get/SwaggerProcessorPetApiTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Logging;
22
using Newtonsoft.Json;
3+
using QAToolKit.Core.Models;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -37,5 +38,27 @@ public async Task AllEndpointsSuccessfull()
3738
Assert.NotNull(requests);
3839
Assert.Equal(19, requests.Count);
3940
}
41+
42+
[Fact]
43+
public async Task OnlySpecifiedEndpointsSuccessfull()
44+
{
45+
var fileSource = new SwaggerFileSource(options =>
46+
{
47+
options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
48+
options.AddRequestFilters(new RequestFilter()
49+
{
50+
EndpointNameWhitelist = new string[] { "findPetsByStatus", "deletePet", "addPet", "updatePet" }
51+
});
52+
});
53+
54+
var requests = await fileSource.Load(new List<FileInfo>() {
55+
new FileInfo("Assets/swagger-pets-test.json")
56+
});
57+
58+
_logger.LogInformation(JsonConvert.SerializeObject(requests, Formatting.Indented));
59+
60+
Assert.NotNull(requests);
61+
Assert.Equal(4, requests.Count);
62+
}
4063
}
4164
}

0 commit comments

Comments
 (0)