-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
112 lines (96 loc) · 2.83 KB
/
utils_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package apiserver
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/state/testing"
)
type utilsSuite struct {
testing.StateSuite
}
var _ = gc.Suite(&utilsSuite{})
func (s *utilsSuite) TestValidateEmpty(c *gc.C) {
st, needsClosing, err := validateEnvironUUID(
validateArgs{
st: s.State,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(needsClosing, jc.IsFalse)
c.Assert(st.EnvironUUID(), gc.Equals, s.State.EnvironUUID())
}
func (s *utilsSuite) TestValidateEmptyStrict(c *gc.C) {
_, _, err := validateEnvironUUID(
validateArgs{
st: s.State,
strict: true,
})
c.Assert(err, gc.ErrorMatches, `unknown environment: ""`)
}
func (s *utilsSuite) TestValidateStateServer(c *gc.C) {
st, needsClosing, err := validateEnvironUUID(
validateArgs{
st: s.State,
envUUID: s.State.EnvironUUID(),
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(needsClosing, jc.IsFalse)
c.Assert(st.EnvironUUID(), gc.Equals, s.State.EnvironUUID())
}
func (s *utilsSuite) TestValidateStateServerStrict(c *gc.C) {
st, needsClosing, err := validateEnvironUUID(
validateArgs{
st: s.State,
envUUID: s.State.EnvironUUID(),
strict: true,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(needsClosing, jc.IsFalse)
c.Assert(st.EnvironUUID(), gc.Equals, s.State.EnvironUUID())
}
func (s *utilsSuite) TestValidateBadEnvUUID(c *gc.C) {
_, _, err := validateEnvironUUID(
validateArgs{
st: s.State,
envUUID: "bad",
})
c.Assert(err, gc.ErrorMatches, `unknown environment: "bad"`)
}
func (s *utilsSuite) TestValidateOtherEnvironment(c *gc.C) {
envState := s.Factory.MakeEnvironment(c, nil)
defer envState.Close()
st, needsClosing, err := validateEnvironUUID(
validateArgs{
st: s.State,
envUUID: envState.EnvironUUID(),
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(needsClosing, jc.IsTrue)
c.Assert(st.EnvironUUID(), gc.Equals, envState.EnvironUUID())
st.Close()
}
func (s *utilsSuite) TestValidateOtherEnvironmentStateServerOnly(c *gc.C) {
envState := s.Factory.MakeEnvironment(c, nil)
defer envState.Close()
_, _, err := validateEnvironUUID(
validateArgs{
st: s.State,
envUUID: envState.EnvironUUID(),
stateServerEnvOnly: true,
})
c.Assert(err, gc.ErrorMatches, `requested environment ".*" is not the state server environment`)
}
func (s *utilsSuite) TestValidateNonAliveEnvironment(c *gc.C) {
envState := s.Factory.MakeEnvironment(c, nil)
defer envState.Close()
env, err := envState.Environment()
c.Assert(err, jc.ErrorIsNil)
err = env.Destroy()
c.Assert(err, jc.ErrorIsNil)
_, _, err = validateEnvironUUID(
validateArgs{
st: s.State,
envUUID: envState.EnvironUUID(),
})
c.Assert(err, gc.ErrorMatches, `environment ".*" is no longer live`)
}