Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Peppe committed Aug 23, 2012
1 parent f316670 commit e42a34a
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 21 deletions.
22 changes: 21 additions & 1 deletion downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,28 @@ import (
)

type suite struct {
testing.HTTPSuite
testing.LoggingSuite
testing.HTTPSuite
}

func (s *suite) SetUpSuite(c *C) {
s.LoggingSuite.SetUpSuite(c)
s.HTTPSuite.SetUpSuite(c)
}

func (s *suite) TearDownSuite(c *C) {
s.HTTPSuite.TearDownSuite(c)
s.LoggingSuite.TearDownSuite(c)
}

func (s *suite) SetUpTest(c *C) {
s.LoggingSuite.SetUpTest(c)
s.HTTPSuite.SetUpTest(c)
}

func (s *suite) TearDownTest(c *C) {
s.HTTPSuite.TearDownTest(c)
s.LoggingSuite.TearDownTest(c)
}

var _ = Suite(&suite{})
Expand Down
2 changes: 2 additions & 0 deletions environs/ec2/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type LiveTests struct {
}

func (t *LiveTests) SetUpSuite(c *C) {
t.LoggingSuite.SetUpSuite(c)
e, err := t.Environs.Open("")
c.Assert(err, IsNil)
// Put some fake tools in place so that tests that are simply
Expand All @@ -85,6 +86,7 @@ func (t *LiveTests) TearDownSuite(c *C) {
}
err := ec2.DeleteStorageContent(t.Env.PublicStorage().(environs.Storage))
c.Assert(err, IsNil)
t.LoggingSuite.TearDownSuite(c)
}

