Skip to content

Commit

Permalink
Extract requireEnv in a util class
Browse files Browse the repository at this point in the history
  • Loading branch information
krvikash committed Dec 17, 2024
1 parent 4ec70b5 commit 0bbb59d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermissions;

import static io.trino.testing.ProductTestEnvUtils.requireEnv;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.tests.product.launcher.docker.ContainerUtil.forSelectedPorts;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR;
Expand Down Expand Up @@ -203,9 +204,4 @@ private Path getTemptoConfiguration(String schema)
throw new UncheckedIOException(e);
}
}

private static String requireEnv(String variable)
{
return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Base64;
import java.util.UUID;

import static io.trino.testing.ProductTestEnvUtils.requireEnv;
import static io.trino.tests.product.launcher.docker.ContainerUtil.forSelectedPorts;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.HADOOP;
Expand Down Expand Up @@ -188,9 +189,4 @@ private Path getHiveSiteOverrideXml(String gcpStorageBucket)
throw new UncheckedIOException(e);
}
}

private static String requireEnv(String variable)
{
return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.trino.tests.product.launcher.env.common.Standard;
import io.trino.tests.product.launcher.env.common.TestsEnvironment;

import static io.trino.testing.ProductTestEnvUtils.requireEnv;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.isTrinoContainer;
import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_TRINO_JVM_CONFIG;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -57,9 +58,4 @@ public void extendEnvironment(Environment.Builder builder)

builder.addConnector("snowflake", forHostPath(configDir.getPath("snowflake.properties")));
}

private static String requireEnv(String variable)
{
return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.testing;

import static java.util.Objects.requireNonNull;

public final class ProductTestEnvUtils
{
private ProductTestEnvUtils() {}

/**
* Get the named environment variable, throwing an exception if it is not set.
*/
public static String requireEnv(String variable)
{
return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable);
}
}

0 comments on commit 0bbb59d

Please sign in to comment.