Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALMS-211 GitHub action added for unit test #18

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/test-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run Unit Tests for Android
on:
workflow_dispatch:
pull_request:
branches: [ main ]
jobs:
test-android:
name: Test Android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'

- name: Run Unit Tests
run: |
./gradlew testDebugUnitTest

- name: Upload test results
uses: actions/upload-artifact@v2
if: always()
with:
name: test-results
path: library/build/reports/tests/testDebugUnitTest/
retention-days: 1
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ class LocationCredentialsProviderTest {
}
}

@Test
fun `initializeLocationClient`() {
val expirationTime =
Instant.fromEpochMilliseconds(Instant.now().epochMilliseconds + 10000) // 10 seconds in the future
val mockCredentials =
Credentials.invoke {
expiration = expirationTime
secretKey = "test"
accessKeyId = "test"
sessionToken = "test"
}
every { anyConstructed<CognitoCredentialsProvider>().getCachedCredentials() } returns mockCredentials
every { anyConstructed<EncryptedSharedPreferences>().get(METHOD) } returns ""
every { anyConstructed<EncryptedSharedPreferences>().get(IDENTITY_POOL_ID) } returns TEST_IDENTITY_POOL_ID
every { anyConstructed<EncryptedSharedPreferences>().get(ACCESS_KEY_ID) } returns "test"
every { anyConstructed<EncryptedSharedPreferences>().get(SECRET_KEY) } returns "test"
every { anyConstructed<EncryptedSharedPreferences>().get(SESSION_TOKEN) } returns "test"
every { anyConstructed<EncryptedSharedPreferences>().get(EXPIRATION) } returns "11111"
val provider =
LocationCredentialsProvider(context, TEST_IDENTITY_POOL_ID, AwsRegions.US_EAST_1)
runBlocking {
provider.initializeLocationClient(credentialsProvider)
assertNotNull(provider.getLocationClient())
}
}

@Test
fun `isCredentialsValid returns true when credentials are valid`() {
val expirationTime =
Expand Down
Loading