Skip to content

Commit

Permalink
Use assumeThat to GCP/Azure ITs that need secrets
Browse files Browse the repository at this point in the history
This change lets the tests that require secrets not pass but mark those as "skipped".

Also a nit-ish change (suppress-warning).
  • Loading branch information
snazy committed Aug 26, 2024
1 parent 7b4aa0b commit ae82eec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,25 @@
import org.apache.polaris.core.storage.azure.AzureCredentialsStorageIntegration;
import org.apache.polaris.core.storage.azure.AzureStorageConfigurationInfo;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.Assumptions;
import org.assertj.core.util.Strings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AzureCredentialStorageIntegrationTest {

private static final Logger LOGGER =
LoggerFactory.getLogger(AzureCredentialStorageIntegrationTest.class);

private final String clientId = System.getenv("AZURE_CLIENT_ID");
private final String clientSecret = System.getenv("AZURE_CLIENT_SECRET");
private final String tenantId = "d479c7c9-2632-445a-b22d-7c19e68774f6";

private boolean checkEnvNullVariables() {
if (Strings.isNullOrEmpty(clientId) || Strings.isNullOrEmpty(clientSecret)) {
LOGGER.debug("Null Azure testing environment variables! Skip {}", this.getClass().getName());
return true;
}
return false;
private void checkEnvNullVariables() {
Assumptions.assumeThat(Strings.isNullOrEmpty(clientId) || Strings.isNullOrEmpty(clientSecret))
.describedAs("Null Azure testing environment variables!")
.isFalse();
}

@Test
Expand Down Expand Up @@ -115,9 +109,8 @@ public void testNegativeCases() {
@TestWithAzureArgs
public void testGetSubscopedTokenList(boolean allowListAction, String service) {

if (checkEnvNullVariables()) {
return;
}
checkEnvNullVariables();

boolean isBlobService = service.equals("blob");
List<String> allowedLoc =
Arrays.asList(
Expand Down Expand Up @@ -184,10 +177,10 @@ public void testGetSubscopedTokenList(boolean allowListAction, String service) {
}

@TestWithAzureArgs
public void testGetSubscopedTokenRead(boolean allowListAction, String service) {
if (checkEnvNullVariables()) {
return;
}
public void testGetSubscopedTokenRead(
@SuppressWarnings("unused") boolean allowListAction, String service) {
checkEnvNullVariables();

String allowedPrefix = "polaris-test";
String blockedPrefix = "blocked-prefix";
List<String> allowedLoc =
Expand Down Expand Up @@ -253,10 +246,10 @@ public void testGetSubscopedTokenRead(boolean allowListAction, String service) {
}

@TestWithAzureArgs
public void testGetSubscopedTokenWrite(boolean allowListAction, String service) {
if (checkEnvNullVariables()) {
return;
}
public void testGetSubscopedTokenWrite(
@SuppressWarnings("unused") boolean allowListAction, String service) {
checkEnvNullVariables();

boolean isBlobService = service.equals("blob");
String allowedPrefix = "polaris-test/scopedcreds/";
String blockedPrefix = "blocked-prefix";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,25 @@
import org.apache.polaris.core.storage.gcp.GcpCredentialsStorageIntegration;
import org.apache.polaris.core.storage.gcp.GcpStorageConfigurationInfo;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.Assumptions;
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
import org.assertj.core.util.Strings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class GcpCredentialsStorageIntegrationTest {

private final String gcsServiceKeyJsonFileLocation =
System.getenv("GOOGLE_APPLICATION_CREDENTIALS");

private static final Logger LOGGER =
LoggerFactory.getLogger(GcpCredentialsStorageIntegrationTest.class);

@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testSubscope(boolean allowedListAction) throws IOException {
if (Strings.isNullOrEmpty(gcsServiceKeyJsonFileLocation)) {
LOGGER.debug(
"Environment variable GOOGLE_APPLICATION_CREDENTIALS not exits, skip test {}",
getClass().getName());
return;
}
public void testSubscope(boolean allowedListAction) throws Exception {
Assumptions.assumeThat(gcsServiceKeyJsonFileLocation)
.describedAs("Environment variable GOOGLE_APPLICATION_CREDENTIALS not exits")
.isNotNull()
.isNotEmpty();

List<String> allowedRead =
Arrays.asList(
"gs://sfc-dev1-regtest/polaris-test/subscoped-test/read1/",
Expand Down

0 comments on commit ae82eec

Please sign in to comment.