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