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

Side by Side Diff: charm/charm_test.go

Issue 5845051: Make test charm repository available from testing package
Patch Set: Make test charm repository available from testing package Created 11 years, 11 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 package charm_test 1 package charm_test
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "io" 5 "io"
6 "io/ioutil" 6 "io/ioutil"
7 . "launchpad.net/gocheck" 7 . "launchpad.net/gocheck"
8 "launchpad.net/goyaml" 8 "launchpad.net/goyaml"
9 "launchpad.net/juju/go/charm" 9 "launchpad.net/juju/go/charm"
10 "os"
11 "path/filepath"
12 "testing" 10 "testing"
13 ) 11 )
14 12
15 func Test(t *testing.T) { 13 func Test(t *testing.T) {
16 TestingT(t) 14 TestingT(t)
17 } 15 }
18 16
19 type S struct{} 17 type S struct{}
20 18
21 var _ = Suite(&S{}) 19 var _ = Suite(&S{})
22 20
23 func init() { 21 func (s *S) SetUpSuite(c *C) {}
24 » // Bazaar can't hold subtle mode differences, so we enforce
25 » // them here to run more interesting checks below.
26 » modes := []struct {
27 » » path string
28 » » mode os.FileMode
29 » }{
30 » » {"hooks/install", 0751},
31 » » {"empty", 0750},
32 » » {"src/hello.c", 0614},
33 » }
34 » for _, m := range modes {
35 » » err := os.Chmod(filepath.Join(repoDir("dummy"), m.path), m.mode)
36 » » if err != nil {
37 » » » panic(err)
38 » » }
39 » }
40 }
41 22
42 func checkDummy(c *C, f charm.Charm, path string) { 23 func checkDummy(c *C, f charm.Charm, path string) {
43 c.Assert(f.Revision(), Equals, 1) 24 c.Assert(f.Revision(), Equals, 1)
44 c.Assert(f.Meta().Name, Equals, "dummy") 25 c.Assert(f.Meta().Name, Equals, "dummy")
45 c.Assert(f.Config().Options["title"].Default, Equals, "My Title") 26 c.Assert(f.Config().Options["title"].Default, Equals, "My Title")
46 switch f := f.(type) { 27 switch f := f.(type) {
47 case *charm.Bundle: 28 case *charm.Bundle:
48 c.Assert(f.Path, Equals, path) 29 c.Assert(f.Path, Equals, path)
49 30
50 case *charm.Dir: 31 case *charm.Dir:
51 c.Assert(f.Path, Equals, path) 32 c.Assert(f.Path, Equals, path)
52 if path == repoDir("dummy") {
53 break // Don't test original Bazaar content.
54 }
55
56 info, err := os.Stat(filepath.Join(path, "src", "hello.c"))
57 c.Assert(err, IsNil)
58 c.Assert(info.Mode()&0777, Equals, os.FileMode(0644))
59 c.Assert(info.Mode()&os.ModeType, Equals, os.FileMode(0))
60
61 info, err = os.Stat(filepath.Join(path, "hooks", "install"))
62 c.Assert(err, IsNil)
63 c.Assert(info.Mode()&0777, Equals, os.FileMode(0755))
64 c.Assert(info.Mode()&os.ModeType, Equals, os.FileMode(0))
65
66 info, err = os.Stat(filepath.Join(path, "empty"))
67 c.Assert(err, IsNil)
68 c.Assert(info.Mode()&0777, Equals, os.FileMode(0755))
69
70 target, err := os.Readlink(filepath.Join(path, "hooks", "symlink "))
71 c.Assert(err, IsNil)
72 c.Assert(target, Equals, "../target")
73 } 33 }
74 } 34 }
75 35
76 type YamlHacker map[interface{}]interface{} 36 type YamlHacker map[interface{}]interface{}
77 37
78 func ReadYaml(r io.Reader) YamlHacker { 38 func ReadYaml(r io.Reader) YamlHacker {
79 data, err := ioutil.ReadAll(r) 39 data, err := ioutil.ReadAll(r)
80 if err != nil { 40 if err != nil {
81 panic(err) 41 panic(err)
82 } 42 }
83 m := make(map[interface{}]interface{}) 43 m := make(map[interface{}]interface{})
84 err = goyaml.Unmarshal(data, m) 44 err = goyaml.Unmarshal(data, m)
85 if err != nil { 45 if err != nil {
86 panic(err) 46 panic(err)
87 } 47 }
88 return YamlHacker(m) 48 return YamlHacker(m)
89 } 49 }
90 50
91 func (yh YamlHacker) Reader() io.Reader { 51 func (yh YamlHacker) Reader() io.Reader {
92 data, err := goyaml.Marshal(yh) 52 data, err := goyaml.Marshal(yh)
93 if err != nil { 53 if err != nil {
94 panic(err) 54 panic(err)
95 } 55 }
96 return bytes.NewBuffer(data) 56 return bytes.NewBuffer(data)
97 } 57 }
OLDNEW
« charm/bundle_test.go ('K') | « charm/bundle_test.go ('k') | charm/config_test.go » ('j') | no next file with comments »

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