~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to testing/git.go

  • Committer: William Reade
  • Date: 2012-01-20 21:32:53 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: fwereade@gmail.com-20120120213253-csks5e12opl8t1rq
hefty rearrangement, few actual changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
        . "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 *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 *C) {
42
 
        for k, v := range t.oldValues {
43
 
                os.Setenv(k, v)
44
 
        }
45
 
}