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

Side by Side Diff: state/apiserver/api_test.go

Issue 7444052: Add a CharmInfo API command.
Patch Set: Add a CharmInfo API command. Created 11 years 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
« no previous file with comments | « state/api/params/params.go ('k') | state/apiserver/apiserver.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package apiserver_test 1 package apiserver_test
2 2
3 import ( 3 import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 . "launchpad.net/gocheck" 7 . "launchpad.net/gocheck"
8 "launchpad.net/juju-core/juju/testing" 8 "launchpad.net/juju-core/juju/testing"
9 "launchpad.net/juju-core/rpc" 9 "launchpad.net/juju-core/rpc"
10 "launchpad.net/juju-core/state" 10 "launchpad.net/juju-core/state"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 op: opClientServiceGet, 77 op: opClientServiceGet,
78 allow: []string{"user-admin", "user-other"}, 78 allow: []string{"user-admin", "user-other"},
79 }, { 79 }, {
80 about: "Client.ServiceExpose", 80 about: "Client.ServiceExpose",
81 op: opClientServiceExpose, 81 op: opClientServiceExpose,
82 allow: []string{"user-admin", "user-other"}, 82 allow: []string{"user-admin", "user-other"},
83 }, { 83 }, {
84 about: "Client.ServiceUnexpose", 84 about: "Client.ServiceUnexpose",
85 op: opClientServiceUnexpose, 85 op: opClientServiceUnexpose,
86 allow: []string{"user-admin", "user-other"}, 86 allow: []string{"user-admin", "user-other"},
87 }, {
88 about: "Client.CharmInfo",
89 op: opClientCharmInfo,
90 allow: []string{"user-admin", "user-other"},
87 }, 91 },
88 } 92 }
89 93
90 // allowed returns the set of allowed entities given an allow list and a 94 // allowed returns the set of allowed entities given an allow list and a
91 // deny list. If an allow list is specified, only those entities are 95 // deny list. If an allow list is specified, only those entities are
92 // allowed; otherwise those in deny are disallowed. 96 // allowed; otherwise those in deny are disallowed.
93 func allowed(all, allow, deny []string) map[string]bool { 97 func allowed(all, allow, deny []string) map[string]bool {
94 p := make(map[string]bool) 98 p := make(map[string]bool)
95 if allow != nil { 99 if allow != nil {
96 for _, e := range allow { 100 for _, e := range allow {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 183 }
180 err = m.SetPassword("another password") 184 err = m.SetPassword("another password")
181 if err != nil { 185 if err != nil {
182 return func() {}, err 186 return func() {}, err
183 } 187 }
184 return func() { 188 return func() {
185 setDefaultPassword(c, m) 189 setDefaultPassword(c, m)
186 }, nil 190 }, nil
187 } 191 }
188 192
193 func opClientCharmInfo(c *C, st *api.State) (func(), error) {
194 info, err := st.Client().CharmInfo("local:series/wordpress-3")
195 if err != nil {
196 c.Check(info, IsNil)
197 return func() {}, err
198 }
199 c.Assert(err, IsNil)
200 c.Assert(info.URL, Equals, "local:series/wordpress-3")
201 c.Assert(info.Meta.Name, Equals, "wordpress")
202 c.Assert(info.Revision, Equals, 3)
203 return func() {}, nil
204 }
205
189 func opClientStatus(c *C, st *api.State) (func(), error) { 206 func opClientStatus(c *C, st *api.State) (func(), error) {
190 status, err := st.Client().Status() 207 status, err := st.Client().Status()
191 if err != nil { 208 if err != nil {
192 c.Check(status, IsNil) 209 c.Check(status, IsNil)
193 return func() {}, err 210 return func() {}, err
194 } 211 }
195 c.Assert(err, IsNil) 212 c.Assert(err, IsNil)
196 c.Assert(status, DeepEquals, scenarioStatus) 213 c.Assert(status, DeepEquals, scenarioStatus)
197 return func() {}, nil 214 return func() {}, nil
198 } 215 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 err = s.APIState.Client().ServiceSetYAML("dummy", "title: aaa\nusername: bbb") 495 err = s.APIState.Client().ServiceSetYAML("dummy", "title: aaa\nusername: bbb")
479 c.Assert(err, IsNil) 496 c.Assert(err, IsNil)
480 conf, err := dummy.Config() 497 conf, err := dummy.Config()
481 c.Assert(err, IsNil) 498 c.Assert(err, IsNil)
482 c.Assert(conf.Map(), DeepEquals, map[string]interface{}{ 499 c.Assert(conf.Map(), DeepEquals, map[string]interface{}{
483 "title": "aaa", 500 "title": "aaa",
484 "username": "bbb", 501 "username": "bbb",
485 }) 502 })
486 } 503 }
487 504
505 var clientCharmInfoTests = []struct {
506 about string
507 url string
508 err string
509 }{
510 {
511 about: "retrieves charm info",
512 url: "local:series/wordpress-3",
513 },
514 {
515 about: "invalid URL",
516 url: "not-valid",
517 err: `charm URL has invalid schema: "not-valid"`,
518 },
519 {
520 about: "unknown charm",
521 url: "cs:missing/one-1",
522 err: `charm "cs:missing/one-1" not found`,
523 },
524 }
525
526 func (s *suite) TestClientCharmInfo(c *C) {
527 // Use wordpress for tests so that we can compare Provides and Requires.
528 charm := s.AddTestingCharm(c, "wordpress")
529 for i, t := range clientCharmInfoTests {
530 c.Logf("test %d. %s", i, t.about)
531 info, err := s.APIState.Client().CharmInfo(t.url)
532 if t.err != "" {
533 c.Assert(err, ErrorMatches, t.err)
534 continue
535 }
536 c.Assert(err, IsNil)
537 expected := &api.CharmInfo{
538 Revision: charm.Revision(),
539 URL: charm.URL().String(),
540 Config: charm.Config(),
541 Meta: charm.Meta(),
542 }
543 c.Assert(info, DeepEquals, expected)
544 }
545 }
546
488 func (s *suite) TestClientEnvironmentInfo(c *C) { 547 func (s *suite) TestClientEnvironmentInfo(c *C) {
489 conf, _ := s.State.EnvironConfig() 548 conf, _ := s.State.EnvironConfig()
490 info, err := s.APIState.Client().EnvironmentInfo() 549 info, err := s.APIState.Client().EnvironmentInfo()
491 c.Assert(err, IsNil) 550 c.Assert(err, IsNil)
492 c.Assert(info.DefaultSeries, Equals, conf.DefaultSeries()) 551 c.Assert(info.DefaultSeries, Equals, conf.DefaultSeries())
493 c.Assert(info.ProviderType, Equals, conf.Type()) 552 c.Assert(info.ProviderType, Equals, conf.Type())
494 } 553 }
495 554
496 func (s *suite) TestMachineLogin(c *C) { 555 func (s *suite) TestMachineLogin(c *C) {
497 stm, err := s.State.AddMachine("series", state.JobHostUnits) 556 stm, err := s.State.AddMachine("series", state.JobHostUnits)
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 _, info, err := s.APIConn.Environ.StateInfo() 987 _, info, err := s.APIConn.Environ.StateInfo()
929 c.Assert(err, IsNil) 988 c.Assert(err, IsNil)
930 info.EntityName = entityName 989 info.EntityName = entityName
931 info.Password = fmt.Sprintf("%s password", entityName) 990 info.Password = fmt.Sprintf("%s password", entityName)
932 c.Logf("opening state; entity %q; password %q", info.EntityName, info.Pa ssword) 991 c.Logf("opening state; entity %q; password %q", info.EntityName, info.Pa ssword)
933 st, err := api.Open(info) 992 st, err := api.Open(info)
934 c.Assert(err, IsNil) 993 c.Assert(err, IsNil)
935 c.Assert(st, NotNil) 994 c.Assert(st, NotNil)
936 return st 995 return st
937 } 996 }
OLDNEW
« no previous file with comments | « state/api/params/params.go ('k') | state/apiserver/apiserver.go » ('j') | no next file with comments »

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