Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
firemaples committed Jan 3, 2024
1 parent 94dd919 commit 88357f1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ms_svc_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches: [ "*" ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
env:
MS_KEY_1: ${{ secrets.MS_KEY_1 }}
run: ./gradlew :main:testDevDebug --tests "tw.firemaples.onscreenocr.MicrosoftAzureAPIServiceTest"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package tw.firemaples.onscreenocr

import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import tw.firemaples.onscreenocr.translator.azure.MicrosoftAzureAPIService
import tw.firemaples.onscreenocr.translator.azure.TranslateRequest

class MicrosoftAzureAPIServiceTest {
private val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl("http://localhost/")
.addConverterFactory(MoshiConverterFactory.create())
.build()
}

private val apiService: MicrosoftAzureAPIService by lazy {
retrofit.create(MicrosoftAzureAPIService::class.java)
}

@Test
fun test() = runTest {
val key = System.getenv().getOrDefault("MS_KEY_1", "")

val result = apiService.translate(
subscriptionKey = key,
to = "fr",
request = TranslateRequest.single("Hello"),
)

val actual = result.body()?.firstOrNull()?.translations?.firstOrNull()?.text
assertEquals("Bonjour", actual)
}
}

0 comments on commit 88357f1

Please sign in to comment.