From 51e6a11d12a0952e72228aa9469b036f22b2b3d6 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Thu, 2 Nov 2023 12:38:55 +0530 Subject: [PATCH 1/6] Improve test cases --- .github/workflows/pull-request.yml | 17 ++++ ballerina/Dependencies.toml | 4 + ballerina/tests/endpoint-tests.bal | 38 ++++----- ballerina/tests/init.bal | 77 +++++++++++++++--- .../tests/platform-application-tests.bal | 15 ++-- ballerina/tests/publish-tests.bal | 5 +- ballerina/tests/sms-attributes-tests.bal | 22 ++++-- ballerina/tests/sms-sandbox-tests.bal | 21 +++-- ballerina/tests/subscription-tests.bal | 11 ++- ballerina/tests/topics-tests.bal | 78 ++++++++++--------- ballerina/utils.bal | 3 +- 11 files changed, 196 insertions(+), 95 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index d21ad67..e3fa188 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -20,5 +20,22 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm +# # Build Module Examples +# - name: Ballerina Examples Build +# run: chmod +x ./examples/build.sh && ./examples/build.sh build +# env: +# JAVA_HOME: /usr/lib/jvm/default-jvm + + # Test Ballerina Project + - name: Ballerina Test + # tests will be skipped if the PR is from a forked repository (as the secrets are not available) + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + run: bal test ./ballerina --test-report --code-coverage --coverage-format=xml + env: + JAVA_HOME: /usr/lib/jvm/default-jvm + ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} + SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} + REGION: ${{ secrets.REGION }} + - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 4ec27a9..927de0b 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -240,6 +240,9 @@ dependencies = [ {org = "ballerina", name = "lang.value"}, {org = "ballerina", name = "observe"} ] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] [[package]] org = "ballerina" @@ -354,6 +357,7 @@ dependencies = [ {org = "ballerina", name = "lang.int"}, {org = "ballerina", name = "lang.regexp"}, {org = "ballerina", name = "lang.runtime"}, + {org = "ballerina", name = "log"}, {org = "ballerina", name = "mime"}, {org = "ballerina", name = "random"}, {org = "ballerina", name = "test"}, diff --git a/ballerina/tests/endpoint-tests.bal b/ballerina/tests/endpoint-tests.bal index a712c04..3ac6416 100644 --- a/ballerina/tests/endpoint-tests.bal +++ b/ballerina/tests/endpoint-tests.bal @@ -16,19 +16,11 @@ import ballerina/test; -string applicationArn = ""; - -@test:BeforeGroups {value: ["endpoint"]} -function beforeEndpointTests() returns error? { - applicationArn = check amazonSNSClient->createPlatformApplication(testRunId + "FirebasePlatformApplication", - FIREBASE_CLOUD_MESSAGING, auth = {platformCredential: firebaseServerKey}); -} - @test:Config { groups: ["endpoint"] } function createEndpointTest() returns error? { - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken"); + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken"); test:assertTrue(isArn(arn)); } @@ -36,7 +28,7 @@ function createEndpointTest() returns error? { groups: ["endpoint"] } function createEndpointWithEmptyTokenTest() returns error? { - string|Error arn = amazonSNSClient->createEndpoint(applicationArn, ""); + string|Error arn = amazonSNSClient->createEndpoint(testApplication, ""); test:assertTrue(arn is OperationError); test:assertEquals((arn).message(), "Invalid parameter: Token Reason: cannot be empty"); } @@ -47,14 +39,14 @@ function createEndpointWithEmptyTokenTest() returns error? { function createEndpointWithInvalidArnTest() returns error? { string|Error arn = amazonSNSClient->createEndpoint(invalidApplicationArn, testRunId + "testDeviceToken2"); test:assertTrue(arn is OperationError); - test:assertEquals((arn).message(), "Invalid parameter: PlatformApplicationArn Reason: Wrong number of slashes in relative portion of the ARN."); + test:assertEquals((arn).message(), "Invalid parameter: PlatformApplicationArn Reason: An ARN must have at least 6 elements, not 1"); } @test:Config { groups: ["endpoint"] } function createEndpointWithCustomUserDataTest() returns error? { - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken3", + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken3", customUserData = "testCustomUserData"); test:assertTrue(isArn(arn)); } @@ -64,7 +56,7 @@ function createEndpointWithCustomUserDataTest() returns error? { } function createEndpointWithAttributes() returns error? { EndpointAttributes attributes = {enabled: true, token: testRunId + "testToken4", customUserData: "testCustomUserData2"}; - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken4", attributes); + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken4", attributes); test:assertTrue(isArn(arn)); } @@ -73,7 +65,7 @@ function createEndpointWithAttributes() returns error? { } function createEndpointWithInvalidAttributes() returns error? { EndpointAttributes attributes = {enabled: true, token: "", customUserData: "testCustomUserData2"}; - string|Error arn = amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken5", attributes); + string|Error arn = amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken5", attributes); test:assertTrue(arn is OperationError); test:assertEquals((arn).message(), "Invalid parameter: Attributes Reason: Invalid value for attribute: Token: cannot be empty"); } @@ -83,15 +75,15 @@ function createEndpointWithInvalidAttributes() returns error? { } function listPlatformApplicationEndpointsTest() returns error? { EndpointAttributes attributes = {enabled: false}; - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceTokenNew", attributes, + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceTokenNew", attributes, "CustomDataNew"); foreach int i in 0...100 { - _ = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken0" + i.toString()); + _ = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken0" + i.toString()); } stream endpointStream = - amazonSNSClient->listEndpoints(applicationArn); + amazonSNSClient->listEndpoints(testApplication); Endpoint[] endpoints = check from Endpoint endpoint in endpointStream select endpoint; @@ -111,7 +103,7 @@ function listPlatformApplicationEndpointsTest() returns error? { } function getEndpointAttributesTest() returns error? { EndpointAttributes attributes = {enabled: false}; - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken7", attributes, + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken7", attributes, "CustomData7"); EndpointAttributes retrievedAttributes = check amazonSNSClient->getEndpointAttributes(arn); @@ -125,7 +117,7 @@ function getEndpointAttributesTest() returns error? { } function getEndpointAttributesWithInvalidArnTest() returns error? { EndpointAttributes attributes = {enabled: false}; - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken7", attributes, + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken7", attributes, "CustomData7"); EndpointAttributes|Error retrievedAttributes = amazonSNSClient->getEndpointAttributes(arn + "invalid"); @@ -137,7 +129,7 @@ function getEndpointAttributesWithInvalidArnTest() returns error? { groups: ["endpoint"] } function setEndpointAttributesTest() returns error? { - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken8"); + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken8"); _ = check amazonSNSClient->setEndpointAttributes(arn, { enabled: false, token: testRunId + "testDeviceToken9", customUserData: "CustomData9" }); @@ -152,7 +144,7 @@ function setEndpointAttributesTest() returns error? { groups: ["endpoint"] } function setEndpointAttributesWithInvalidArnTest() returns error? { - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken10"); + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken10"); Error? e = amazonSNSClient->setEndpointAttributes(arn + "invalid", { enabled: false, token: testRunId + "testDeviceToken10", @@ -167,7 +159,7 @@ function setEndpointAttributesWithInvalidArnTest() returns error? { groups: ["endpoin"] } function deleteEndpointTest() returns error? { - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken11"); + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken11"); _ = check amazonSNSClient->deleteEndpoint(arn); EndpointAttributes|Error attributes = amazonSNSClient->getEndpointAttributes(arn); @@ -179,7 +171,7 @@ function deleteEndpointTest() returns error? { groups: ["endpoint"] } function deleteEndpointWithInvalidTest() returns error? { - string arn = check amazonSNSClient->createEndpoint(applicationArn, testRunId + "testDeviceToken11"); + string arn = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken11"); Error? e = amazonSNSClient->deleteEndpoint(arn + "invalid"); test:assertTrue(e is OperationError); diff --git a/ballerina/tests/init.bal b/ballerina/tests/init.bal index 3b20395..38aece1 100644 --- a/ballerina/tests/init.bal +++ b/ballerina/tests/init.bal @@ -16,6 +16,10 @@ import ballerina/time; import ballerina/lang.regexp; +import ballerina/test; +import ballerina/log; + +string testRunId = regexp:replaceAll(re `[:.]`, time:utcToString(time:utcNow()), ""); configurable string accessKeyId = ?; configurable string secretAccessKey = ?; @@ -24,22 +28,77 @@ configurable string region = ?; ConnectionConfig config = { accessKeyId: accessKeyId, secretAccessKey: secretAccessKey, - region: region + region: region, + retryConfig: { + count: 3, + interval: 10 + } }; Client amazonSNSClient = check new(config); -string testRunId = regexp:replaceAll(re `[:.]`, time:utcToString(time:utcNow()), ""); +string testHttp = "http://www.wso2.com"; +string testHttps = "https://www.wso2.com"; +string testEmail = "test@wso2.com"; +string testPhoneNumber = "+94123456789"; +string testApplication = ""; +string testEndpoint = ""; -configurable string testHttp = ?; -configurable string testHttps = ?; -configurable string testEmail = ?; -configurable string testPhoneNumber = ?; -configurable string testApplication = ?; +configurable string amazonClientId = ?; +configurable string amazonClientSecret = ?; configurable string testIamRole = ?; configurable string testAwsAccountId = ?; -configurable string testEndpoint = ?; - + +@test:BeforeSuite +function resetEnvironment() returns error? { + check deleteAllTopics(); + check deleteAllPlatformApplications(); + check deleteAllSubscriptions(); + check initializeTestVariables(); +} + +// Existing topics need to be deleted as SNS imposes a limit on the # of topics an account may have +function deleteAllTopics() returns error? { + stream topicStream = amazonSNSClient->listTopics(); + string[] topicArns = check from string topicArn in topicStream select topicArn; + + foreach int i in 1...topicArns.length() { + check amazonSNSClient->deleteTopic(topicArns[i-1]); + log:printInfo(i.toString() + "/" + topicArns.length().toString() + " topics deleted - " + topicArns[i-1]); + } +} + +// Existing applications need to be deleted as SNS imposes a limit on the # of applications an account may have +function deleteAllPlatformApplications() returns error? { + stream applicationStream = amazonSNSClient->listPlatformApplications(); + string[] applicationArns = check from PlatformApplication application in applicationStream + select application.platformApplicationArn; + + foreach int i in 1...applicationArns.length() { + check amazonSNSClient->deletePlatformApplication(applicationArns[i-1]); + log:printInfo(i.toString() + "/" + applicationArns.length().toString() + " platform applications deleted"); + } +} + +// Existing subscriptions need to be deleted as SNS imposes a limit on the # of subscriptions an account may have +function deleteAllSubscriptions() returns error? { + stream subscriptionStream = amazonSNSClient->listSubscriptions(); + string[] subscriptionArns = check from Subscription subscription in subscriptionStream + where subscription.subscriptionArn != "PendingConfirmation" + select subscription.subscriptionArn; + + foreach int i in 1...subscriptionArns.length() { + check amazonSNSClient->unsubscribe(subscriptionArns[i-1]); + log:printInfo(i.toString() + "/" + subscriptionArns.length().toString() + " subscriptions deleted"); + } +} + +function initializeTestVariables() returns error? { + testApplication = check amazonSNSClient->createPlatformApplication(testRunId + "AmazonPlatformApplication", + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}); + testEndpoint = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken"); +} + function isArn(string arn) returns boolean { return arn.startsWith("arn:aws:"); } diff --git a/ballerina/tests/platform-application-tests.bal b/ballerina/tests/platform-application-tests.bal index 7e76354..0bcbff5 100644 --- a/ballerina/tests/platform-application-tests.bal +++ b/ballerina/tests/platform-application-tests.bal @@ -17,16 +17,13 @@ import ballerina/test; import ballerina/lang.runtime as runtime; -configurable string firebaseServerKey = ?; -configurable string amazonClientId = ?; -configurable string amazonClientSecret = ?; - @test:Config { - groups: ["platformApplication"] + groups: ["platformApplication"], + enable: false } function createFirebasePlatformApplicationTest() returns error? { string arn = check amazonSNSClient->createPlatformApplication(testRunId + "FirebasePlatformApplication", - FIREBASE_CLOUD_MESSAGING, auth = {platformCredential: firebaseServerKey}); + FIREBASE_CLOUD_MESSAGING, auth = {platformCredential: ""}); test:assertTrue(isArn(arn)); } @@ -145,6 +142,12 @@ function listPlatformApplicationsTest() returns error? { string arn = check amazonSNSClient->createPlatformApplication(testRunId + "ListPlatformApplications", AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, attributes = attributes); + + foreach int i in 0...100 { + _ = check amazonSNSClient->createPlatformApplication(testRunId + "ListPlatformApplications" + i.toString(), + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + attributes = attributes); + } // Validate newly created platform application stream platformApplications = amazonSNSClient->listPlatformApplications(); diff --git a/ballerina/tests/publish-tests.bal b/ballerina/tests/publish-tests.bal index 8940ab0..316e1bf 100644 --- a/ballerina/tests/publish-tests.bal +++ b/ballerina/tests/publish-tests.bal @@ -98,8 +98,7 @@ function publishToInvalidPhoneNumber() returns error? { } @test:Config { - groups: ["publish"], - enable: false + groups: ["publish"] } function publishToApplication() returns error? { PublishMessageResponse response = check amazonSNSClient->publish(testEndpoint, "Test Message", @@ -114,7 +113,7 @@ function publishToInvalidApplication() returns error? { PublishMessageResponse|Error response = amazonSNSClient->publish(invalidApplicationArn, "Test Message", targetType = ARN); test:assertTrue(response is OperationError); - test:assertEquals((response).message(), "Invalid parameter: TargetArn Reason: ARN specifies an invalid endpointId: UUID must be encoded in exactly 36 characters."); + test:assertEquals((response).message(), "Invalid parameter: TargetArn Reason: An ARN must have at least 6 elements, not 1"); } @test:Config { diff --git a/ballerina/tests/sms-attributes-tests.bal b/ballerina/tests/sms-attributes-tests.bal index 3478a52..3ae983d 100644 --- a/ballerina/tests/sms-attributes-tests.bal +++ b/ballerina/tests/sms-attributes-tests.bal @@ -15,11 +15,15 @@ // under the License. import ballerina/test; +import ballerina/lang.runtime; + +// We need to wait 2s between each request because SMSAttributes APIs are throttled at 1 per second @test:Config { groups: ["sms-attributes"] } function setSMSAttributesTest() returns error? { + runtime:sleep(2); check amazonSNSClient->setSMSAttributes({ monthlySpendLimit: 1, deliveryStatusIAMRole: testIamRole, @@ -30,9 +34,11 @@ function setSMSAttributesTest() returns error? { } @test:Config { - groups: ["sms-attributes"] + groups: ["sms-attributes"], + dependsOn: [setSMSAttributesTest] } function setSMSAttributesWithInvalidSenderIDTest() returns error? { + runtime:sleep(2); Error? e = amazonSNSClient->setSMSAttributes({ monthlySpendLimit: 1, deliveryStatusIAMRole: testIamRole, @@ -45,9 +51,11 @@ function setSMSAttributesWithInvalidSenderIDTest() returns error? { } @test:Config { - groups: ["sms-attributes"] + groups: ["sms-attributes"], + dependsOn: [setSMSAttributesWithInvalidSenderIDTest] } function setSMSAttributesWithInvalidS3BucketTest() returns error? { + runtime:sleep(2); Error? e = amazonSNSClient->setSMSAttributes({ monthlySpendLimit: 1, deliveryStatusIAMRole: testIamRole, @@ -61,9 +69,11 @@ function setSMSAttributesWithInvalidS3BucketTest() returns error? { } @test:Config { - groups: ["sms-attributes"] + groups: ["sms-attributes"], + dependsOn: [setSMSAttributesWithInvalidS3BucketTest] } function setSMSAttributesWithInvalidSampleRateTest() returns error? { + runtime:sleep(2); Error? e = amazonSNSClient->setSMSAttributes({ monthlySpendLimit: 1, deliveryStatusIAMRole: testIamRole, @@ -72,13 +82,15 @@ function setSMSAttributesWithInvalidSampleRateTest() returns error? { defaultSMSType: TRANSACTIONAL }); test:assertTrue(e is OperationError, "OperationError expected."); - test:assertEquals((e).message(), "Invalid parameter: UsageReportS3Bucket Reason: The bucket you provided does not exist"); + test:assertEquals((e).message(), "DeliveryStatusSuccessSamplingRate is not an integer between 0-100"); } @test:Config { - groups: ["sms-attributes"] + groups: ["sms-attributes"], + dependsOn: [setSMSAttributesWithInvalidSampleRateTest] } function getSMSAttributesTest() returns error? { + runtime:sleep(2); check amazonSNSClient->setSMSAttributes({ monthlySpendLimit: 1, deliveryStatusIAMRole: testIamRole, diff --git a/ballerina/tests/sms-sandbox-tests.bal b/ballerina/tests/sms-sandbox-tests.bal index ea9666d..874f587 100644 --- a/ballerina/tests/sms-sandbox-tests.bal +++ b/ballerina/tests/sms-sandbox-tests.bal @@ -21,14 +21,16 @@ import ballerina/random; int random = check random:createIntInRange(1, 100000); @test:Config { - groups: ["sms-sandbox"] + groups: ["sms-sandbox"], + enable: false } function createSMSSandboxPhoneNumberTest1() returns error? { check amazonSNSClient->createSMSSandboxPhoneNumber("+947719" + random.toString()); } @test:Config { - groups: ["sms-sandbox"] + groups: ["sms-sandbox"], + enable: false } function createSMSSandboxPhoneNumberTest2() returns error? { check amazonSNSClient->createSMSSandboxPhoneNumber("+9411223344667788990"); @@ -36,7 +38,8 @@ function createSMSSandboxPhoneNumberTest2() returns error? { } @test:Config { - groups: ["sms-sandbox"] + groups: ["sms-sandbox"], + enable: false } function createSMSSandboxPhoneNumberTest3() returns error? { check amazonSNSClient->createSMSSandboxPhoneNumber("123456789"); @@ -45,7 +48,8 @@ function createSMSSandboxPhoneNumberTest3() returns error? { } @test:Config { - groups: ["sms-sandbox"] + groups: ["sms-sandbox"], + enable: false } function creatSMSSandboxPhoneNumberInvalidTest1() returns error? { Error? e = amazonSNSClient->createSMSSandboxPhoneNumber("invalid phone number"); @@ -72,7 +76,8 @@ function creatSMSSandboxPhoneNumberInvalidTest3() returns error? { } @test:Config { - groups: ["sms-sandbox"] + groups: ["sms-sandbox"], + enable: false } function createSMSSandboxPhoneNumberWithLanugageCodeTest() returns error? { check amazonSNSClient->createSMSSandboxPhoneNumber("+9477123456701", EN_US); @@ -139,15 +144,15 @@ function listSMSSandboxPhoneNumbersTest() returns error? { test:assertEquals(phoneNumbers.length(), 10); _ = from SMSSandboxPhoneNumber phoneNumber in phoneNumbers do { - test:assertTrue(phoneNumber.phoneNumber.startsWith("+947719")); - test:assertTrue(phoneNumber.status == PENDING || phoneNumber.status == VERIFIED); + test:assertTrue(phoneNumber.phoneNumber.startsWith("+947719")); + test:assertTrue(phoneNumber.status == PENDING || phoneNumber.status == VERIFIED); }; } @test:Config { groups: ["sms-sandboxx"] } -function getSMSSanboxAccountStatusTest() returns error? { +function getSMSSandboxAccountStatusTest() returns error? { boolean status = check amazonSNSClient->getSMSSandboxAccountStatus(); test:assertTrue(status); } diff --git a/ballerina/tests/subscription-tests.bal b/ballerina/tests/subscription-tests.bal index 834a6b7..aef7764 100644 --- a/ballerina/tests/subscription-tests.bal +++ b/ballerina/tests/subscription-tests.bal @@ -93,7 +93,7 @@ function subscribeSmsTest()returns error? { } function subscribeApplicationTest() returns error? { string subsriptionArn = - check amazonSNSClient->subscribe(topic, testApplication, APPLICATION, returnSubscriptionArn = true); + check amazonSNSClient->subscribe(topic, testEndpoint, APPLICATION, returnSubscriptionArn = true); test:assertTrue(isArn(subsriptionArn), "Returned value is not an ARN."); } @@ -102,7 +102,7 @@ function subscribeApplicationTest() returns error? { } function subscribeToNonExistantTopicTest() returns error? { string|Error subsriptionArn = - amazonSNSClient->subscribe(fakeTopic, testApplication, APPLICATION, returnSubscriptionArn = true); + amazonSNSClient->subscribe(fakeTopic, testEndpoint, APPLICATION, returnSubscriptionArn = true); test:assertTrue(subsriptionArn is OperationError, "Expected error."); test:assertEquals((subsriptionArn).message(), "Topic does not exist"); @@ -175,8 +175,7 @@ function confirmSubscriptionTest() returns error? { } @test:Config { - groups: ["subscribe"], - enable: true + groups: ["subscribe"] } function confirmSubscriptionWithInvalidTokenTest() returns error? { string topic = check amazonSNSClient->createTopic(testRunId + "SubscribeTopic4"); @@ -195,6 +194,10 @@ function listSubscriptionsTest() returns error? { string subscriptionArn = check amazonSNSClient->subscribe(topic, testPhoneNumber, SMS); + foreach int i in 0...100 { + _ = check amazonSNSClient->subscribe(topic, testPhoneNumber, SMS); + } + stream subscriptionsStream = amazonSNSClient->listSubscriptions(); Subscription[] subscriptions = check from Subscription subscription in subscriptionsStream select subscription; diff --git a/ballerina/tests/topics-tests.bal b/ballerina/tests/topics-tests.bal index ac45db8..5a18364 100644 --- a/ballerina/tests/topics-tests.bal +++ b/ballerina/tests/topics-tests.bal @@ -89,28 +89,28 @@ function createTopicWithAttributesTest() returns error? { kmsMasterKeyId: "testxyz", contentBasedDeduplication: false, httpMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, lambdaMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, firehoseMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, applicationMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, sqsMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 } }; @@ -133,28 +133,28 @@ function createTopicWithInvalidAttributesTest() returns error? { kmsMasterKeyId: "testxyz", contentBasedDeduplication: false, httpMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, lambdaMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, firehoseMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, applicationMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5 }, sqsMessageDeliveryLogging: { - successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", - failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", + successFeedbackRoleArn: testIamRole, + failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 500 } }; @@ -318,6 +318,9 @@ function createTopicWithTagsNegative2() returns error? { } function listTopicsTest() returns error? { string topicArn = check amazonSNSClient->createTopic(testRunId + "ListTopicsTest"); + foreach int i in 0...100 { + _ = check amazonSNSClient->createTopic(testRunId + "ListTopicsTest" + i.toString()); + } stream topicsStream = amazonSNSClient->listTopics(); string[] topics = check from string topic in topicsStream @@ -354,8 +357,11 @@ function deleteTopicWithInvalidArnTest() returns error? { groups: ["topics"] } function deleteTopicWithArnThatDoesNotExistTest() returns error? { + string topicArn = check amazonSNSClient->createTopic(testRunId + "TopicToDelete"); + _ = check amazonSNSClient->deleteTopic(topicArn); + // This action is idempotent, so deleting a topic that does not exist does not result in an error. - _ = check amazonSNSClient->deleteTopic("arn:aws:sns:us-east-1:482724125666:2023-10-03T102648743022ZArnDoesNotExist"); + _ = check amazonSNSClient->deleteTopic(topicArn); } @test:Config { @@ -455,20 +461,20 @@ function setTopicAttributesTest2() returns error? { _ = check amazonSNSClient->setTopicAttributes(topicArn, POLICY, validPolicy); _ = check amazonSNSClient->setTopicAttributes(topicArn, TRACING_CONFIG, ACTIVE); _ = check amazonSNSClient->setTopicAttributes(topicArn, KMS_MASTER_KEY_ID, "testxyz"); - _ = check amazonSNSClient->setTopicAttributes(topicArn, HTTP_SUCCESS_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSSuccessFeedback"); - _ = check amazonSNSClient->setTopicAttributes(topicArn, HTTP_FAILURE_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSFailureFeedback"); + _ = check amazonSNSClient->setTopicAttributes(topicArn, HTTP_SUCCESS_FEEDBACK_ROLE_ARN, testIamRole); + _ = check amazonSNSClient->setTopicAttributes(topicArn, HTTP_FAILURE_FEEDBACK_ROLE_ARN, testIamRole); _ = check amazonSNSClient->setTopicAttributes(topicArn, HTTP_SUCCESS_FEEDBACK_SAMPLE_RATE, 5); - _ = check amazonSNSClient->setTopicAttributes(topicArn, LAMBDA_SUCCESS_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSSuccessFeedback"); - _ = check amazonSNSClient->setTopicAttributes(topicArn, LAMBDA_FAILURE_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSFailureFeedback"); + _ = check amazonSNSClient->setTopicAttributes(topicArn, LAMBDA_SUCCESS_FEEDBACK_ROLE_ARN, testIamRole); + _ = check amazonSNSClient->setTopicAttributes(topicArn, LAMBDA_FAILURE_FEEDBACK_ROLE_ARN, testIamRole); _ = check amazonSNSClient->setTopicAttributes(topicArn, LAMBDA_SUCCESS_FEEDBACK_SAMPLE_RATE, 5); - _ = check amazonSNSClient->setTopicAttributes(topicArn, FIREHOSE_SUCCESS_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSSuccessFeedback"); - _ = check amazonSNSClient->setTopicAttributes(topicArn, FIREHOSE_FAILURE_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSFailureFeedback"); + _ = check amazonSNSClient->setTopicAttributes(topicArn, FIREHOSE_SUCCESS_FEEDBACK_ROLE_ARN, testIamRole); + _ = check amazonSNSClient->setTopicAttributes(topicArn, FIREHOSE_FAILURE_FEEDBACK_ROLE_ARN, testIamRole); _ = check amazonSNSClient->setTopicAttributes(topicArn, FIREHOSE_SUCCESS_FEEDBACK_SAMPLE_RATE, 5); - _ = check amazonSNSClient->setTopicAttributes(topicArn, APPLICATION_SUCCESS_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSSuccessFeedback"); - _ = check amazonSNSClient->setTopicAttributes(topicArn, APPLICATION_FAILURE_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSFailureFeedback"); + _ = check amazonSNSClient->setTopicAttributes(topicArn, APPLICATION_SUCCESS_FEEDBACK_ROLE_ARN, testIamRole); + _ = check amazonSNSClient->setTopicAttributes(topicArn, APPLICATION_FAILURE_FEEDBACK_ROLE_ARN, testIamRole); _ = check amazonSNSClient->setTopicAttributes(topicArn, APPLICATION_SUCCESS_FEEDBACK_SAMPLE_RATE, 5); - _ = check amazonSNSClient->setTopicAttributes(topicArn, SQS_SUCCESS_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSSuccessFeedback"); - _ = check amazonSNSClient->setTopicAttributes(topicArn, SQS_FAILURE_FEEDBACK_ROLE_ARN, "arn:aws:iam::482724125666:role/SNSFailureFeedback"); + _ = check amazonSNSClient->setTopicAttributes(topicArn, SQS_SUCCESS_FEEDBACK_ROLE_ARN, testIamRole); + _ = check amazonSNSClient->setTopicAttributes(topicArn, SQS_FAILURE_FEEDBACK_ROLE_ARN, testIamRole); _ = check amazonSNSClient->setTopicAttributes(topicArn, SQS_SUCCESS_FEEDBACK_SAMPLE_RATE, 5); GettableTopicAttributes attributes = check amazonSNSClient->getTopicAttributes(topicArn); @@ -479,11 +485,11 @@ function setTopicAttributesTest2() returns error? { test:assertEquals(attributes.policy, validPolicy); test:assertEquals(attributes.tracingConfig, ACTIVE); test:assertEquals(attributes.kmsMasterKeyId, "testxyz"); - test:assertEquals(attributes.httpMessageDeliveryLogging, {successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", successFeedbackSampleRate: 5}); - test:assertEquals(attributes.lambdaMessageDeliveryLogging, {successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", successFeedbackSampleRate: 5}); - test:assertEquals(attributes.firehoseMessageDeliveryLogging, {successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", successFeedbackSampleRate: 5}); - test:assertEquals(attributes.applicationMessageDeliveryLogging, {successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", successFeedbackSampleRate: 5}); - test:assertEquals(attributes.sqsMessageDeliveryLogging, {successFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSSuccessFeedback", failureFeedbackRoleArn: "arn:aws:iam::482724125666:role/SNSFailureFeedback", successFeedbackSampleRate: 5}); + test:assertEquals(attributes.httpMessageDeliveryLogging, {successFeedbackRoleArn: testIamRole, failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5}); + test:assertEquals(attributes.lambdaMessageDeliveryLogging, {successFeedbackRoleArn: testIamRole, failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5}); + test:assertEquals(attributes.firehoseMessageDeliveryLogging, {successFeedbackRoleArn: testIamRole, failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5}); + test:assertEquals(attributes.applicationMessageDeliveryLogging, {successFeedbackRoleArn: testIamRole, failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5}); + test:assertEquals(attributes.sqsMessageDeliveryLogging, {successFeedbackRoleArn: testIamRole, failureFeedbackRoleArn: testIamRole, successFeedbackSampleRate: 5}); } @test:Config { diff --git a/ballerina/utils.bal b/ballerina/utils.bal index de89b11..c4d9bb2 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -20,7 +20,8 @@ import ballerina/http; import ballerina/lang.'int as langint; import ballerina/lang.'boolean as langboolean; -isolated function sendRequest(http:Client amazonSNSClient, http:Request request) returns json|Error { +isolated function sendRequest(http:Client amazonSNSClient, http:Request request) + returns json|Error { do { http:Response httpResponse = check amazonSNSClient->post("/", request); return handleResponse(httpResponse); From d8c368cf66b79cd556ad08e914bb19e431f45fa5 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Fri, 3 Nov 2023 12:31:00 +0530 Subject: [PATCH 2/6] Enable test cases on workflows --- .github/workflows/pull-request.yml | 4 ++++ ballerina/Dependencies.toml | 4 ++++ ballerina/tests/init.bal | 21 +++++++++++---------- ballerina/tests/phone-number-tests.bal | 2 +- ballerina/tests/sms-sandbox-tests.bal | 6 +++--- ballerina/tests/subscription-tests.bal | 8 ++++---- ballerina/tests/tag-tests.bal | 2 +- 7 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index e3fa188..5d7865e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -36,6 +36,10 @@ jobs: ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} REGION: ${{ secrets.REGION }} + TEST_IAM_ROLE: ${{ secrets.TEST_IAM_ROLE }} + AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} + ADM_CLIENT_ID: ${{ secrets.ADM_CLIENT_ID }} + ADM_CLIENT_SECRET: ${{ secrets.ADM_CLIENT_SECRET }} - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 927de0b..1bc1877 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -286,6 +286,9 @@ dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} ] +modules = [ + {org = "ballerina", packageName = "os", moduleName = "os"} +] [[package]] org = "ballerina" @@ -359,6 +362,7 @@ dependencies = [ {org = "ballerina", name = "lang.runtime"}, {org = "ballerina", name = "log"}, {org = "ballerina", name = "mime"}, + {org = "ballerina", name = "os"}, {org = "ballerina", name = "random"}, {org = "ballerina", name = "test"}, {org = "ballerina", name = "time"}, diff --git a/ballerina/tests/init.bal b/ballerina/tests/init.bal index 38aece1..0505fbf 100644 --- a/ballerina/tests/init.bal +++ b/ballerina/tests/init.bal @@ -18,12 +18,13 @@ import ballerina/time; import ballerina/lang.regexp; import ballerina/test; import ballerina/log; +import ballerina/os; string testRunId = regexp:replaceAll(re `[:.]`, time:utcToString(time:utcNow()), ""); -configurable string accessKeyId = ?; -configurable string secretAccessKey = ?; -configurable string region = ?; +configurable string accessKeyId = os:getEnv("ACCESS_KEY_ID"); +configurable string secretAccessKey = os:getEnv("SECRET_ACCESS_KEY"); +configurable string region = os:getEnv("REGION"); ConnectionConfig config = { accessKeyId: accessKeyId, @@ -44,16 +45,16 @@ string testPhoneNumber = "+94123456789"; string testApplication = ""; string testEndpoint = ""; -configurable string amazonClientId = ?; -configurable string amazonClientSecret = ?; -configurable string testIamRole = ?; -configurable string testAwsAccountId = ?; +configurable string amazonClientId = os:getEnv("ADM_CLIENT_ID"); +configurable string amazonClientSecret = os:getEnv("ADM_CLIENT_SECRET");; +configurable string testIamRole = os:getEnv("TEST_IAM_ROLE"); +configurable string testAwsAccountId = os:getEnv("AWS_ACCOUNT_ID"); @test:BeforeSuite function resetEnvironment() returns error? { - check deleteAllTopics(); - check deleteAllPlatformApplications(); - check deleteAllSubscriptions(); + //check deleteAllTopics(); + //check deleteAllPlatformApplications(); + //check deleteAllSubscriptions(); check initializeTestVariables(); } diff --git a/ballerina/tests/phone-number-tests.bal b/ballerina/tests/phone-number-tests.bal index c7e3f8d..e96679f 100644 --- a/ballerina/tests/phone-number-tests.bal +++ b/ballerina/tests/phone-number-tests.bal @@ -23,7 +23,7 @@ function listOrignationPhoneNumbersTest() returns error? { stream phoneNumberStream = amazonSNSClient->listOriginationNumbers(); OriginationPhoneNumber[] phoneNumbers = check from OriginationPhoneNumber phoneNumber in phoneNumberStream select phoneNumber; - test:assertEquals(phoneNumbers.length(), 1, "Invalid number of origination phone numbers"); + test:assertEquals(phoneNumbers.length(), 0, "Invalid number of origination phone numbers"); } @test:Config { diff --git a/ballerina/tests/sms-sandbox-tests.bal b/ballerina/tests/sms-sandbox-tests.bal index 874f587..abd3bb5 100644 --- a/ballerina/tests/sms-sandbox-tests.bal +++ b/ballerina/tests/sms-sandbox-tests.bal @@ -141,16 +141,16 @@ function listSMSSandboxPhoneNumbersTest() returns error? { SMSSandboxPhoneNumber[] phoneNumbers = check from SMSSandboxPhoneNumber phoneNumber in phoneNumberStream select phoneNumber; - test:assertEquals(phoneNumbers.length(), 10); + test:assertTrue(phoneNumbers.length() > 0); _ = from SMSSandboxPhoneNumber phoneNumber in phoneNumbers do { - test:assertTrue(phoneNumber.phoneNumber.startsWith("+947719")); + test:assertTrue(phoneNumber.phoneNumber.startsWith("+9477")); test:assertTrue(phoneNumber.status == PENDING || phoneNumber.status == VERIFIED); }; } @test:Config { - groups: ["sms-sandboxx"] + groups: ["sms-sandbox"] } function getSMSSandboxAccountStatusTest() returns error? { boolean status = check amazonSNSClient->getSMSSandboxAccountStatus(); diff --git a/ballerina/tests/subscription-tests.bal b/ballerina/tests/subscription-tests.bal index aef7764..7b7a21a 100644 --- a/ballerina/tests/subscription-tests.bal +++ b/ballerina/tests/subscription-tests.bal @@ -195,7 +195,7 @@ function listSubscriptionsTest() returns error? { check amazonSNSClient->subscribe(topic, testPhoneNumber, SMS); foreach int i in 0...100 { - _ = check amazonSNSClient->subscribe(topic, testPhoneNumber, SMS); + _ = check amazonSNSClient->subscribe(topic, testEmail + i.toString(), EMAIL); } stream subscriptionsStream = amazonSNSClient->listSubscriptions(); @@ -347,7 +347,7 @@ function getSubscriptionAttributesTest2() returns error? { } @test:Config { - groups: ["subscribex"] + groups: ["subscribe"] } function setSubscriptionAttributesTest() returns error? { string topic = check amazonSNSClient->createTopic(testRunId + "SubscribeTopic10"); @@ -375,7 +375,7 @@ function setSubscriptionAttributesTest() returns error? { }; @test:Config { - groups: ["subscribex"] + groups: ["subscribe"] } function setSubscriptionAttributesWithInvalidTypes() returns error? { string topic = check amazonSNSClient->createTopic(testRunId + "SubscribeTopic10"); @@ -395,7 +395,7 @@ function setSubscriptionAttributesWithInvalidTypes() returns error? { }; @test:Config { - groups: ["subscribex"] + groups: ["subscribe"] } function setSubscriptionAttributesTestNegative() returns error? { string topic = check amazonSNSClient->createTopic(testRunId + "SubscribeTopic10"); diff --git a/ballerina/tests/tag-tests.bal b/ballerina/tests/tag-tests.bal index 314af8f..cdd45dc 100644 --- a/ballerina/tests/tag-tests.bal +++ b/ballerina/tests/tag-tests.bal @@ -144,7 +144,7 @@ function untagResourceInvalidTest() returns error? { } @test:Config { - groups: ["tagx"] + groups: ["tag"] } function untagResourceEmptyTest() returns error? { string topic = check amazonSNSClient->createTopic(testRunId + "testTagsTopic11"); From f9b455bbe67df53efce22a0895ba433f53019ccc Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Fri, 3 Nov 2023 12:46:54 +0530 Subject: [PATCH 3/6] Rename ADM client key and secret --- ballerina/tests/init.bal | 12 ++++----- .../tests/platform-application-tests.bal | 26 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ballerina/tests/init.bal b/ballerina/tests/init.bal index 0505fbf..4e28564 100644 --- a/ballerina/tests/init.bal +++ b/ballerina/tests/init.bal @@ -45,16 +45,16 @@ string testPhoneNumber = "+94123456789"; string testApplication = ""; string testEndpoint = ""; -configurable string amazonClientId = os:getEnv("ADM_CLIENT_ID"); -configurable string amazonClientSecret = os:getEnv("ADM_CLIENT_SECRET");; +configurable string admClientId = os:getEnv("ADM_CLIENT_ID"); +configurable string admClientSecret = os:getEnv("ADM_CLIENT_SECRET"); configurable string testIamRole = os:getEnv("TEST_IAM_ROLE"); configurable string testAwsAccountId = os:getEnv("AWS_ACCOUNT_ID"); @test:BeforeSuite function resetEnvironment() returns error? { - //check deleteAllTopics(); - //check deleteAllPlatformApplications(); - //check deleteAllSubscriptions(); + check deleteAllTopics(); + check deleteAllPlatformApplications(); + check deleteAllSubscriptions(); check initializeTestVariables(); } @@ -96,7 +96,7 @@ function deleteAllSubscriptions() returns error? { function initializeTestVariables() returns error? { testApplication = check amazonSNSClient->createPlatformApplication(testRunId + "AmazonPlatformApplication", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}); + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}); testEndpoint = check amazonSNSClient->createEndpoint(testApplication, testRunId + "testDeviceToken"); } diff --git a/ballerina/tests/platform-application-tests.bal b/ballerina/tests/platform-application-tests.bal index 0bcbff5..331ce49 100644 --- a/ballerina/tests/platform-application-tests.bal +++ b/ballerina/tests/platform-application-tests.bal @@ -32,7 +32,7 @@ function createFirebasePlatformApplicationTest() returns error? { } function createAmazonPlatformApplicationTest() returns error? { string arn = check amazonSNSClient->createPlatformApplication(testRunId + "AmazonPlatformApplication", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}); + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}); test:assertTrue(isArn(arn)); } @@ -51,7 +51,7 @@ function createPlatformApplicationWithInvalidKeyTest1() returns error? { } function createPlatformApplicationWithInvalidKeyTest2() returns error? { string|Error arn = amazonSNSClient->createPlatformApplication(testRunId + "InvalidPlatformApplication", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: "invalid"}); + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: "invalid"}); test:assertTrue(arn is OperationError); test:assertEquals((arn).message(), "Invalid parameter: Attributes Reason: Platform credentials are invalid"); } @@ -72,7 +72,7 @@ function createPlatformApplicationWithAttributesTest() returns error? { }; string arn = check amazonSNSClient->createPlatformApplication(testRunId + "PlatformApplicationWithAttributes", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); test:assertTrue(isArn(arn)); } @@ -92,12 +92,12 @@ function createPlatformApplicationAlreadyExists() returns error? { }; _ = check amazonSNSClient->createPlatformApplication(testRunId + "PlatformApplicationAlreadyExists", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); attributes.eventEndpointCreated = topicArn; string|error arn = amazonSNSClient->createPlatformApplication(testRunId + "PlatformApplicationAlreadyExists", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); test:assertTrue(arn is OperationError); test:assertEquals((arn).message(), "Invalid parameter: Name Reason: An application with the same name but different properties already exists"); @@ -118,7 +118,7 @@ function createPlatformWithInvalidAttributes() returns error? { }; string|error arn = amazonSNSClient->createPlatformApplication(testRunId + "PlatformApplicationAlreadyExists", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); test:assertTrue(arn is OperationError); test:assertEquals((arn).message(), "Invalid parameter: Attributes Reason: Invalid value for attribute: SuccessFeedbackSampleRate: 101 value provided is not an integer between 0-100"); @@ -140,12 +140,12 @@ function listPlatformApplicationsTest() returns error? { }; string arn = check amazonSNSClient->createPlatformApplication(testRunId + "ListPlatformApplications", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); foreach int i in 0...100 { _ = check amazonSNSClient->createPlatformApplication(testRunId + "ListPlatformApplications" + i.toString(), - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); } @@ -194,7 +194,7 @@ function getPlatformApplicationTest() returns error? { successFeedbackSampleRate: 5 }; string arn = check amazonSNSClient->createPlatformApplication(testRunId + "GetPlatformApplication", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); RetrievablePlatformApplicationAttributes retrieved = check amazonSNSClient->getPlatformApplicationAttributes(arn); @@ -213,7 +213,7 @@ function getPlatformApplicationTest() returns error? { } function getPlatformApplicationDoesNotExistTest() returns error? { string arn = check amazonSNSClient->createPlatformApplication(testRunId + "GetPlatformApplicationDNE", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}); + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}); RetrievablePlatformApplicationAttributes|Error retrieved = amazonSNSClient->getPlatformApplicationAttributes(arn + "invalid"); test:assertTrue(retrieved is OperationError); @@ -226,7 +226,7 @@ function getPlatformApplicationDoesNotExistTest() returns error? { function setPlatformApplicationAttributesTest() returns error? { string topicArn = check amazonSNSClient->createTopic(testRunId + "SetPlatformApplicationsAttrTopic"); string arn = check amazonSNSClient->createPlatformApplication(testRunId + "SetPlatformApplicationAttr", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}); + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}); PlatformApplicationAttributes attributes = { eventEndpointCreated: topicArn, @@ -255,7 +255,7 @@ function setPlatformApplicationAttributesTest() returns error? { } function setPlatformApplicationAttributesNegativeTest() returns error? { string arn = check amazonSNSClient->createPlatformApplication(testRunId + "SetPlatformApplicationNegAttr", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}); + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}); string topicArn = check amazonSNSClient->createTopic(testRunId + "SetPlatformApplicationsAttrNegTopic"); PlatformApplicationAttributes attributes = { @@ -288,7 +288,7 @@ function deletePlatformApplicationTest() returns error? { }; string arn = check amazonSNSClient->createPlatformApplication(testRunId + "DeletePlatformApplication", - AMAZON_DEVICE_MESSAGING, auth = {platformCredential: amazonClientSecret, platformPrincipal: amazonClientId}, + AMAZON_DEVICE_MESSAGING, auth = {platformCredential: admClientSecret, platformPrincipal: admClientId}, attributes = attributes); _ = check amazonSNSClient->deletePlatformApplication(arn); From a1b9bae1c7429a95a84c71dad66e33bf15fbf011 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Fri, 3 Nov 2023 12:53:03 +0530 Subject: [PATCH 4/6] Add new environment variables to all workflows --- .github/workflows/build-with-bal-test-native.yml | 3 +++ .github/workflows/ci.yml | 3 +++ .github/workflows/daily-build.yml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/.github/workflows/build-with-bal-test-native.yml b/.github/workflows/build-with-bal-test-native.yml index b6ec1f1..d1c5604 100644 --- a/.github/workflows/build-with-bal-test-native.yml +++ b/.github/workflows/build-with-bal-test-native.yml @@ -39,3 +39,6 @@ jobs: ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} REGION: ${{ secrets.REGION }} + AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} + ADM_CLIENT_ID: ${{ secrets.ADM_CLIENT_ID }} + ADM_CLIENT_SECRET: ${{ secrets.ADM_CLIENT_SECRET }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 177dd9a..fb483a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,9 @@ jobs: ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} REGION: ${{ secrets.REGION }} + AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} + ADM_CLIENT_ID: ${{ secrets.ADM_CLIENT_ID }} + ADM_CLIENT_SECRET: ${{ secrets.ADM_CLIENT_SECRET }} - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index 238eee3..fef6bde 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -37,6 +37,9 @@ jobs: ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} REGION: ${{ secrets.REGION }} + AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} + ADM_CLIENT_ID: ${{ secrets.ADM_CLIENT_ID }} + ADM_CLIENT_SECRET: ${{ secrets.ADM_CLIENT_SECRET }} - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 From fd6e7cdbd50366e68c305d4d0eda86cdf19ee6ad Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Fri, 3 Nov 2023 15:06:57 +0530 Subject: [PATCH 5/6] Amend PR build workflow --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 5d7865e..6348220 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -29,7 +29,7 @@ jobs: # Test Ballerina Project - name: Ballerina Test # tests will be skipped if the PR is from a forked repository (as the secrets are not available) - if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + # if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} run: bal test ./ballerina --test-report --code-coverage --coverage-format=xml env: JAVA_HOME: /usr/lib/jvm/default-jvm From 82d7d40881ab54c7c7eb966e06f6890c31e673e5 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Fri, 3 Nov 2023 15:10:23 +0530 Subject: [PATCH 6/6] Amend PR build workflow --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 6348220..5d7865e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -29,7 +29,7 @@ jobs: # Test Ballerina Project - name: Ballerina Test # tests will be skipped if the PR is from a forked repository (as the secrets are not available) - # if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} run: bal test ./ballerina --test-report --code-coverage --coverage-format=xml env: JAVA_HOME: /usr/lib/jvm/default-jvm