github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/client/bundles_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package client_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 10 "github.com/juju/juju/apiserver/params" 11 ) 12 13 func (s *serverSuite) TestGetBundleChangesBundleContentError(c *gc.C) { 14 args := params.GetBundleChangesParams{ 15 BundleDataYAML: ":", 16 } 17 r, err := s.client.GetBundleChanges(args) 18 c.Assert(err, gc.ErrorMatches, `cannot read bundle YAML: cannot unmarshal bundle data: YAML error: did not find expected key`) 19 c.Assert(r, gc.DeepEquals, params.GetBundleChangesResults{}) 20 } 21 22 func (s *serverSuite) TestGetBundleChangesBundleVerificationErrors(c *gc.C) { 23 args := params.GetBundleChangesParams{ 24 BundleDataYAML: ` 25 services: 26 django: 27 charm: django 28 to: [1] 29 haproxy: 30 charm: 42 31 num_units: -1 32 `, 33 } 34 r, err := s.client.GetBundleChanges(args) 35 c.Assert(err, jc.ErrorIsNil) 36 c.Assert(r.Changes, gc.IsNil) 37 c.Assert(r.Errors, jc.SameContents, []string{ 38 `placement "1" refers to a machine not defined in this bundle`, 39 `too many units specified in unit placement for service "django"`, 40 `invalid charm URL in service "haproxy": URL has invalid charm or bundle name: "42"`, 41 `negative number of units specified on service "haproxy"`, 42 }) 43 } 44 45 func (s *serverSuite) TestGetBundleChangesBundleConstraintsError(c *gc.C) { 46 args := params.GetBundleChangesParams{ 47 BundleDataYAML: ` 48 services: 49 django: 50 charm: django 51 num_units: 1 52 constraints: bad=wolf 53 `, 54 } 55 r, err := s.client.GetBundleChanges(args) 56 c.Assert(err, jc.ErrorIsNil) 57 c.Assert(r.Changes, gc.IsNil) 58 c.Assert(r.Errors, jc.SameContents, []string{ 59 `invalid constraints "bad=wolf" in service "django": unknown constraint "bad"`, 60 }) 61 } 62 63 func (s *serverSuite) TestGetBundleChangesBundleStorageError(c *gc.C) { 64 args := params.GetBundleChangesParams{ 65 BundleDataYAML: ` 66 services: 67 django: 68 charm: django 69 num_units: 1 70 storage: 71 bad: 0,100M 72 `, 73 } 74 r, err := s.client.GetBundleChanges(args) 75 c.Assert(err, jc.ErrorIsNil) 76 c.Assert(r.Changes, gc.IsNil) 77 c.Assert(r.Errors, jc.SameContents, []string{ 78 `invalid storage "bad" in service "django": cannot parse count: count must be greater than zero, got "0"`, 79 }) 80 } 81 82 func (s *serverSuite) TestGetBundleChangesSuccess(c *gc.C) { 83 args := params.GetBundleChangesParams{ 84 BundleDataYAML: ` 85 services: 86 django: 87 charm: django 88 options: 89 debug: true 90 storage: 91 tmpfs: tmpfs,1G 92 haproxy: 93 charm: cs:trusty/haproxy-42 94 relations: 95 - - django:web 96 - haproxy:web 97 `, 98 } 99 r, err := s.client.GetBundleChanges(args) 100 c.Assert(err, jc.ErrorIsNil) 101 c.Assert(r.Changes, jc.DeepEquals, []*params.BundleChangesChange{{ 102 Id: "addCharm-0", 103 Method: "addCharm", 104 Args: []interface{}{"django"}, 105 }, { 106 Id: "deploy-1", 107 Method: "deploy", 108 Args: []interface{}{ 109 "$addCharm-0", "django", 110 map[string]interface{}{"debug": true}, "", 111 map[string]string{"tmpfs": "tmpfs,1G"}, 112 map[string]string{}, 113 }, 114 Requires: []string{"addCharm-0"}, 115 }, { 116 Id: "addCharm-2", 117 Method: "addCharm", 118 Args: []interface{}{"cs:trusty/haproxy-42"}, 119 }, { 120 Id: "deploy-3", 121 Method: "deploy", 122 Args: []interface{}{ 123 "$addCharm-2", "haproxy", 124 map[string]interface{}{}, "", 125 map[string]string{}, 126 map[string]string{}, 127 }, 128 Requires: []string{"addCharm-2"}, 129 }, { 130 Id: "addRelation-4", 131 Method: "addRelation", 132 Args: []interface{}{"$deploy-1:web", "$deploy-3:web"}, 133 Requires: []string{"deploy-1", "deploy-3"}, 134 }}) 135 c.Assert(r.Errors, gc.IsNil) 136 } 137 138 func (s *serverSuite) TestGetBundleChangesBundleEndpointBindingsSuccess(c *gc.C) { 139 args := params.GetBundleChangesParams{ 140 BundleDataYAML: ` 141 services: 142 django: 143 charm: django 144 num_units: 1 145 bindings: 146 url: public 147 `, 148 } 149 r, err := s.client.GetBundleChanges(args) 150 c.Assert(err, jc.ErrorIsNil) 151 152 for _, change := range r.Changes { 153 if change.Method == "deploy" { 154 c.Assert(change, jc.DeepEquals, ¶ms.BundleChangesChange{ 155 Id: "deploy-1", 156 Method: "deploy", 157 Args: []interface{}{ 158 "$addCharm-0", 159 "django", 160 map[string]interface{}{}, 161 "", 162 map[string]string{}, 163 map[string]string{"url": "public"}, 164 }, 165 Requires: []string{"addCharm-0"}, 166 }) 167 } 168 } 169 }