github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/apiserver/bundle/bundle_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package bundle_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 "gopkg.in/juju/names.v2" 10 11 "github.com/juju/juju/apiserver/bundle" 12 "github.com/juju/juju/apiserver/params" 13 apiservertesting "github.com/juju/juju/apiserver/testing" 14 coretesting "github.com/juju/juju/testing" 15 ) 16 17 type bundleSuite struct { 18 coretesting.BaseSuite 19 facade bundle.Bundle 20 } 21 22 var _ = gc.Suite(&bundleSuite{}) 23 24 func (s *bundleSuite) SetUpTest(c *gc.C) { 25 s.BaseSuite.SetUpTest(c) 26 auth := apiservertesting.FakeAuthorizer{ 27 Tag: names.NewUserTag("who"), 28 } 29 facade, err := bundle.NewFacade(auth) 30 c.Assert(err, jc.ErrorIsNil) 31 s.facade = facade 32 } 33 34 func (s *bundleSuite) TestGetChangesBundleContentError(c *gc.C) { 35 args := params.BundleChangesParams{ 36 BundleDataYAML: ":", 37 } 38 r, err := s.facade.GetChanges(args) 39 c.Assert(err, gc.ErrorMatches, `cannot read bundle YAML: cannot unmarshal bundle data: yaml: did not find expected key`) 40 c.Assert(r, gc.DeepEquals, params.BundleChangesResults{}) 41 } 42 43 func (s *bundleSuite) TestGetChangesBundleVerificationErrors(c *gc.C) { 44 args := params.BundleChangesParams{ 45 BundleDataYAML: ` 46 applications: 47 django: 48 charm: django 49 to: [1] 50 haproxy: 51 charm: 42 52 num_units: -1 53 `, 54 } 55 r, err := s.facade.GetChanges(args) 56 c.Assert(err, jc.ErrorIsNil) 57 c.Assert(r.Changes, gc.IsNil) 58 c.Assert(r.Errors, jc.SameContents, []string{ 59 `placement "1" refers to a machine not defined in this bundle`, 60 `too many units specified in unit placement for application "django"`, 61 `invalid charm URL in application "haproxy": cannot parse URL "42": name "42" not valid`, 62 `negative number of units specified on application "haproxy"`, 63 }) 64 } 65 66 func (s *bundleSuite) TestGetChangesBundleConstraintsError(c *gc.C) { 67 args := params.BundleChangesParams{ 68 BundleDataYAML: ` 69 applications: 70 django: 71 charm: django 72 num_units: 1 73 constraints: bad=wolf 74 `, 75 } 76 r, err := s.facade.GetChanges(args) 77 c.Assert(err, jc.ErrorIsNil) 78 c.Assert(r.Changes, gc.IsNil) 79 c.Assert(r.Errors, jc.SameContents, []string{ 80 `invalid constraints "bad=wolf" in application "django": unknown constraint "bad"`, 81 }) 82 } 83 84 func (s *bundleSuite) TestGetChangesBundleStorageError(c *gc.C) { 85 args := params.BundleChangesParams{ 86 BundleDataYAML: ` 87 applications: 88 django: 89 charm: django 90 num_units: 1 91 storage: 92 bad: 0,100M 93 `, 94 } 95 r, err := s.facade.GetChanges(args) 96 c.Assert(err, jc.ErrorIsNil) 97 c.Assert(r.Changes, gc.IsNil) 98 c.Assert(r.Errors, jc.SameContents, []string{ 99 `invalid storage "bad" in application "django": cannot parse count: count must be greater than zero, got "0"`, 100 }) 101 } 102 103 func (s *bundleSuite) TestGetChangesSuccess(c *gc.C) { 104 args := params.BundleChangesParams{ 105 BundleDataYAML: ` 106 applications: 107 django: 108 charm: django 109 options: 110 debug: true 111 storage: 112 tmpfs: tmpfs,1G 113 haproxy: 114 charm: cs:trusty/haproxy-42 115 relations: 116 - - django:web 117 - haproxy:web 118 `, 119 } 120 r, err := s.facade.GetChanges(args) 121 c.Assert(err, jc.ErrorIsNil) 122 c.Assert(r.Changes, jc.DeepEquals, []*params.BundleChange{{ 123 Id: "addCharm-0", 124 Method: "addCharm", 125 Args: []interface{}{"django", ""}, 126 }, { 127 Id: "deploy-1", 128 Method: "deploy", 129 Args: []interface{}{ 130 "$addCharm-0", 131 "", 132 "django", 133 map[string]interface{}{"debug": true}, 134 "", 135 map[string]string{"tmpfs": "tmpfs,1G"}, 136 map[string]string{}, 137 map[string]int{}, 138 }, 139 Requires: []string{"addCharm-0"}, 140 }, { 141 Id: "addCharm-2", 142 Method: "addCharm", 143 Args: []interface{}{"cs:trusty/haproxy-42", "trusty"}, 144 }, { 145 Id: "deploy-3", 146 Method: "deploy", 147 Args: []interface{}{ 148 "$addCharm-2", 149 "trusty", 150 "haproxy", 151 map[string]interface{}{}, 152 "", 153 map[string]string{}, 154 map[string]string{}, 155 map[string]int{}, 156 }, 157 Requires: []string{"addCharm-2"}, 158 }, { 159 Id: "addRelation-4", 160 Method: "addRelation", 161 Args: []interface{}{"$deploy-1:web", "$deploy-3:web"}, 162 Requires: []string{"deploy-1", "deploy-3"}, 163 }}) 164 c.Assert(r.Errors, gc.IsNil) 165 } 166 167 func (s *bundleSuite) TestGetChangesBundleEndpointBindingsSuccess(c *gc.C) { 168 args := params.BundleChangesParams{ 169 BundleDataYAML: ` 170 applications: 171 django: 172 charm: django 173 num_units: 1 174 bindings: 175 url: public 176 `, 177 } 178 r, err := s.facade.GetChanges(args) 179 c.Assert(err, jc.ErrorIsNil) 180 181 for _, change := range r.Changes { 182 if change.Method == "deploy" { 183 c.Assert(change, jc.DeepEquals, ¶ms.BundleChange{ 184 Id: "deploy-1", 185 Method: "deploy", 186 Args: []interface{}{ 187 "$addCharm-0", 188 "", 189 "django", 190 map[string]interface{}{}, 191 "", 192 map[string]string{}, 193 map[string]string{"url": "public"}, 194 map[string]int{}, 195 }, 196 Requires: []string{"addCharm-0"}, 197 }) 198 } 199 } 200 }