github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/service/get_test.go (about) 1 // Copyright 2012-2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package service_test 5 6 import ( 7 "bytes" 8 9 "github.com/juju/cmd" 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 goyaml "gopkg.in/yaml.v2" 13 14 "github.com/juju/juju/cmd/juju/service" 15 coretesting "github.com/juju/juju/testing" 16 ) 17 18 type GetSuite struct { 19 coretesting.FakeJujuXDGDataHomeSuite 20 fake *fakeServiceAPI 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": "Specifies title", 37 "type": "string", 38 "value": "Nearly There", 39 }, 40 "skill-level": map[string]interface{}{ 41 "description": "Specifies skill-level", 42 "value": 100, 43 "type": "int", 44 }, 45 "username": map[string]interface{}{ 46 "description": "Specifies username", 47 "type": "string", 48 "value": "admin001", 49 }, 50 "outlook": map[string]interface{}{ 51 "description": "Specifies outlook", 52 "type": "string", 53 "value": "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) SetUpTest(c *gc.C) { 64 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 65 s.fake = &fakeServiceAPI{serviceName: "dummy-service", charmName: "dummy", 66 values: map[string]interface{}{ 67 "title": "Nearly There", 68 "skill-level": 100, 69 "username": "admin001", 70 "outlook": "true", 71 }} 72 } 73 74 func (s *GetSuite) TestGetCommandInit(c *gc.C) { 75 // missing args 76 err := coretesting.InitCommand(service.NewGetCommandForTest(s.fake), []string{}) 77 c.Assert(err, gc.ErrorMatches, "no service name specified") 78 } 79 80 func (s *GetSuite) TestGetConfig(c *gc.C) { 81 for _, t := range getTests { 82 ctx := coretesting.Context(c) 83 code := cmd.Main(service.NewGetCommandForTest(s.fake), ctx, []string{t.service}) 84 c.Check(code, gc.Equals, 0) 85 c.Assert(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "") 86 // round trip via goyaml to avoid being sucked into a quagmire of 87 // map[interface{}]interface{} vs map[string]interface{}. This is 88 // also required if we add json support to this command. 89 buf, err := goyaml.Marshal(t.expected) 90 c.Assert(err, jc.ErrorIsNil) 91 expected := make(map[string]interface{}) 92 err = goyaml.Unmarshal(buf, &expected) 93 c.Assert(err, jc.ErrorIsNil) 94 95 actual := make(map[string]interface{}) 96 err = goyaml.Unmarshal(ctx.Stdout.(*bytes.Buffer).Bytes(), &actual) 97 c.Assert(err, jc.ErrorIsNil) 98 c.Assert(actual, gc.DeepEquals, expected) 99 } 100 }