~fwereade/pyjuju/go-log-type

« back to all changes in this revision

Viewing changes to charm/charm_test.go

  • Committer: Gustavo Niemeyer
  • Date: 2012-02-10 16:33:57 UTC
  • mfrom: (51.2.11 go-charm-symlinks)
  • Revision ID: gustavo@niemeyer.net-20120210163357-lb2jk8ani7if2h5h
charm: fix symlink and file mode when bundling/expanding

R=fwereade, rog
CC=
https://codereview.appspot.com/5647047

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
var _ = Suite(&S{})
22
22
 
 
23
func init() {
 
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
 
23
42
func checkDummy(c *C, f charm.Charm, path string) {
24
43
        c.Assert(f.Revision(), Equals, 1)
25
44
        c.Assert(f.Meta().Name, Equals, "dummy")
27
46
        switch f := f.(type) {
28
47
        case *charm.Bundle:
29
48
                c.Assert(f.Path, Equals, path)
 
49
 
30
50
        case *charm.Dir:
31
51
                c.Assert(f.Path, Equals, path)
32
 
                _, err := os.Stat(filepath.Join(path, "src", "hello.c"))
33
 
                c.Assert(err, IsNil)
 
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")
34
73
        }
35
74
}
36
75