~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/utils_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package apiserver
 
5
 
 
6
import (
 
7
        jc "github.com/juju/testing/checkers"
 
8
        gc "gopkg.in/check.v1"
 
9
 
 
10
        "github.com/juju/juju/state"
 
11
        "github.com/juju/juju/state/testing"
 
12
)
 
13
 
 
14
type utilsSuite struct {
 
15
        testing.StateSuite
 
16
        pool *state.StatePool
 
17
}
 
18
 
 
19
var _ = gc.Suite(&utilsSuite{})
 
20
 
 
21
func (s *utilsSuite) SetUpTest(c *gc.C) {
 
22
        s.StateSuite.SetUpTest(c)
 
23
        s.pool = state.NewStatePool(s.State)
 
24
        s.AddCleanup(func(*gc.C) { s.pool.Close() })
 
25
}
 
26
 
 
27
func (s *utilsSuite) TestValidateEmpty(c *gc.C) {
 
28
        uuid, err := validateModelUUID(
 
29
                validateArgs{
 
30
                        statePool: s.pool,
 
31
                })
 
32
        c.Assert(err, jc.ErrorIsNil)
 
33
        c.Assert(uuid, gc.Equals, s.State.ModelUUID())
 
34
}
 
35
 
 
36
func (s *utilsSuite) TestValidateEmptyStrict(c *gc.C) {
 
37
        _, err := validateModelUUID(
 
38
                validateArgs{
 
39
                        statePool: s.pool,
 
40
                        strict:    true,
 
41
                })
 
42
        c.Assert(err, gc.ErrorMatches, `unknown model: ""`)
 
43
}
 
44
 
 
45
func (s *utilsSuite) TestValidateController(c *gc.C) {
 
46
        uuid, err := validateModelUUID(
 
47
                validateArgs{
 
48
                        statePool: s.pool,
 
49
                        modelUUID: s.State.ModelUUID(),
 
50
                })
 
51
        c.Assert(err, jc.ErrorIsNil)
 
52
        c.Assert(uuid, gc.Equals, s.State.ModelUUID())
 
53
}
 
54
 
 
55
func (s *utilsSuite) TestValidateControllerStrict(c *gc.C) {
 
56
        uuid, err := validateModelUUID(
 
57
                validateArgs{
 
58
                        statePool: s.pool,
 
59
                        modelUUID: s.State.ModelUUID(),
 
60
                        strict:    true,
 
61
                })
 
62
        c.Assert(err, jc.ErrorIsNil)
 
63
        c.Assert(uuid, gc.Equals, s.State.ModelUUID())
 
64
}
 
65
 
 
66
func (s *utilsSuite) TestValidateBadModelUUID(c *gc.C) {
 
67
        _, err := validateModelUUID(
 
68
                validateArgs{
 
69
                        statePool: s.pool,
 
70
                        modelUUID: "bad",
 
71
                })
 
72
        c.Assert(err, gc.ErrorMatches, `unknown model: "bad"`)
 
73
}
 
74
 
 
75
func (s *utilsSuite) TestValidateOtherModel(c *gc.C) {
 
76
        envState := s.Factory.MakeModel(c, nil)
 
77
        defer envState.Close()
 
78
 
 
79
        uuid, err := validateModelUUID(
 
80
                validateArgs{
 
81
                        statePool: s.pool,
 
82
                        modelUUID: envState.ModelUUID(),
 
83
                })
 
84
        c.Assert(err, jc.ErrorIsNil)
 
85
        c.Assert(uuid, gc.Equals, envState.ModelUUID())
 
86
}
 
87
 
 
88
func (s *utilsSuite) TestValidateOtherModelControllerOnly(c *gc.C) {
 
89
        envState := s.Factory.MakeModel(c, nil)
 
90
        defer envState.Close()
 
91
 
 
92
        _, err := validateModelUUID(
 
93
                validateArgs{
 
94
                        statePool:           s.pool,
 
95
                        modelUUID:           envState.ModelUUID(),
 
96
                        controllerModelOnly: true,
 
97
                })
 
98
        c.Assert(err, gc.ErrorMatches, `requested model ".*" is not the controller model`)
 
99
}