-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_test.go
88 lines (73 loc) · 2.27 KB
/
block_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package upgrades_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/api"
"github.com/juju/juju/api/block"
"github.com/juju/juju/juju"
jujutesting "github.com/juju/juju/juju/testing"
"github.com/juju/juju/state"
"github.com/juju/juju/upgrades"
)
type blockSuite struct {
jujutesting.JujuConnSuite
ctx upgrades.Context
blockClient *block.Client
}
var _ = gc.Suite(&blockSuite{})
func (s *blockSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { conn.Close() })
s.ctx = &mockContext{
agentConfig: &mockAgentConfig{dataDir: s.DataDir()},
apiState: conn,
state: s.State,
}
s.blockClient = block.NewClient(conn)
}
func (s *blockSuite) TestUpdateBlocksNone(c *gc.C) {
err := upgrades.MoveBlocksFromEnvironToState(s.ctx)
c.Assert(err, jc.ErrorIsNil)
s.ensureBlocksUpdated(c, nil)
s.ensureBlocksRemovedFromEnvConfig(c)
}
func (s *blockSuite) ensureBlocksRemovedFromEnvConfig(c *gc.C) {
cfg, err := s.State.EnvironConfig()
c.Assert(err, jc.ErrorIsNil)
attrs := cfg.AllAttrs()
_, exists := attrs["block-destroy-environment"]
c.Assert(exists, jc.IsFalse)
_, exists = attrs["block-remove-object"]
c.Assert(exists, jc.IsFalse)
_, exists = attrs["block-all-changes"]
c.Assert(exists, jc.IsFalse)
}
func (s *blockSuite) ensureBlocksUpdated(c *gc.C, expected []string) {
blocks, err := s.blockClient.List()
c.Assert(err, jc.ErrorIsNil)
var types []string
for _, ablock := range blocks {
types = append(types, ablock.Type)
}
c.Assert(types, jc.SameContents, expected)
}
func (s *blockSuite) TestUpgradeBlocks(c *gc.C) {
err := s.State.UpdateEnvironConfig(map[string]interface{}{
"block-destroy-environment": true,
"block-remove-object": true,
"block-all-changes": true,
}, nil, nil)
c.Assert(err, jc.ErrorIsNil)
err = upgrades.MoveBlocksFromEnvironToState(s.ctx)
c.Assert(err, jc.ErrorIsNil)
s.ensureBlocksUpdated(c, []string{
state.ChangeBlock.String(),
state.DestroyBlock.String(),
state.RemoveBlock.String(),
})
s.ensureBlocksRemovedFromEnvConfig(c)
}