forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodelvalidation_test.go
44 lines (35 loc) · 1.52 KB
/
modelvalidation_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
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuclient_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/jujuclient"
"github.com/juju/juju/testing"
)
type ModelValidationSuite struct {
testing.BaseSuite
model jujuclient.ModelDetails
}
func (s *ModelValidationSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
s.model = jujuclient.ModelDetails{
"test.uuid",
}
}
var _ = gc.Suite(&ModelValidationSuite{})
func (s *ModelValidationSuite) TestValidateModelName(c *gc.C) {
c.Assert(jujuclient.ValidateModelName("foo@bar/baz"), jc.ErrorIsNil)
c.Assert(jujuclient.ValidateModelName("foo"), gc.ErrorMatches, `validating model name "foo": unqualified model name "foo" not valid`)
c.Assert(jujuclient.ValidateModelName(""), gc.ErrorMatches, `validating model name "": unqualified model name "" not valid`)
c.Assert(jujuclient.ValidateModelName("!"), gc.ErrorMatches, `validating model name "!": unqualified model name "!" not valid`)
c.Assert(jujuclient.ValidateModelName("!/foo"), gc.ErrorMatches, `validating model name "!/foo": user name "!" not valid`)
}
func (s *ModelValidationSuite) TestValidateModelDetailsNoModelUUID(c *gc.C) {
s.model.ModelUUID = ""
s.assertValidateModelDetailsFails(c, "missing uuid, model details not valid")
}
func (s *ModelValidationSuite) assertValidateModelDetailsFails(c *gc.C, failureMessage string) {
err := jujuclient.ValidateModelDetails(s.model)
c.Assert(err, gc.ErrorMatches, failureMessage)
}