~themue/juju-core/go-worker-firewaller-machineunits

« back to all changes in this revision

Viewing changes to mstate/state_test.go

  • Committer: Aram Hăvărneanu
  • Date: 2012-06-25 19:13:42 UTC
  • mto: (262.2.2 mstate-machine-tests1)
  • mto: This revision was merged to the branch mainline in revision 263.
  • Revision ID: aram@canonical.com-20120625191342-ubd6t74engy3qcrf
mstate: basic charms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package mstate_test
2
2
 
3
3
import (
 
4
        "fmt"
 
5
        "labix.org/v2/mgo"
 
6
        "labix.org/v2/mgo/bson"
4
7
        . "launchpad.net/gocheck"
 
8
        "launchpad.net/juju-core/charm"
5
9
        state "launchpad.net/juju-core/mstate"
6
 
        "labix.org/v2/mgo"
7
 
        "labix.org/v2/mgo/bson"
8
 
        "testing"
 
10
        "launchpad.net/juju-core/testing"
 
11
        "net/url"
 
12
        stdtesting "testing"
9
13
)
10
14
 
11
 
func Test(t *testing.T) { TestingT(t) }
 
15
func Test(t *stdtesting.T) { TestingT(t) }
12
16
 
13
17
var _ = Suite(&StateSuite{})
14
18
 
15
19
type StateSuite struct {
16
20
        MgoSuite
17
 
        st       *state.State
18
21
        session  *mgo.Session
19
22
        machines *mgo.Collection
 
23
        charms   *mgo.Collection
 
24
        st       *state.State
 
25
        ch       charm.Charm
 
26
        curl     *charm.URL
20
27
}
21
28
 
22
29
func (s *StateSuite) SetUpTest(c *C) {
23
30
        s.MgoSuite.SetUpTest(c)
 
31
        session, err := mgo.Dial(mgoaddr)
 
32
        c.Assert(err, IsNil)
 
33
        s.session = session
 
34
 
24
35
        st, err := state.Dial(mgoaddr)
25
36
        c.Assert(err, IsNil)
26
37
        s.st = st
27
 
        session, err := mgo.Dial(mgoaddr)
28
 
        c.Assert(err, IsNil)
29
 
        s.session = session
 
38
 
30
39
        s.machines = session.DB("juju").C("machines")
 
40
        s.charms = session.DB("juju").C("charms")
 
41
 
 
42
        s.ch = testing.Charms.Dir("dummy")
 
43
        url := fmt.Sprintf("local:series/%s-%d", s.ch.Meta().Name, s.ch.Revision())
 
44
        s.curl = charm.MustParseURL(url)
31
45
}
32
46
 
33
47
func (s *StateSuite) TearDownTest(c *C) {
36
50
        s.MgoSuite.TearDownTest(c)
37
51
}
38
52
 
 
53
func (s *StateSuite) TestAddCharm(c *C) {
 
54
        // Check that adding charms works correctly.
 
55
        bundleURL, err := url.Parse("http://bundle.url")
 
56
        c.Assert(err, IsNil)
 
57
        dummy, err := s.st.AddCharm(s.ch, s.curl, bundleURL, "dummy-sha256")
 
58
        c.Assert(err, IsNil)
 
59
        c.Assert(dummy.URL().String(), Equals, s.curl.String())
 
60
 
 
61
        mdoc := &struct {
 
62
                Url *charm.URL `bson:"_id"`
 
63
        }{}
 
64
        err = s.charms.Find(bson.D{{"_id", s.curl}}).One(mdoc)
 
65
        c.Assert(err, IsNil)
 
66
        c.Assert(mdoc.Url, DeepEquals, s.curl)
 
67
}
 
68
 
39
69
func (s *StateSuite) assertMachineCount(c *C, expect int) {
40
70
        ms, err := s.st.AllMachines()
41
71
        c.Assert(err, IsNil)