diff --git a/src/plugin/config_test.go b/src/plugin/config_test.go index 7ea1f27..6ef80ef 100644 --- a/src/plugin/config_test.go +++ b/src/plugin/config_test.go @@ -10,12 +10,11 @@ import ( ) func TestFailOnMissingEnvironment(t *testing.T) { + unsetEnvironmentVariables() + var config plugin.Config fetcher := plugin.EnvironmentConfigFetcher{} - t.Setenv("BUILDKITE_PLUGIN_EXAMPLE_GO_MESSAGE", "") - os.Unsetenv("BUILDKITE_PLUGIN_EXAMPLE_GO_MESSAGE") - err := fetcher.Fetch(&config) expectedErr := "required key BUILDKITE_PLUGIN_EXAMPLE_GO_MESSAGE missing value" @@ -23,6 +22,9 @@ func TestFailOnMissingEnvironment(t *testing.T) { } func TestFetchConfigFromEnvironment(t *testing.T) { + unsetEnvironmentVariables() + defer unsetEnvironmentVariables() + var config plugin.Config fetcher := plugin.EnvironmentConfigFetcher{} @@ -33,3 +35,9 @@ func TestFetchConfigFromEnvironment(t *testing.T) { require.NoError(t, err, "fetch should not error") assert.Equal(t, "test-message", config.Message, "fetched message should match environment") } + +// Unsets environment variables through an all-in-one function. Extend this with additional environment variables as +// needed. +func unsetEnvironmentVariables() { + os.Unsetenv("BUILDKITE_PLUGIN_EXAMPLE_GO_MESSAGE") +}