1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
jc "github.com/juju/testing/checkers"
12
"github.com/juju/juju/testcharms"
15
// compatSuite contains backwards compatibility tests,
16
// for ensuring state operations behave correctly across
18
type compatSuite struct {
23
var _ = gc.Suite(&compatSuite{})
25
func (s *compatSuite) SetUpTest(c *gc.C) {
26
s.internalStateSuite.SetUpTest(c)
28
env, err := s.state.Model()
29
c.Assert(err, jc.ErrorIsNil)
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.
39
Update: bson.D{{"$unset", bson.D{{"life", nil}}}},
41
err := s.state.runTransaction(ops)
42
c.Assert(err, jc.ErrorIsNil)
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)
49
c.Assert(err, jc.ErrorIsNil)
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)
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)
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)
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)