From 546bb3ca14e0148713bde12f4bf65569bcbdd2ee Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Wed, 4 Oct 2023 12:30:39 -0400 Subject: [PATCH] Shift environment.go to horizon package --- .../internal/test/integration/environment.go | 45 ------------------- .../internal/test/integration/integration.go | 6 +-- 2 files changed, 3 insertions(+), 48 deletions(-) delete mode 100644 services/horizon/internal/test/integration/environment.go diff --git a/services/horizon/internal/test/integration/environment.go b/services/horizon/internal/test/integration/environment.go deleted file mode 100644 index 9a3d7c09d2..0000000000 --- a/services/horizon/internal/test/integration/environment.go +++ /dev/null @@ -1,45 +0,0 @@ -//lint:file-ignore U1001 Ignore all unused code, this is only used in tests. -package integration - -import ( - "os" -) - -type EnvironmentManager struct { - oldEnvironment, newEnvironment map[string]string -} - -func NewEnvironmentManager() *EnvironmentManager { - env := &EnvironmentManager{} - env.oldEnvironment = make(map[string]string) - env.newEnvironment = make(map[string]string) - return env -} - -// Add sets a new environment variable, saving the original value (if any). -func (envmgr *EnvironmentManager) Add(key, value string) error { - // If someone pushes an environmental variable more than once, we don't want - // to lose the *original* value, so we're being careful here. - if _, ok := envmgr.newEnvironment[key]; !ok { - if oldValue, ok := os.LookupEnv(key); ok { - envmgr.oldEnvironment[key] = oldValue - } - } - - envmgr.newEnvironment[key] = value - return os.Setenv(key, value) -} - -// Restore restores the environment prior to any modifications. -// -// You should probably use this alongside `defer` to ensure the global -// environment isn't modified for longer than you intend. -func (envmgr *EnvironmentManager) Restore() { - for key := range envmgr.newEnvironment { - if oldValue, ok := envmgr.oldEnvironment[key]; ok { - os.Setenv(key, oldValue) - } else { - os.Unsetenv(key) - } - } -} diff --git a/services/horizon/internal/test/integration/integration.go b/services/horizon/internal/test/integration/integration.go index e83b061b3e..df5e15aae3 100644 --- a/services/horizon/internal/test/integration/integration.go +++ b/services/horizon/internal/test/integration/integration.go @@ -96,7 +96,7 @@ type Test struct { config Config coreConfig CaptiveConfig horizonIngestConfig horizon.Config - environment *EnvironmentManager + environment *horizon.EnvironmentManager horizonClient *sdk.Client horizonAdminClient *sdk.AdminClient @@ -151,7 +151,7 @@ func NewTest(t *testing.T, config Config) *Test { config: config, composePath: composePath, passPhrase: StandaloneNetworkPassphrase, - environment: NewEnvironmentManager(), + environment: horizon.NewEnvironmentManager(), } i.configureCaptiveCore() // Only run Stellar Core container and its dependencies. @@ -160,7 +160,7 @@ func NewTest(t *testing.T, config Config) *Test { i = &Test{ t: t, config: config, - environment: NewEnvironmentManager(), + environment: horizon.NewEnvironmentManager(), } }