Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1014)

Side by Side Diff: state/apiserver/client/client_test.go

Issue 13522043: charm: allow empty string options
Patch Set: charm: allow empty string options Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package client_test 4 package client_test
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 gc "launchpad.net/gocheck" 8 gc "launchpad.net/gocheck"
9 "launchpad.net/juju-core/charm" 9 "launchpad.net/juju-core/charm"
10 "launchpad.net/juju-core/constraints" 10 "launchpad.net/juju-core/constraints"
(...skipping 12 matching lines...) Expand all
23 23
24 var _ = gc.Suite(&clientSuite{}) 24 var _ = gc.Suite(&clientSuite{})
25 25
26 func (s *clientSuite) TestClientStatus(c *gc.C) { 26 func (s *clientSuite) TestClientStatus(c *gc.C) {
27 s.setUpScenario(c) 27 s.setUpScenario(c)
28 status, err := s.APIState.Client().Status() 28 status, err := s.APIState.Client().Status()
29 c.Assert(err, gc.IsNil) 29 c.Assert(err, gc.IsNil)
30 c.Assert(status, gc.DeepEquals, scenarioStatus) 30 c.Assert(status, gc.DeepEquals, scenarioStatus)
31 } 31 }
32 32
33 func (s *clientSuite) TestCompatibleSettingsParsing(c *gc.C) {
34 // Test the exported settings parsing in a compatible way.
35 _, err := s.State.AddService("dummy", s.AddTestingCharm(c, "dummy"))
36 c.Assert(err, gc.IsNil)
37 service, err := s.State.Service("dummy")
38 c.Assert(err, gc.IsNil)
39 ch, _, err := service.Charm()
40 c.Assert(err, gc.IsNil)
41 c.Assert(ch.URL().String(), gc.Equals, "local:series/dummy-1")
42
43 // Empty string will be returned as nil.
44 options := map[string]string{
45 "title": "foobar",
46 "username": "",
47 }
48 settings, err := client.ParseSettingsCompatible(ch, options)
49 c.Assert(err, gc.IsNil)
50 c.Assert(settings, gc.DeepEquals, charm.Settings{
51 "title": "foobar",
52 "username": nil,
53 })
54
55 // Illegal settings lead to an error.
56 options = map[string]string{
57 "yummy": "didgeridoo",
58 }
59 settings, err = client.ParseSettingsCompatible(ch, options)
60 c.Assert(err, gc.ErrorMatches, `unknown option "yummy"`)
61 }
62
33 func (s *clientSuite) TestClientServerSet(c *gc.C) { 63 func (s *clientSuite) TestClientServerSet(c *gc.C) {
34 dummy, err := s.State.AddService("dummy", s.AddTestingCharm(c, "dummy")) 64 dummy, err := s.State.AddService("dummy", s.AddTestingCharm(c, "dummy"))
35 c.Assert(err, gc.IsNil) 65 c.Assert(err, gc.IsNil)
66
36 err = s.APIState.Client().ServiceSet("dummy", map[string]string{ 67 err = s.APIState.Client().ServiceSet("dummy", map[string]string{
37 » » "title": "xxx", 68 » » "title": "foobar",
38 » » "username": "yyy", 69 » » "username": "user name",
39 }) 70 })
40 c.Assert(err, gc.IsNil) 71 c.Assert(err, gc.IsNil)
41 settings, err := dummy.ConfigSettings() 72 settings, err := dummy.ConfigSettings()
42 c.Assert(err, gc.IsNil) 73 c.Assert(err, gc.IsNil)
43 c.Assert(settings, gc.DeepEquals, charm.Settings{ 74 c.Assert(settings, gc.DeepEquals, charm.Settings{
44 » » "title": "xxx", 75 » » "title": "foobar",
45 » » "username": "yyy", 76 » » "username": "user name",
77 » })
78
79 » err = s.APIState.Client().ServiceSet("dummy", map[string]string{
80 » » "title": "barfoo",
81 » » "username": "",
82 » })
83 » c.Assert(err, gc.IsNil)
84 » settings, err = dummy.ConfigSettings()
85 » c.Assert(err, gc.IsNil)
86 » c.Assert(settings, gc.DeepEquals, charm.Settings{
87 » » "title": "barfoo",
46 }) 88 })
47 } 89 }
48 90
49 func (s *clientSuite) TestClientServiceSetYAML(c *gc.C) { 91 func (s *clientSuite) TestClientServiceSetYAML(c *gc.C) {
50 dummy, err := s.State.AddService("dummy", s.AddTestingCharm(c, "dummy")) 92 dummy, err := s.State.AddService("dummy", s.AddTestingCharm(c, "dummy"))
51 c.Assert(err, gc.IsNil) 93 c.Assert(err, gc.IsNil)
52 » err = s.APIState.Client().ServiceSetYAML("dummy", "dummy:\n title: aaa\ n username: bbb") 94
95 » err = s.APIState.Client().ServiceSetYAML("dummy", "dummy:\n title: foob ar\n username: user name\n")
53 c.Assert(err, gc.IsNil) 96 c.Assert(err, gc.IsNil)
54 settings, err := dummy.ConfigSettings() 97 settings, err := dummy.ConfigSettings()
55 c.Assert(err, gc.IsNil) 98 c.Assert(err, gc.IsNil)
56 c.Assert(settings, gc.DeepEquals, charm.Settings{ 99 c.Assert(settings, gc.DeepEquals, charm.Settings{
57 » » "title": "aaa", 100 » » "title": "foobar",
58 » » "username": "bbb", 101 » » "username": "user name",
102 » })
103
104 » err = s.APIState.Client().ServiceSetYAML("dummy", "dummy:\n title: barf oo\n username: \n")
105 » c.Assert(err, gc.IsNil)
106 » settings, err = dummy.ConfigSettings()
107 » c.Assert(err, gc.IsNil)
108 » c.Assert(settings, gc.DeepEquals, charm.Settings{
109 » » "title": "barfoo",
59 }) 110 })
60 } 111 }
61 112
62 var clientAddServiceUnitsTests = []struct { 113 var clientAddServiceUnitsTests = []struct {
63 about string 114 about string
64 service string // if not set, defaults to 'dummy' 115 service string // if not set, defaults to 'dummy'
65 expected []string 116 expected []string
66 to string 117 to string
67 err string 118 err string
68 }{ 119 }{
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 InstanceId: "i-0", 867 InstanceId: "i-0",
817 Status: params.StatusPending, 868 Status: params.StatusPending,
818 }, 869 },
819 }}) { 870 }}) {
820 c.Logf("got:") 871 c.Logf("got:")
821 for _, d := range deltas { 872 for _, d := range deltas {
822 c.Logf("%#v\n", d.Entity) 873 c.Logf("%#v\n", d.Entity)
823 } 874 }
824 } 875 }
825 } 876 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b