Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 package glance_test | |
2 | |
3 import ( | |
4 "flag" | |
5 . "launchpad.net/gocheck" | |
6 "launchpad.net/goose/client" | |
7 "launchpad.net/goose/glance" | |
8 "launchpad.net/goose/identity" | |
9 "testing" | |
10 ) | |
11 | |
12 func Test(t *testing.T) { TestingT(t) } | |
13 | |
14 var live = flag.Bool("live", false, "Include live OpenStack (Canonistack) tests" ) | |
15 | |
16 type GlanceSuite struct { | |
17 glance glance.Glance | |
18 } | |
19 | |
20 func (s *GlanceSuite) SetUpSuite(c *C) { | |
21 if !*live { | |
dave_cheney.net
2012/11/28 01:32:51
nice
| |
22 c.Skip("-live not provided") | |
23 } | |
24 | |
25 cred, err := identity.CompleteCredentialsFromEnv() | |
26 if err != nil { | |
27 c.Fatalf("Error setting up test suite: %s", err.Error()) | |
dave_cheney.net
2012/11/28 01:32:51
c.Fatalf("Error...: %v", err)
errors know how to
wallyworld
2012/11/29 02:34:37
Done.
| |
28 } | |
29 client := client.NewOpenStackClient(cred, identity.AuthUserPass) | |
30 err = client.Authenticate() | |
31 if err != nil { | |
32 c.Fatalf("OpenStack authentication failed for %s", cred.User) | |
33 } | |
34 c.Logf("client authenticated") | |
35 s.glance = glance.NewClient(client) | |
dimitern
2012/11/28 15:46:28
glance.New() instead
wallyworld
2012/11/29 02:34:37
Done.
| |
36 } | |
37 | |
38 var suite = Suite(&GlanceSuite{}) | |
39 | |
40 func (s *GlanceSuite) TestListImages(c *C) { | |
41 images, err := s.glance.ListImages() | |
42 c.Assert(err, IsNil) | |
dave_cheney.net
2012/11/28 01:32:51
c.Assert(len(images), NotEqual, 0) maybe
wallyworld
2012/11/29 02:34:37
Done.
| |
43 if len(images) < 1 { | |
dave_cheney.net
2012/11/28 01:32:51
c.Assert(images, Not(HasLen), 0)
wallyworld
2012/11/29 02:34:37
Done.
| |
44 c.Fatalf("no images to list (expected at least 1)") | |
45 } | |
46 for _, ir := range images { | |
47 c.Assert(ir.Id, Not(Equals), "") | |
48 c.Assert(ir.Name, Not(Equals), "") | |
49 for _, l := range ir.Links { | |
50 c.Assert(l.Href, Matches, "https?://.*") | |
51 c.Assert(l.Rel, Matches, "self|bookmark|alternate") | |
52 } | |
53 } | |
54 } | |
55 | |
56 func (s *GlanceSuite) TestListImagesDetail(c *C) { | |
57 images, err := s.glance.ListImagesDetail() | |
58 c.Assert(err, IsNil) | |
59 if len(images) < 1 { | |
dave_cheney.net
2012/11/28 01:32:51
ditto
wallyworld
2012/11/29 02:34:37
Done.
| |
60 c.Fatalf("no images to list (expected at least 1)") | |
61 } | |
62 for _, ir := range images { | |
63 c.Assert(ir.Created, Matches, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{ 2}.*`) | |
64 c.Assert(ir.Updated, Matches, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{ 2}.*`) | |
65 c.Assert(ir.Id, Not(Equals), "") | |
66 c.Assert(ir.Status, Not(Equals), "") | |
67 c.Assert(ir.Name, Not(Equals), "") | |
68 for _, l := range ir.Links { | |
69 c.Assert(l.Href, Matches, "https?://.*") | |
70 c.Assert(l.Rel, Matches, "self|bookmark|alternate") | |
71 } | |
72 m := ir.Metadata | |
73 c.Assert(m.Architecture, Matches, "i386|x86_64|") | |
74 c.Assert(m.State, Matches, "active|available|") | |
75 } | |
76 } | |
77 | |
78 func (s *GlanceSuite) TestGetImageDetail(c *C) { | |
79 images, err := s.glance.ListImagesDetail() | |
80 c.Assert(err, IsNil) | |
81 firstImage := images[0] | |
82 ir, err := s.glance.GetImageDetail(firstImage.Id) | |
83 c.Assert(err, IsNil) | |
84 c.Assert(ir.Created, Matches, firstImage.Created) | |
85 c.Assert(ir.Updated, Matches, firstImage.Updated) | |
86 c.Assert(ir.Name, Equals, firstImage.Name) | |
87 c.Assert(ir.Status, Equals, firstImage.Status) | |
88 } | |
OLD | NEW |