-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from gcw-it/pr_ghrepo
Allow injecting fully set up GHRepository into action method
- Loading branch information
Showing
7 changed files
with
208 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
integration-tests/src/main/java/io/quarkiverse/githubaction/it/RepositoryAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkiverse.githubaction.it; | ||
|
||
import org.kohsuke.github.GHRepository; | ||
|
||
import io.quarkiverse.githubaction.Action; | ||
|
||
public class RepositoryAction { | ||
public static final String ACTION_NAME = "RepositoryAction"; | ||
|
||
@Action(ACTION_NAME) | ||
void test(GHRepository repository) { | ||
System.out.println(repository.getFullName()); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
integration-tests/src/test/java/io/quarkiverse/githubaction/it/RepositoryActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.quarkiverse.githubaction.it; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import jakarta.enterprise.inject.Alternative; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledIf; | ||
import org.junit.jupiter.api.condition.EnabledIf; | ||
|
||
import io.quarkiverse.githubaction.Context; | ||
import io.quarkiverse.githubaction.ContextInitializer; | ||
import io.quarkiverse.githubaction.Inputs; | ||
import io.quarkiverse.githubaction.InputsInitializer; | ||
import io.quarkiverse.githubaction.it.RepositoryActionTest.RepositoryActionTestProfile; | ||
import io.quarkiverse.githubaction.testing.DefaultTestContext; | ||
import io.quarkiverse.githubaction.testing.DefaultTestInputs; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.quarkus.test.junit.main.Launch; | ||
import io.quarkus.test.junit.main.LaunchResult; | ||
import io.quarkus.test.junit.main.QuarkusMainTest; | ||
|
||
@QuarkusMainTest | ||
@TestProfile(RepositoryActionTestProfile.class) | ||
public class RepositoryActionTest { | ||
private static final boolean LOCAL = System.getenv("CURRENT_REPO") == null; | ||
private static final String REPOSITORY_NAME = LOCAL ? "my/local-repo" : System.getenv("CURRENT_REPO"); | ||
private static final String GITHUB_TOKEN = System.getenv("CURRENT_TOKEN"); | ||
|
||
@Test | ||
@Launch(value = {}) | ||
@DisabledIf("isLocal") | ||
public void shouldPrintRepositoryNameWhenRunningOnGitHub(LaunchResult result) { | ||
assertThat(result.getOutput()).contains(REPOSITORY_NAME); | ||
} | ||
|
||
@Test | ||
@Launch(value = {}, exitCode = 1) | ||
@EnabledIf("isLocal") | ||
public void shouldFailWhenRunningLocally(LaunchResult result) { | ||
String fullOutput = result.getOutput() + "\n" + result.getErrorOutput(); | ||
|
||
assertThat(fullOutput).contains(REPOSITORY_NAME); | ||
} | ||
|
||
public static class RepositoryActionTestProfile implements QuarkusTestProfile { | ||
@Override | ||
public Set<Class<?>> getEnabledAlternatives() { | ||
var alternatives = new HashSet<Class<?>>(); | ||
alternatives.add(MockInputsInitializer.class); | ||
if (LOCAL) { | ||
alternatives.add(MockContextInitializer.class); | ||
} | ||
return alternatives; | ||
} | ||
} | ||
|
||
@Alternative | ||
@Singleton | ||
public static class MockInputsInitializer implements InputsInitializer { | ||
@Override | ||
public Inputs createInputs() { | ||
var inputs = new HashMap<String, String>(); | ||
inputs.put(Inputs.ACTION, RepositoryAction.ACTION_NAME); | ||
if (!LOCAL) { | ||
inputs.put(Inputs.GITHUB_TOKEN, GITHUB_TOKEN); | ||
} | ||
return new DefaultTestInputs(inputs); | ||
} | ||
} | ||
|
||
@Alternative | ||
@Singleton | ||
public static class MockContextInitializer implements ContextInitializer { | ||
@Override | ||
public Context createContext() { | ||
return new DefaultTestContext() { | ||
@Override | ||
public String getGitHubRepository() { | ||
return REPOSITORY_NAME; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
private static boolean isLocal() { | ||
return LOCAL; | ||
} | ||
} |
Oops, something went wrong.