-
Notifications
You must be signed in to change notification settings - Fork 59
/
payloads_test.go
96 lines (75 loc) · 2.14 KB
/
payloads_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
// Copyright 2015 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(&payloadClassSuite{})
type payloadClassSuite struct{}
func (s *payloadClassSuite) TestParsePayloadClassOkay(c *gc.C) {
name := "my-payload"
data := map[string]interface{}{
"type": "docker",
}
payloadClass := charm.ParsePayloadClass(name, data)
c.Check(payloadClass, jc.DeepEquals, charm.PayloadClass{
Name: "my-payload",
Type: "docker",
})
}
func (s *payloadClassSuite) TestParsePayloadClassMissingName(c *gc.C) {
name := ""
data := map[string]interface{}{
"type": "docker",
}
payloadClass := charm.ParsePayloadClass(name, data)
c.Check(payloadClass, jc.DeepEquals, charm.PayloadClass{
Name: "",
Type: "docker",
})
}
func (s *payloadClassSuite) TestParsePayloadClassEmpty(c *gc.C) {
name := "my-payload"
var data map[string]interface{}
payloadClass := charm.ParsePayloadClass(name, data)
c.Check(payloadClass, jc.DeepEquals, charm.PayloadClass{
Name: "my-payload",
})
}
func (s *payloadClassSuite) TestValidateFull(c *gc.C) {
payloadClass := charm.PayloadClass{
Name: "my-payload",
Type: "docker",
}
err := payloadClass.Validate()
c.Check(err, jc.ErrorIsNil)
}
func (s *payloadClassSuite) TestValidateZeroValue(c *gc.C) {
var payloadClass charm.PayloadClass
err := payloadClass.Validate()
c.Check(err, gc.NotNil)
}
func (s *payloadClassSuite) TestValidateMissingName(c *gc.C) {
payloadClass := charm.PayloadClass{
Type: "docker",
}
err := payloadClass.Validate()
c.Check(err, gc.ErrorMatches, `payload class missing name`)
}
func (s *payloadClassSuite) TestValidateBadName(c *gc.C) {
payloadClass := charm.PayloadClass{
Name: "my-###-payload",
Type: "docker",
}
err := payloadClass.Validate()
c.Check(err, gc.ErrorMatches, `invalid payload class "my-###-payload"`)
}
func (s *payloadClassSuite) TestValidateMissingType(c *gc.C) {
payloadClass := charm.PayloadClass{
Name: "my-payload",
}
err := payloadClass.Validate()
c.Check(err, gc.ErrorMatches, `payload class missing type`)
}