Add more tests and run them before each merge (#10)

These tests are very basic sanity checks
This commit is contained in:
Theo Kanning 2022-04-28 14:49:54 -05:00 committed by GitHub
parent d3074e113e
commit ed2f1152e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 117 additions and 3 deletions

View File

@ -6,8 +6,7 @@ on:
- '[0-9]+.[0-9]+.[0-9]+'
jobs:
build:
publish:
runs-on: ubuntu-latest
steps:
@ -20,6 +19,8 @@ jobs:
- name: Test
run: ./gradlew test
env:
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
- name: Publish
run: ./gradlew build publish
@ -27,4 +28,4 @@ jobs:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoeryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }}

24
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: Publish
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Test
run: ./gradlew test --stacktrace
env:
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}

View File

@ -15,3 +15,7 @@ compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
test {
useJUnitPlatform()
}

View File

@ -0,0 +1,27 @@
package com.theokanning.openai;
import com.theokanning.openai.completion.CompletionChoice;
import com.theokanning.openai.completion.CompletionRequest;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class CompletionTest {
String token = System.getenv("OPENAI_TOKEN");
OpenAiService service = new OpenAiService(token);
@Test
void createCompletion() {
CompletionRequest completionRequest = CompletionRequest.builder()
.prompt("Somebody once told me the world is gonna roll me")
.echo(true)
.build();
List<CompletionChoice> choices = service.createCompletion("ada", completionRequest).getChoices();
assertFalse(choices.isEmpty());
}
}

View File

@ -0,0 +1,30 @@
package com.theokanning.openai;
import com.theokanning.openai.engine.Engine;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class EngineTest {
String token = System.getenv("OPENAI_TOKEN");
OpenAiService service = new OpenAiService(token);
@Test
void getEngines() {
List<Engine> engines = service.getEngines();
assertFalse(engines.isEmpty());
}
@Test
void getEngine() {
Engine ada = service.getEngine("ada");
assertEquals("ada", ada.id);
}
}

View File

@ -0,0 +1,28 @@
package com.theokanning.openai;
import com.theokanning.openai.search.SearchRequest;
import com.theokanning.openai.search.SearchResult;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class SearchTest {
String token = System.getenv("OPENAI_TOKEN");
OpenAiService service = new OpenAiService(token);
@Test
void search() {
SearchRequest searchRequest = SearchRequest.builder()
.documents(Arrays.asList("Water", "Earth", "Electricity", "Fire"))
.query("Pikachu")
.build();
List<SearchResult> results = service.search("ada", searchRequest);
assertFalse(results.isEmpty());
}
}