Beispiel #1
0
func (e *MergeEnvSuite) TestMergeEnviron(c *gc.C) {
	// environment does not get fully cleared on Windows
	// when using testing.IsolationSuite
	origEnv := os.Environ()
	extraExpected := []string{
		"DUMMYVAR=foo",
		"DUMMYVAR2=bar",
		"NEWVAR=ImNew",
	}
	expectEnv := make([]string, 0, len(origEnv)+len(extraExpected))

	// os.Environ prepends some garbage on Windows that we need to strip out.
	// All the garbage starts and ends with = (for example "=C:=").
	for _, v := range origEnv {
		if !(strings.HasPrefix(v, "=") && strings.HasSuffix(v, "=")) {
			expectEnv = append(expectEnv, v)
		}
	}
	expectEnv = append(expectEnv, extraExpected...)
	os.Setenv("DUMMYVAR2", "ChangeMe")
	os.Setenv("DUMMYVAR", "foo")

	newEnv := make([]string, 0, len(expectEnv))
	for _, v := range runner.MergeWindowsEnvironment([]string{"dummyvar2=bar", "NEWVAR=ImNew"}, os.Environ()) {
		if !(strings.HasPrefix(v, "=") && strings.HasSuffix(v, "=")) {
			newEnv = append(newEnv, v)
		}
	}
	c.Assert(expectEnv, jc.SameContents, newEnv)
}
Beispiel #2
0
func (s *MergeEnvSuite) TestMergeEnvWin(c *gc.C) {
	initial := []string{"a=foo", "b=bar", "foo=val"}
	newValues := []string{"a=baz", "c=omg", "FOO=val2", "d=another"}

	created := runner.MergeWindowsEnvironment(newValues, initial)
	expected := []string{"a=baz", "b=bar", "c=omg", "foo=val2", "d=another"}
	c.Check(created, jc.SameContents, expected)
}