Allow customization of the env configuration in a test fixture

Adds FixtureModifyEnv and FixtureMergeEnv.

Bug: 181070625
Test: m nothing
Change-Id: I1b6eb88907efa2476d96912961fea2df2d902659
diff --git a/android/fixture.go b/android/fixture.go
index 2085e43..607b5bd 100644
--- a/android/fixture.go
+++ b/android/fixture.go
@@ -15,6 +15,7 @@
 package android
 
 import (
+	"fmt"
 	"reflect"
 	"strings"
 	"testing"
@@ -286,6 +287,32 @@
 	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.
 //