-
Notifications
You must be signed in to change notification settings - Fork 59
/
extra_bindings_test.go
69 lines (57 loc) · 2.03 KB
/
extra_bindings_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
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package charm_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/charm/v12"
)
var _ = gc.Suite(&extraBindingsSuite{})
type extraBindingsSuite struct {
riakMeta charm.Meta
}
func (s *extraBindingsSuite) SetUpTest(c *gc.C) {
riakMeta, err := charm.ReadMeta(repoMeta(c, "riak"))
c.Assert(err, jc.ErrorIsNil)
s.riakMeta = *riakMeta
}
func (s *extraBindingsSuite) TestSchemaOkay(c *gc.C) {
raw := map[interface{}]interface{}{
"foo": nil,
"bar": nil,
}
v, err := charm.ExtraBindingsSchema.Coerce(raw, nil)
c.Assert(err, jc.ErrorIsNil)
c.Check(v, jc.DeepEquals, map[interface{}]interface{}{
"foo": nil,
"bar": nil,
})
}
func (s *extraBindingsSuite) TestValidateWithEmptyNonNilMap(c *gc.C) {
s.riakMeta.ExtraBindings = map[string]charm.ExtraBinding{}
err := charm.ValidateMetaExtraBindings(s.riakMeta)
c.Assert(err, gc.ErrorMatches, "extra bindings cannot be empty when specified")
}
func (s *extraBindingsSuite) TestValidateWithEmptyName(c *gc.C) {
s.riakMeta.ExtraBindings = map[string]charm.ExtraBinding{
"": charm.ExtraBinding{Name: ""},
}
err := charm.ValidateMetaExtraBindings(s.riakMeta)
c.Assert(err, gc.ErrorMatches, "missing binding name")
}
func (s *extraBindingsSuite) TestValidateWithMismatchedName(c *gc.C) {
s.riakMeta.ExtraBindings = map[string]charm.ExtraBinding{
"bar": charm.ExtraBinding{Name: "foo"},
}
err := charm.ValidateMetaExtraBindings(s.riakMeta)
c.Assert(err, gc.ErrorMatches, `mismatched extra binding name: got "foo", expected "bar"`)
}
func (s *extraBindingsSuite) TestValidateWithRelationNamesMatchingExtraBindings(c *gc.C) {
s.riakMeta.ExtraBindings = map[string]charm.ExtraBinding{
"admin": charm.ExtraBinding{Name: "admin"},
"ring": charm.ExtraBinding{Name: "ring"},
"foo": charm.ExtraBinding{Name: "foo"},
}
err := charm.ValidateMetaExtraBindings(s.riakMeta)
c.Assert(err, gc.ErrorMatches, `relation names \(admin, ring\) cannot be used in extra bindings`)
}