github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/juju/application/bundle_resources_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package application_test 5 6 import ( 7 "sort" 8 "strings" 9 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 charmresource "gopkg.in/juju/charm.v6-unstable/resource" 13 14 "github.com/juju/juju/cmd/juju/application" 15 "github.com/juju/juju/component/all" 16 "github.com/juju/juju/resource" 17 "github.com/juju/juju/testcharms" 18 ) 19 20 func init() { 21 if err := all.RegisterForServer(); err != nil { 22 panic(err) 23 } 24 } 25 26 type ResourcesBundleSuite struct { 27 application.BundleDeployCharmStoreSuite 28 } 29 30 var _ = gc.Suite(&ResourcesBundleSuite{}) 31 32 func (s *ResourcesBundleSuite) TestDeployBundleResources(c *gc.C) { 33 testcharms.UploadCharm(c, s.Client(), "trusty/starsay-42", "starsay") 34 bundleMeta := ` 35 applications: 36 starsay: 37 charm: cs:starsay 38 num_units: 1 39 resources: 40 store-resource: 0 41 install-resource: 0 42 upload-resource: 0 43 ` 44 output, err := s.DeployBundleYAML(c, bundleMeta) 45 c.Assert(err, jc.ErrorIsNil) 46 47 lines := strings.Split(output, "\n") 48 expectedLines := strings.Split(strings.TrimSpace(` 49 Deploying charm "cs:trusty/starsay-42" 50 added resource install-resource 51 added resource store-resource 52 added resource upload-resource 53 Deploy of bundle completed. 54 `), "\n") 55 c.Check(lines, gc.HasLen, len(expectedLines)) 56 c.Check(lines[0], gc.Equals, expectedLines[0]) 57 // The "added resource" lines are checked after we sort since 58 // the ordering of those lines is unknown. 59 sort.Strings(lines) 60 sort.Strings(expectedLines) 61 c.Check(lines, jc.DeepEquals, expectedLines) 62 s.checkResources(c, "starsay", []resource.Resource{{ 63 Resource: charmresource.Resource{ 64 Meta: charmresource.Meta{ 65 Name: "install-resource", 66 Type: charmresource.TypeFile, 67 Path: "gotta-have-it.txt", 68 Description: "get things started", 69 }, 70 Origin: charmresource.OriginStore, 71 Revision: 0, 72 Fingerprint: resourceHash("install-resource content"), 73 Size: int64(len("install-resource content")), 74 }, 75 ID: "starsay/install-resource", 76 ApplicationID: "starsay", 77 }, { 78 Resource: charmresource.Resource{ 79 Meta: charmresource.Meta{ 80 Name: "store-resource", 81 Type: charmresource.TypeFile, 82 Path: "filename.tgz", 83 Description: "One line that is useful when operators need to push it.", 84 }, 85 Origin: charmresource.OriginStore, 86 Fingerprint: resourceHash("store-resource content"), 87 Size: int64(len("store-resource content")), 88 Revision: 0, 89 }, 90 ID: "starsay/store-resource", 91 ApplicationID: "starsay", 92 }, { 93 Resource: charmresource.Resource{ 94 Meta: charmresource.Meta{ 95 Name: "upload-resource", 96 Type: charmresource.TypeFile, 97 Path: "somename.xml", 98 Description: "Who uses xml anymore?", 99 }, 100 Origin: charmresource.OriginStore, 101 Fingerprint: resourceHash("upload-resource content"), 102 Size: int64(len("upload-resource content")), 103 Revision: 0, 104 }, 105 ID: "starsay/upload-resource", 106 ApplicationID: "starsay", 107 }}) 108 } 109 110 func (s *ResourcesBundleSuite) checkResources(c *gc.C, serviceName string, expected []resource.Resource) { 111 _, err := s.State.Application("starsay") 112 c.Check(err, jc.ErrorIsNil) 113 st, err := s.State.Resources() 114 c.Assert(err, jc.ErrorIsNil) 115 svcResources, err := st.ListResources("starsay") 116 c.Assert(err, jc.ErrorIsNil) 117 resources := svcResources.Resources 118 resource.Sort(resources) 119 c.Assert(resources, jc.DeepEquals, expected) 120 }