Skip to content

Commit

Permalink
Add test for SubscriptionAPIPolicy generation from apk-conf
Browse files Browse the repository at this point in the history
  • Loading branch information
ashera96 committed Nov 9, 2023
1 parent 98d2e66 commit 0eccacf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions runtime/config-deployer-service/ballerina/tests/APIClientTest.bal
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,26 @@ public function testBasicAPIFromAPKConf() returns error? {

}

@test:Config {}
public function testSubscriptionAPIPolicyGenerationFromAPKConf() returns error? {

GenerateK8sResourcesBody body = {};
body.apkConfiguration = {fileName: "sub-validation.apk-conf", fileContent: check io:fileReadBytes("./tests/resources/sub-validation.apk-conf")};
body.definitionFile = {fileName: "api.yaml", fileContent: check io:fileReadBytes("./tests/resources/api.yaml")};
body.apiType = "REST";
APIClient apiClient = new;

model:APIArtifact apiArtifact = check apiClient.prepareArtifact(body.apkConfiguration, body.definitionFile, organization);

boolean expectedAPIPolicySpec = true;
foreach model:APIPolicy apiPolicy in apiArtifact.apiPolicies {
model:APIPolicyData? policyData = apiPolicy.spec.default;
if (policyData is model:APIPolicyData) {
test:assertEquals(policyData.subscriptionValidation, expectedAPIPolicySpec, "Subscription Policy is not equal to expected Subscription Policy");
}
}
}

public function APIToAPKConfDataProvider() returns map<[runtimeModels:API, APKConf]>|error {
runtimeModels:API api = runtimeModels:newAPI1();
api.setName("testAPI");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: api1
version: 1.0.0
basePath: /api1/1.0.0
type: REST
defaultVersion: true
subscriptionValidation: true
endpointConfigurations:
production:
endpoint: http://backend.test-apk.svc.cluster.local:80
sandbox:
endpoint: http://backend.test-apk.svc.cluster.local:80
operations:
- target: /get
verb: GET
secured: false
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ basePath: "/c2FtcGxlLWFwaTIuMC4w"
version: "2.0.0"
type: "REST"
defaultVersion: false
subscriptionValidation: false
endpointConfigurations:
production:
endpoint: "https://httpbin.org"
Expand Down

0 comments on commit 0eccacf

Please sign in to comment.