diff options
| -rw-r--r-- | android/fixture.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/android/fixture.go b/android/fixture.go index 2085e43ed..607b5bd39 100644 --- a/android/fixture.go +++ b/android/fixture.go @@ -15,6 +15,7 @@ package android import ( + "fmt" "reflect" "strings" "testing" @@ -286,6 +287,32 @@ func FixtureWithRootAndroidBp(contents string) FixturePreparer { return FixtureAddTextFile("Android.bp", contents) } +// Merge some environment variables into the fixture. +func FixtureMergeEnv(env map[string]string) FixturePreparer { + return FixtureModifyConfig(func(config Config) { + for k, v := range env { + if k == "PATH" { + panic("Cannot set PATH environment variable") + } + config.env[k] = v + } + }) +} + +// Modify the env. +// +// Will panic if the mutator changes the PATH environment variable. +func FixtureModifyEnv(mutator func(env map[string]string)) FixturePreparer { + return FixtureModifyConfig(func(config Config) { + oldPath := config.env["PATH"] + mutator(config.env) + newPath := config.env["PATH"] + if newPath != oldPath { + panic(fmt.Errorf("Cannot change PATH environment variable from %q to %q", oldPath, newPath)) + } + }) +} + // GroupFixturePreparers creates a composite FixturePreparer that is equivalent to applying each of // the supplied FixturePreparer instances in order. // |