813
839
s.PatchValue(&charmrepo.CacheDir, c.MkDir())
815
841
// Point the CLI to the charm store testing server.
816
original := newCharmStoreClient
817
s.PatchValue(&newCharmStoreClient, func(httpClient *http.Client) *csClient {
818
csclient := original(httpClient)
819
csclient.params.URL = s.srv.URL
842
s.PatchValue(&newCharmStoreClient, func(client *httpbakery.Client) *csclient.Client {
820
843
// Add a cookie so that the discharger can detect whether the
821
844
// HTTP client is the juju environment or the juju client.
822
845
lurl, err := url.Parse(s.discharger.Location())
823
846
c.Assert(err, jc.ErrorIsNil)
824
csclient.params.HTTPClient.Jar.SetCookies(lurl, []*http.Cookie{{
847
client.Jar.SetCookies(lurl, []*http.Cookie{{
825
848
Name: clientUserCookie,
826
849
Value: clientUserName,
851
return csclient.New(csclient.Params{
853
BakeryClient: client,
831
857
// Point the Juju API server to the charm store testing server.
832
858
s.PatchValue(&csclient.ServerURL, s.srv.URL)
834
s.PatchValue(&getApiClient, func(*http.Client) (apiClient, error) { return &mockBudgetAPIClient{&jujutesting.Stub{}}, nil })
860
s.PatchValue(&getApiClient, func(*httpbakery.Client) (apiClient, error) {
861
return &mockBudgetAPIClient{&jujutesting.Stub{}}, nil
837
865
func (s *charmStoreSuite) TearDownTest(c *gc.C) {
1100
1128
_, err = s.State.AddSpace("public", "", nil, false)
1101
1129
c.Assert(err, jc.ErrorIsNil)
1103
testcharms.UploadCharm(c, s.client, "cs:quantal/wordpress-1", "wordpress")
1104
err = runDeploy(c, "cs:quantal/wordpress-1", "--bind", "db=db public")
1131
testcharms.UploadCharm(c, s.client, "cs:quantal/wordpress-extra-bindings-1", "wordpress-extra-bindings")
1132
err = runDeploy(c, "cs:quantal/wordpress-extra-bindings-1", "--bind", "db=db db-client=db public admin-api=public")
1105
1133
c.Assert(err, jc.ErrorIsNil)
1106
1134
s.assertServicesDeployed(c, map[string]serviceInfo{
1107
"wordpress": {charm: "cs:quantal/wordpress-1"},
1135
"wordpress-extra-bindings": {charm: "cs:quantal/wordpress-extra-bindings-1"},
1109
1137
s.assertDeployedServiceBindings(c, map[string]serviceInfo{
1138
"wordpress-extra-bindings": {
1111
1139
endpointBindings: map[string]string{
1112
1140
"cache": "public",
1113
1141
"url": "public",
1114
1142
"logging-dir": "public",
1115
1143
"monitoring-port": "public",
1146
"admin-api": "public",
1147
"foo-bar": "public",
1148
"cluster": "public",
1150
1182
var _ = gc.Suite(&ParseBindSuite{})
1152
func (s *ParseBindSuite) TestBindParseEmpty(c *gc.C) {
1153
deploy := &DeployCommand{BindToSpaces: ""}
1154
err := deploy.parseBind()
1155
c.Assert(err, jc.ErrorIsNil)
1156
c.Assert(deploy.Bindings, gc.IsNil)
1159
func (s *ParseBindSuite) TestBindParseOK(c *gc.C) {
1160
deploy := &DeployCommand{BindToSpaces: "foo=a bar=b"}
1161
err := deploy.parseBind()
1162
c.Assert(err, jc.ErrorIsNil)
1163
c.Assert(deploy.Bindings, jc.DeepEquals, map[string]string{"foo": "a", "bar": "b"})
1166
func (s *ParseBindSuite) TestBindParseServiceDefault(c *gc.C) {
1167
deploy := &DeployCommand{BindToSpaces: "service-default"}
1168
err := deploy.parseBind()
1169
c.Assert(err, jc.ErrorIsNil)
1170
c.Assert(deploy.Bindings, jc.DeepEquals, map[string]string{"": "service-default"})
1173
func (s *ParseBindSuite) TestBindParseNoEndpoint(c *gc.C) {
1174
deploy := &DeployCommand{BindToSpaces: "=bad"}
1175
err := deploy.parseBind()
1176
c.Assert(err.Error(), gc.Equals, parseBindErrorPrefix+"Found = without relation name. Use a lone space name to set the default.")
1177
c.Assert(deploy.Bindings, gc.IsNil)
1180
func (s *ParseBindSuite) TestBindParseBadList(c *gc.C) {
1181
deploy := &DeployCommand{BindToSpaces: "foo=bar=baz"}
1182
err := deploy.parseBind()
1183
c.Assert(err.Error(), gc.Equals, parseBindErrorPrefix+"Found multiple = in binding. Did you forget to space-separate the binding list?")
1184
c.Assert(deploy.Bindings, gc.IsNil)
1187
func (s *ParseBindSuite) TestBindParseDefaultAndEndpoints(c *gc.C) {
1188
deploy := &DeployCommand{BindToSpaces: "rel1=space1 rel2=space2 space3"}
1189
err := deploy.parseBind()
1190
c.Assert(err, jc.ErrorIsNil)
1191
c.Assert(deploy.Bindings, jc.DeepEquals, map[string]string{"rel1": "space1", "rel2": "space2", "": "space3"})
1194
func (s *ParseBindSuite) TestBindParseDefaultAndEndpoints2(c *gc.C) {
1195
deploy := &DeployCommand{BindToSpaces: "rel1=space1 space3 rel2=space2"}
1196
err := deploy.parseBind()
1197
c.Assert(err, jc.ErrorIsNil)
1198
c.Assert(deploy.Bindings, jc.DeepEquals, map[string]string{"rel1": "space1", "rel2": "space2", "": "space3"})
1201
func (s *ParseBindSuite) TestBindParseDefaultAndEndpoints3(c *gc.C) {
1202
deploy := &DeployCommand{BindToSpaces: "space3 rel1=space1 rel2=space2"}
1203
err := deploy.parseBind()
1204
c.Assert(err, jc.ErrorIsNil)
1205
c.Assert(deploy.Bindings, jc.DeepEquals, map[string]string{"rel1": "space1", "rel2": "space2", "": "space3"})
1208
func (s *ParseBindSuite) TestBindParseBadSpace(c *gc.C) {
1209
deploy := &DeployCommand{BindToSpaces: "rel1=spa#ce1"}
1210
err := deploy.parseBind()
1211
c.Assert(err.Error(), gc.Equals, parseBindErrorPrefix+"Space name invalid.")
1212
c.Assert(deploy.Bindings, gc.IsNil)
1184
func (s *ParseBindSuite) TestParseSuccessWithEmptyArgs(c *gc.C) {
1185
s.checkParseOKForArgs(c, "", nil)
1188
func (s *ParseBindSuite) TestParseSuccessWithEndpointsOnly(c *gc.C) {
1189
s.checkParseOKForArgs(c, "foo=a bar=b", map[string]string{"foo": "a", "bar": "b"})
1192
func (s *ParseBindSuite) TestParseSuccessWithServiceDefaultSpaceOnly(c *gc.C) {
1193
s.checkParseOKForArgs(c, "service-default", map[string]string{"": "service-default"})
1196
func (s *ParseBindSuite) TestBindingsOrderForDefaultSpaceAndEndpointsDoesNotMatter(c *gc.C) {
1197
expectedBindings := map[string]string{
1202
s.checkParseOKForArgs(c, "ep1=sp1 ep2=sp2 sp3", expectedBindings)
1203
s.checkParseOKForArgs(c, "ep1=sp1 sp3 ep2=sp2", expectedBindings)
1204
s.checkParseOKForArgs(c, "ep2=sp2 ep1=sp1 sp3", expectedBindings)
1205
s.checkParseOKForArgs(c, "ep2=sp2 sp3 ep1=sp1", expectedBindings)
1206
s.checkParseOKForArgs(c, "sp3 ep1=sp1 ep2=sp2", expectedBindings)
1207
s.checkParseOKForArgs(c, "sp3 ep2=sp2 ep1=sp1", expectedBindings)
1210
func (s *ParseBindSuite) TestParseFailsWithSpaceNameButNoEndpoint(c *gc.C) {
1211
s.checkParseFailsForArgs(c, "=bad", "Found = without endpoint name. Use a lone space name to set the default.")
1214
func (s *ParseBindSuite) TestParseFailsWithTooManyEqualsSignsInArgs(c *gc.C) {
1215
s.checkParseFailsForArgs(c, "foo=bar=baz", "Found multiple = in binding. Did you forget to space-separate the binding list?")
1218
func (s *ParseBindSuite) TestParseFailsWithBadSpaceName(c *gc.C) {
1219
s.checkParseFailsForArgs(c, "rel1=spa#ce1", "Space name invalid.")
1222
func (s *ParseBindSuite) runParseBindWithArgs(args string) (error, map[string]string) {
1223
deploy := &DeployCommand{BindToSpaces: args}
1224
return deploy.parseBind(), deploy.Bindings
1227
func (s *ParseBindSuite) checkParseOKForArgs(c *gc.C, args string, expectedBindings map[string]string) {
1228
err, parsedBindings := s.runParseBindWithArgs(args)
1229
c.Check(err, jc.ErrorIsNil)
1230
c.Check(parsedBindings, jc.DeepEquals, expectedBindings)
1233
func (s *ParseBindSuite) checkParseFailsForArgs(c *gc.C, args string, expectedErrorSuffix string) {
1234
err, parsedBindings := s.runParseBindWithArgs(args)
1235
c.Check(err.Error(), gc.Equals, parseBindErrorPrefix+expectedErrorSuffix)
1236
c.Check(parsedBindings, gc.IsNil)