github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/cmd/juju/get_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package main 5 6 import ( 7 "bytes" 8 9 "github.com/juju/charm" 10 "github.com/juju/cmd" 11 gc "launchpad.net/gocheck" 12 "launchpad.net/goyaml" 13 14 "github.com/juju/juju/cmd/envcmd" 15 "github.com/juju/juju/juju/testing" 16 coretesting "github.com/juju/juju/testing" 17 ) 18 19 type GetSuite struct { 20 testing.JujuConnSuite 21 } 22 23 var _ = gc.Suite(&GetSuite{}) 24 25 var getTests = []struct { 26 service string 27 expected map[string]interface{} 28 }{ 29 { 30 "dummy-service", 31 map[string]interface{}{ 32 "service": "dummy-service", 33 "charm": "dummy", 34 "settings": map[string]interface{}{ 35 "title": map[string]interface{}{ 36 "description": "A descriptive title used for the service.", 37 "type": "string", 38 "value": "Nearly There", 39 }, 40 "skill-level": map[string]interface{}{ 41 "description": "A number indicating skill.", 42 "type": "int", 43 "default": true, 44 }, 45 "username": map[string]interface{}{ 46 "description": "The name of the initial account (given admin permissions).", 47 "type": "string", 48 "value": "admin001", 49 "default": true, 50 }, 51 "outlook": map[string]interface{}{ 52 "description": "No default outlook.", 53 "type": "string", 54 "default": true, 55 }, 56 }, 57 }, 58 }, 59 60 // TODO(dfc) add additional services (need more charms) 61 // TODO(dfc) add set tests 62 } 63 64 func (s *GetSuite) TestGetConfig(c *gc.C) { 65 sch := s.AddTestingCharm(c, "dummy") 66 svc := s.AddTestingService(c, "dummy-service", sch) 67 err := svc.UpdateConfigSettings(charm.Settings{"title": "Nearly There"}) 68 c.Assert(err, gc.IsNil) 69 for _, t := range getTests { 70 ctx := coretesting.Context(c) 71 code := cmd.Main(envcmd.Wrap(&GetCommand{}), ctx, []string{t.service}) 72 c.Check(code, gc.Equals, 0) 73 c.Assert(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "") 74 // round trip via goyaml to avoid being sucked into a quagmire of 75 // map[interface{}]interface{} vs map[string]interface{}. This is 76 // also required if we add json support to this command. 77 buf, err := goyaml.Marshal(t.expected) 78 c.Assert(err, gc.IsNil) 79 expected := make(map[string]interface{}) 80 err = goyaml.Unmarshal(buf, &expected) 81 c.Assert(err, gc.IsNil) 82 83 actual := make(map[string]interface{}) 84 err = goyaml.Unmarshal(ctx.Stdout.(*bytes.Buffer).Bytes(), &actual) 85 c.Assert(err, gc.IsNil) 86 c.Assert(actual, gc.DeepEquals, expected) 87 } 88 }