~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/compat_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2014 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package state
5
 
 
6
 
import (
7
 
        jc "github.com/juju/testing/checkers"
8
 
        gc "gopkg.in/check.v1"
9
 
        "gopkg.in/mgo.v2/bson"
10
 
        "gopkg.in/mgo.v2/txn"
11
 
 
12
 
        "github.com/juju/juju/testcharms"
13
 
)
14
 
 
15
 
// compatSuite contains backwards compatibility tests,
16
 
// for ensuring state operations behave correctly across
17
 
// schema changes.
18
 
type compatSuite struct {
19
 
        internalStateSuite
20
 
        env *Model
21
 
}
22
 
 
23
 
var _ = gc.Suite(&compatSuite{})
24
 
 
25
 
func (s *compatSuite) SetUpTest(c *gc.C) {
26
 
        s.internalStateSuite.SetUpTest(c)
27
 
 
28
 
        env, err := s.state.Model()
29
 
        c.Assert(err, jc.ErrorIsNil)
30
 
        s.env = env
31
 
}
32
 
 
33
 
func (s *compatSuite) TestModelAssertAlive(c *gc.C) {
34
 
        // 1.17+ has a "Life" field in model documents.
35
 
        // We remove it here, to test 1.16 compatibility.
36
 
        ops := []txn.Op{{
37
 
                C:      modelsC,
38
 
                Id:     s.env.doc.UUID,
39
 
                Update: bson.D{{"$unset", bson.D{{"life", nil}}}},
40
 
        }}
41
 
        err := s.state.runTransaction(ops)
42
 
        c.Assert(err, jc.ErrorIsNil)
43
 
 
44
 
        // Now check the assertAliveOp and Destroy work as if
45
 
        // the model is Alive.
46
 
        err = s.state.runTransaction([]txn.Op{s.env.assertAliveOp()})
47
 
        c.Assert(err, jc.ErrorIsNil)
48
 
        err = s.env.Destroy()
49
 
        c.Assert(err, jc.ErrorIsNil)
50
 
}
51
 
 
52
 
func (s *compatSuite) TestGetServiceWithoutNetworksIsOK(c *gc.C) {
53
 
        charm := addCharm(c, s.state, "quantal", testcharms.Repo.CharmDir("mysql"))
54
 
        owner := s.env.Owner()
55
 
        service, err := s.state.AddService(AddServiceArgs{Name: "mysql", Owner: owner.String(), Charm: charm})
56
 
        c.Assert(err, jc.ErrorIsNil)
57
 
        // In 1.17.7+ all services have associated document in the
58
 
        // requested networks collection. We remove it here to test
59
 
        // backwards compatibility.
60
 
        ops := []txn.Op{removeRequestedNetworksOp(s.state, service.globalKey())}
61
 
        err = s.state.runTransaction(ops)
62
 
        c.Assert(err, jc.ErrorIsNil)
63
 
 
64
 
        // Now check the trying to fetch service's networks is OK.
65
 
        networks, err := service.Networks()
66
 
        c.Assert(err, jc.ErrorIsNil)
67
 
        c.Assert(networks, gc.HasLen, 0)
68
 
}
69
 
 
70
 
func (s *compatSuite) TestGetMachineWithoutRequestedNetworksIsOK(c *gc.C) {
71
 
        machine, err := s.state.AddMachine("quantal", JobHostUnits)
72
 
        c.Assert(err, jc.ErrorIsNil)
73
 
        // In 1.17.7+ all machines have associated document in the
74
 
        // requested networks collection. We remove it here to test
75
 
        // backwards compatibility.
76
 
        ops := []txn.Op{removeRequestedNetworksOp(s.state, machine.globalKey())}
77
 
        err = s.state.runTransaction(ops)
78
 
        c.Assert(err, jc.ErrorIsNil)
79
 
 
80
 
        // Now check the trying to fetch machine's networks is OK.
81
 
        networks, err := machine.RequestedNetworks()
82
 
        c.Assert(err, jc.ErrorIsNil)
83
 
        c.Assert(networks, gc.HasLen, 0)
84
 
}