~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to environs/local/environ_test.go

[r=thumper] Add the initial bootstrap implementation.

This isn't all that is needed to bootstrap, but it is the start.
In particular, this adds the mongo upstart service. This branch
also adds a very simple instance implementation for the local
instances.

https://codereview.appspot.com/11325043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package local_test
5
5
 
6
6
import (
 
7
        "io/ioutil"
 
8
        "os"
 
9
        "path/filepath"
 
10
 
7
11
        gc "launchpad.net/gocheck"
8
12
 
9
13
        "launchpad.net/juju-core/environs/jujutest"
40
44
type localJujuTestSuite struct {
41
45
        baseProviderSuite
42
46
        jujutest.Tests
 
47
        restoreRootCheck   func()
 
48
        oldUpstartLocation string
 
49
        oldPath            string
 
50
        testPath           string
 
51
        dbServiceName      string
43
52
}
44
53
 
45
54
func (s *localJujuTestSuite) SetUpTest(c *gc.C) {
46
55
        s.baseProviderSuite.SetUpTest(c)
 
56
        // Construct the directories first.
 
57
        err := local.CreateDirs(c, minimalConfig(c))
 
58
        c.Assert(err, gc.IsNil)
 
59
        s.oldUpstartLocation = local.SetUpstartScriptLocation(c.MkDir())
 
60
        s.oldPath = os.Getenv("PATH")
 
61
        s.testPath = c.MkDir()
 
62
        os.Setenv("PATH", s.testPath+":"+s.oldPath)
 
63
 
 
64
        // Add in an admin secret
 
65
        s.Tests.TestConfig.Config["admin-secret"] = "sekrit"
 
66
        s.restoreRootCheck = local.SetRootCheckFunction(func() bool { return true })
47
67
        s.Tests.SetUpTest(c)
 
68
        s.dbServiceName = "juju-db-" + local.ConfigNamespace(s.Env.Config())
48
69
}
49
70
 
50
71
func (s *localJujuTestSuite) TearDownTest(c *gc.C) {
51
 
        // TODO(thumper): add the TearDownTest for s.Tests when destroy is implemented
52
 
        // s.Tests.TearDownTest(c)
 
72
        s.Tests.TearDownTest(c)
 
73
        os.Setenv("PATH", s.oldPath)
 
74
        s.restoreRootCheck()
 
75
        local.SetUpstartScriptLocation(s.oldUpstartLocation)
53
76
        s.baseProviderSuite.TearDownTest(c)
54
77
}
55
78
 
 
79
func (s *localJujuTestSuite) MakeTool(c *gc.C, name, script string) {
 
80
        path := filepath.Join(s.testPath, name)
 
81
        script = "#!/bin/bash\n" + script
 
82
        err := ioutil.WriteFile(path, []byte(script), 0755)
 
83
        c.Assert(err, gc.IsNil)
 
84
}
 
85
 
 
86
func (s *localJujuTestSuite) StoppedStatus(c *gc.C) {
 
87
        s.MakeTool(c, "status", `echo "some-service stop/waiting"`)
 
88
}
 
89
 
 
90
func (s *localJujuTestSuite) RunningStatus(c *gc.C) {
 
91
        s.MakeTool(c, "status", `echo "some-service start/running, process 123"`)
 
92
}
 
93
 
56
94
var _ = gc.Suite(&localJujuTestSuite{
57
95
        Tests: jujutest.Tests{
58
96
                TestConfig: jujutest.TestConfig{minimalConfigValues()},
60
98
})
61
99
 
62
100
func (s *localJujuTestSuite) TestBootstrap(c *gc.C) {
63
 
        c.Skip("Bootstrap not implemented yet.")
 
101
        c.Skip("Cannot test bootstrap at this stage.")
64
102
}
65
103
 
66
104
func (s *localJujuTestSuite) TestStartStop(c *gc.C) {