launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/testing/git.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "os" 8 9 gc "launchpad.net/gocheck" 10 ) 11 12 type GitSuite struct { 13 oldValues map[string]string 14 } 15 16 // We ensure that Git is told about the user name and email if the setup under which the 17 // tests are run does not already provide that information. These git env variables are used for 18 // that purpose. 19 var gitEnvVars = []string{ 20 "GIT_AUTHOR_NAME", 21 "GIT_AUTHOR_EMAIL", 22 "GIT_COMMITTER_NAME", 23 "GIT_COMMITTER_EMAIL", 24 } 25 26 func (t *GitSuite) SetUpTest(c *gc.C) { 27 t.oldValues = make(map[string]string) 28 for _, v := range gitEnvVars { 29 t.oldValues[v] = os.Getenv(v) 30 } 31 if t.oldValues["GIT_AUTHOR_NAME"] == "" { 32 os.Setenv("GIT_AUTHOR_NAME", "Foo Bar") 33 } 34 if t.oldValues["GIT_AUTHOR_EMAIL"] == "" { 35 os.Setenv("GIT_AUTHOR_EMAIL", "foo@example.org") 36 } 37 os.Setenv("GIT_COMMITTER_NAME", "$GIT_AUTHOR_NAME") 38 os.Setenv("GIT_COMMITTER_EMAIL", "$GIT_AUTHOR_EMAIL") 39 } 40 41 func (t *GitSuite) TearDownTest(c *gc.C) { 42 for k, v := range t.oldValues { 43 os.Setenv(k, v) 44 } 45 }