diff --git a/.github/workflows/test-android.yml b/.github/workflows/test-android.yml new file mode 100644 index 0000000..bbc842c --- /dev/null +++ b/.github/workflows/test-android.yml @@ -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 \ No newline at end of file diff --git a/library/src/test/java/software/amazon/location/auth/LocationCredentialsProviderTest.kt b/library/src/test/java/software/amazon/location/auth/LocationCredentialsProviderTest.kt index 40a06b6..4527bee 100644 --- a/library/src/test/java/software/amazon/location/auth/LocationCredentialsProviderTest.kt +++ b/library/src/test/java/software/amazon/location/auth/LocationCredentialsProviderTest.kt @@ -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().getCachedCredentials() } returns mockCredentials + every { anyConstructed().get(METHOD) } returns "" + every { anyConstructed().get(IDENTITY_POOL_ID) } returns TEST_IDENTITY_POOL_ID + every { anyConstructed().get(ACCESS_KEY_ID) } returns "test" + every { anyConstructed().get(SECRET_KEY) } returns "test" + every { anyConstructed().get(SESSION_TOKEN) } returns "test" + every { anyConstructed().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 =