Skip to content

Commit

Permalink
Extract ClearGithubEnvVariablesExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslaw-panuszewski committed Jul 15, 2024
1 parent 95008c1 commit 599a6dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pl.allegro.tech.build.axion.release.util

import org.spockframework.runtime.extension.IGlobalExtension

import static java.util.stream.Collectors.toList

class ClearGithubEnvVariablesExtension implements IGlobalExtension {

@Override
void start() {
def keysToRemove = TestEnvironment.getEnvVariableNames().stream()
.filter { variableName -> variableName.startsWith("GITHUB_") }
.collect(toList())
keysToRemove.forEach(TestEnvironment::unsetEnvVariable)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package pl.allegro.tech.build.axion.release.util

import org.spockframework.runtime.extension.IGlobalExtension

import static java.util.stream.Collectors.toList

class TestEnvironment implements IGlobalExtension {
class TestEnvironment {

private static Map<String, String> MUTABLE_ENV_MAP

@Override
void start() {
static {
extractMutableMapFromSystemEnv()
clearGithubActionsVariables()
}

private static void extractMutableMapFromSystemEnv() {
Expand All @@ -22,18 +16,15 @@ class TestEnvironment implements IGlobalExtension {
MUTABLE_ENV_MAP = (Map<String, String>) internalMapField.get(envMap)
}

private static void clearGithubActionsVariables() {
def keysToRemove = MUTABLE_ENV_MAP.keySet().stream()
.filter { variableName -> variableName.startsWith("GITHUB_") }
.collect(toList())
keysToRemove.forEach(MUTABLE_ENV_MAP::remove)
}

static void setEnvVariable(String name, String value) {
MUTABLE_ENV_MAP.put(name, value)
}

static void unsetEnvVariable(String name) {
MUTABLE_ENV_MAP.remove(name)
}

static Set<String> getEnvVariableNames() {
return MUTABLE_ENV_MAP.keySet()
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pl.allegro.tech.build.axion.release.util.TestEnvironment
pl.allegro.tech.build.axion.release.util.ClearGithubEnvVariablesExtension

0 comments on commit 599a6dc

Please sign in to comment.