github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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: 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              applications:
    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 application "django"`,
    40  		`invalid charm URL in application "haproxy": URL has invalid charm or bundle name: "42"`,
    41  		`negative number of units specified on application "haproxy"`,
    42  	})
    43  }
    44  
    45  func (s *serverSuite) TestGetBundleChangesBundleConstraintsError(c *gc.C) {
    46  	args := params.GetBundleChangesParams{
    47  		BundleDataYAML: `
    48              applications:
    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 application "django": unknown constraint "bad"`,
    60  	})
    61  }
    62  
    63  func (s *serverSuite) TestGetBundleChangesBundleStorageError(c *gc.C) {
    64  	args := params.GetBundleChangesParams{
    65  		BundleDataYAML: `
    66              applications:
    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 application "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              applications:
    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",
   110  			"",
   111  			"django",
   112  			map[string]interface{}{"debug": true},
   113  			"",
   114  			map[string]string{"tmpfs": "tmpfs,1G"},
   115  			map[string]string{},
   116  			map[string]int{},
   117  		},
   118  		Requires: []string{"addCharm-0"},
   119  	}, {
   120  		Id:     "addCharm-2",
   121  		Method: "addCharm",
   122  		Args:   []interface{}{"cs:trusty/haproxy-42", "trusty"},
   123  	}, {
   124  		Id:     "deploy-3",
   125  		Method: "deploy",
   126  		Args: []interface{}{
   127  			"$addCharm-2",
   128  			"trusty",
   129  			"haproxy",
   130  			map[string]interface{}{},
   131  			"",
   132  			map[string]string{},
   133  			map[string]string{},
   134  			map[string]int{},
   135  		},
   136  		Requires: []string{"addCharm-2"},
   137  	}, {
   138  		Id:       "addRelation-4",
   139  		Method:   "addRelation",
   140  		Args:     []interface{}{"$deploy-1:web", "$deploy-3:web"},
   141  		Requires: []string{"deploy-1", "deploy-3"},
   142  	}})
   143  	c.Assert(r.Errors, gc.IsNil)
   144  }
   145  
   146  func (s *serverSuite) TestGetBundleChangesBundleEndpointBindingsSuccess(c *gc.C) {
   147  	args := params.GetBundleChangesParams{
   148  		BundleDataYAML: `
   149              applications:
   150                  django:
   151                      charm: django
   152                      num_units: 1
   153                      bindings:
   154                          url: public
   155          `,
   156  	}
   157  	r, err := s.client.GetBundleChanges(args)
   158  	c.Assert(err, jc.ErrorIsNil)
   159  
   160  	for _, change := range r.Changes {
   161  		if change.Method == "deploy" {
   162  			c.Assert(change, jc.DeepEquals, &params.BundleChangesChange{
   163  				Id:     "deploy-1",
   164  				Method: "deploy",
   165  				Args: []interface{}{
   166  					"$addCharm-0",
   167  					"",
   168  					"django",
   169  					map[string]interface{}{},
   170  					"",
   171  					map[string]string{},
   172  					map[string]string{"url": "public"},
   173  					map[string]int{},
   174  				},
   175  				Requires: []string{"addCharm-0"},
   176  			})
   177  		}
   178  	}
   179  }