Skip to content

Commit

Permalink
Merge pull request #22 from ayeshLK/main
Browse files Browse the repository at this point in the history
Add test cases for the package
  • Loading branch information
ayeshLK authored Feb 25, 2025
2 parents 386f42d + 5139e2b commit 44e2e72
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ jobs:
with:
package-name: aws.marketplace.mpm
package-org: ballerinax
additional-release-flags: "-x test"
83 changes: 83 additions & 0 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ modules = [
{org = "ballerina", packageName = "constraint", moduleName = "constraint"}
]

[[package]]
org = "ballerina"
name = "io"
version = "1.7.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]

[[package]]
org = "ballerina"
name = "jballerina.java"
Expand All @@ -26,6 +36,77 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"
scope = "testOnly"

[[package]]
org = "ballerina"
name = "lang.value"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "os"
version = "1.9.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "os", moduleName = "os"}
]

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
]

[[package]]
org = "ballerina"
name = "time"
Expand All @@ -44,6 +125,8 @@ version = "0.2.0"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "os"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"}
]
modules = [
Expand Down
4 changes: 2 additions & 2 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public isolated client class Client {
#
# + registrationToken - The registration-token provided by the customer
# + return - A Ballerina `mpm:Error` if there was an error while executing the operation or else `mpm:ResolveCustomerResponse`
remote function resolveCustomer(string registrationToken) returns ResolveCustomerResponse|Error =
isolated remote function resolveCustomer(string registrationToken) returns ResolveCustomerResponse|Error =
@java:Method {
'class: "io.ballerina.lib.aws.mpm.NativeClientAdaptor"
} external;
Expand All @@ -59,7 +59,7 @@ public isolated client class Client {
#
# + request - The request parameters for the `BatchMeterUsage` operation
# + return - A Ballerina `mpm:Error` if there was an error while executing the operation or else `mpm:BatchMeterUsageResponse`
remote function batchMeterUsage(*BatchMeterUsageRequest request) returns BatchMeterUsageResponse|Error {
isolated remote function batchMeterUsage(*BatchMeterUsageRequest request) returns BatchMeterUsageResponse|Error {
BatchMeterUsageRequest|constraint:Error validated = constraint:validate(request);
if validated is constraint:Error {
return error Error(string `Request validation failed: ${validated.message()}`);
Expand Down
48 changes: 48 additions & 0 deletions ballerina/tests/client_tests.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2025 WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/test;
import ballerina/os;

final string accessKeyId = os:getEnv("BALLERINA_AWS_TEST_ACCESS_KEY_ID");
final string secretAccessKey = os:getEnv("BALLERINA_AWS_TEST_SECRET_ACCESS_KEY");

final Client awsMarketplaceMpm = check initClient();

isolated function initClient() returns Client|error {
boolean enableTests = accessKeyId !is "" && secretAccessKey !is "";
if enableTests {
return new({
region: US_EAST_1,
auth: {accessKeyId, secretAccessKey}
});
}
return test:mock(Client);
}

@test:Config
isolated function testResolveCustomer() returns error? {
ResolveCustomerResponse reponse = check awsMarketplaceMpm->resolveCustomer("t12341");
test:assertTrue(reponse.customerAWSAccountId is string);
test:assertTrue(reponse.customerIdentifier is string);
test:assertTrue(reponse.productCode is string);
}

@test:Config
isolated function testBatchMeterUsage() returns error? {
BatchMeterUsageResponse response = check awsMarketplaceMpm->batchMeterUsage(productCode = "P1234");
test:assertTrue(response.results.length() > 0);
}

0 comments on commit 44e2e72

Please sign in to comment.