func (t *LiveTests) SetUpTest(c *C) {
Expand Down
4 changes: 4 additions & 0 deletions environs/ec2/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type localLiveSuite struct {
}

func (t *localLiveSuite) SetUpSuite(c *C) {
t.LoggingSuite.SetUpSuite(c)
ec2.UseTestImageData(true)
t.srv.startServer(c)
t.LiveTests.SetUpSuite(c)
Expand All @@ -82,6 +83,7 @@ func (t *localLiveSuite) TearDownSuite(c *C) {
t.env = nil
ec2.ShortTimeouts(false)
ec2.UseTestImageData(false)
t.LoggingSuite.TearDownSuite(c)
}

func (t *localLiveSuite) SetUpTest(c *C) {
Expand Down Expand Up @@ -169,6 +171,7 @@ type localServerSuite struct {
}

func (t *localServerSuite) SetUpSuite(c *C) {
t.LoggingSuite.SetUpSuite(c)
ec2.UseTestImageData(true)
ec2.UseTestMetadata(true)
t.Tests.SetUpSuite(c)
Expand All @@ -180,6 +183,7 @@ func (t *localServerSuite) TearDownSuite(c *C) {
ec2.ShortTimeouts(false)
ec2.UseTestMetadata(false)
ec2.UseTestImageData(false)
t.LoggingSuite.TearDownSuite(c)
}

func (t *localServerSuite) SetUpTest(c *C) {
Expand Down
4 changes: 0 additions & 4 deletions juju/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ type ConnSuite struct {

var _ = Suite(&ConnSuite{})

func (cs *ConnSuite) SetUpTest(c *C) {
cs.LoggingSuite.SetUpTest(c)
}

func (cs *ConnSuite) TearDownTest(c *C) {
dummy.Reset()
cs.LoggingSuite.TearDownTest(c)
Expand Down
26 changes: 19 additions & 7 deletions juju/testing/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
"path/filepath"
)

// JujuConnSuite provides a freshly bootstrapped juju.Conn
// JujuConnSuitex provides a freshly bootstrapped juju.Conn
// for each test. It also includes testing.LoggingSuite.
//
// It also sets up $HOME and environs.VarDir to
// temporary directories; the former is primed to
// hold the dummy environments.yaml file.
//
// The name of the dummy environment is "jujutest".
type JujuConnSuite struct {
type JujuConnSuitex struct {
testing.LoggingSuite
testing.ZkSuite
Conn *juju.Conn
Expand All @@ -40,8 +40,19 @@ environments:
authorized-keys: 'i-am-a-key'
`)

func (s *JujuConnSuite) SetUpTest(c *C) {
func (s *JujuConnSuitex) SetUpSuite(c *C) {
s.LoggingSuite.SetUpSuite(c)
s.ZkSuite.SetUpSuite(c)
}

func (s *JujuConnSuitex) TearDownSuite(c *C) {
s.ZkSuite.TearDownSuite(c)
s.LoggingSuite.TearDownSuite(c)
}

func (s *JujuConnSuitex) SetUpTest(c *C) {
s.LoggingSuite.SetUpTest(c)
s.ZkSuite.SetUpTest(c)

s.home = os.Getenv("HOME")
home := c.MkDir()
Expand All @@ -67,7 +78,7 @@ func (s *JujuConnSuite) SetUpTest(c *C) {
c.Assert(err, IsNil)
}

func (s *JujuConnSuite) TearDownTest(c *C) {
func (s *JujuConnSuitex) TearDownTest(c *C) {
dummy.Reset()
c.Assert(s.Conn.Close(), IsNil)
s.Conn = nil
Expand All @@ -76,11 +87,12 @@ func (s *JujuConnSuite) TearDownTest(c *C) {
s.home = ""
environs.VarDir = s.varDir
s.varDir = ""
s.ZkSuite.TearDownTest(c)
s.LoggingSuite.TearDownTest(c)
}

// WriteConfig writes a juju config file to the "home" directory.
func (s *JujuConnSuite) WriteConfig(config string) {
func (s *JujuConnSuitex) WriteConfig(config string) {
if s.home == "" {
panic("SetUpTest has not been called; will not overwrite $HOME/.juju/environments.yaml")
}
Expand All @@ -91,11 +103,11 @@ func (s *JujuConnSuite) WriteConfig(config string) {
}
}

func (s *JujuConnSuite) StateInfo(c *C) *state.Info {
func (s *JujuConnSuitex) StateInfo(c *C) *state.Info {
return &state.Info{Addrs: []string{testing.ZkAddr}}
}

func (s *JujuConnSuite) AddTestingCharm(c *C, name string) *state.Charm {
func (s *JujuConnSuitex) AddTestingCharm(c *C, name string) *state.Charm {
ch := testing.Charms.Dir(name)
ident := fmt.Sprintf("%s-%d", name, ch.Revision())
curl := charm.MustParseURL("local:series/" + ident)
Expand Down
6 changes: 0 additions & 6 deletions state/presence/presence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ func TestPackage(t *stdtesting.T) {
}

type PresenceSuite struct {
testing.LoggingSuite
testing.ZkConnSuite
}

var _ = Suite(&PresenceSuite{})

func (s *PresenceSuite) TearDownTest(c *C) {
s.ZkConnSuite.TearDownTest(c)
s.LoggingSuite.TearDownTest(c)
}

var (
path = "/presence"
period = 500 * time.Millisecond
Expand Down
20 changes: 20 additions & 0 deletions state/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ func init() {

var _ = Suite(&sshSuite{})

func (s *sshSuite) SetUpSuite(c *C) {
s.LoggingSuite.SetUpSuite(c)
s.ZkSuite.SetUpSuite(c)
}

func (s *sshSuite) TearDownSuite(c *C) {
s.ZkSuite.TearDownSuite(c)
s.LoggingSuite.TearDownSuite(c)
}

func (s *sshSuite) SetUpTest(c *C) {
s.LoggingSuite.SetUpTest(c)
s.ZkSuite.SetUpTest(c)
}

func (s *sshSuite) TearDownTest(c *C) {
s.ZkSuite.TearDownTest(c)
s.LoggingSuite.TearDownTest(c)
}

// fakeSSHRun represents the behaviour of the ssh command when run once.
type fakeSSHRun struct {
Output string // The fake ssh will print this...
Expand Down
5 changes: 5 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func (s *StoreSuite) SetUpSuite(c *C) {
s.HTTPSuite.SetUpSuite(c)
}

func (s *StoreSuite) TearDownSuite(c *C) {
s.HTTPSuite.TearDownSuite(c)
s.MgoSuite.TearDownSuite(c)
}

func (s *StoreSuite) SetUpTest(c *C) {
s.MgoSuite.SetUpTest(c)
var err error
Expand Down
3 changes: 3 additions & 0 deletions testing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var Server = NewHTTPServer("http://localhost:4444", 5*time.Second)
func (s *HTTPSuite) SetUpSuite(c *C) {
Server.Start()
}
func (s *HTTPSuite) TearDownSuite(c *C) {}

func (s *HTTPSuite) SetUpTest(c *C) {}

func (s *HTTPSuite) TearDownTest(c *C) {
Server.Flush()
Expand Down
9 changes: 6 additions & 3 deletions testing/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testing

import (
"launchpad.net/gocheck"
. "launchpad.net/gocheck"
"launchpad.net/juju-core/log"
)

Expand All @@ -12,14 +12,17 @@ type LoggingSuite struct {
oldDebug bool
}

func (t *LoggingSuite) SetUpTest(c *gocheck.C) {
func (t *LoggingSuite) SetUpSuite(c *C) {}
func (t *LoggingSuite) TearDownSuite(c *C) {}

func (t *LoggingSuite) SetUpTest(c *C) {
t.oldTarget = log.Target
t.oldDebug = log.Debug
log.Debug = true
log.Target = c
}

func (t *LoggingSuite) TearDownTest(c *gocheck.C) {
func (t *LoggingSuite) TearDownTest(c *C) {
log.Target = t.oldTarget
log.Debug = t.oldDebug
}
3 changes: 3 additions & 0 deletions testing/zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func (s ZkSuite) SetUpSuite(c *C) {
panic("ZkSuite tests must be run with ZkTestPackage")
}
}
func (s ZkSuite) TearDownSuite(c *C) {}

func (s ZkSuite) SetUpTest(c *C) {}

func (s ZkSuite) TearDownTest(c *C) {
ZkReset()
Expand Down

0 comments on commit e42a34a

Please sign in to comment.