Merge lp:~mvo/snappy/snappy-snapfs-tests into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt
Status: Merged
Approved by: John Lenton
Approved revision: 747
Merged at revision: 751
Proposed branch: lp:~mvo/snappy/snappy-snapfs-tests
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~mvo/snappy/snappy-snapfs-chdir
Diff against target: 109 lines (+51/-6) (has conflicts)
1 file modified
pkg/snapfs/pkg_test.go (+51/-6)
Text conflict in snappy/snapp.go
To merge this branch: bzr merge lp:~mvo/snappy/snappy-snapfs-tests
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+273786@code.launchpad.net

Commit message

Improve tests for pkg/snapfs

Description of the change

Improve tests for pkg/snapfs

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkg/snapfs/pkg_test.go'
2--- pkg/snapfs/pkg_test.go 2015-10-08 06:48:13 +0000
3+++ pkg/snapfs/pkg_test.go 2015-10-08 06:48:14 +0000
4@@ -27,6 +27,8 @@
5 "strings"
6 "testing"
7
8+ "launchpad.net/snappy/helpers"
9+
10 . "gopkg.in/check.v1"
11 )
12
13@@ -53,7 +55,7 @@
14 c.Assert(err, IsNil)
15
16 // some data
17- err = ioutil.WriteFile(filepath.Join(tmp, "data"), []byte(data), 0644)
18+ err = ioutil.WriteFile(filepath.Join(tmp, "data.bin"), []byte(data), 0644)
19 c.Assert(err, IsNil)
20
21 // build it
22@@ -65,6 +67,23 @@
23 return snap
24 }
25
26+func (s *SquashfsTestSuite) SetUpTest(c *C) {
27+ err := os.Chdir(c.MkDir())
28+ c.Assert(err, IsNil)
29+}
30+
31+func (s *SquashfsTestSuite) TestName(c *C) {
32+ snap := New("/path/to/foo.snap")
33+ c.Assert(snap.Name(), Equals, "foo.snap")
34+}
35+
36+// FIXME: stub that needs to be fleshed out once assertions land
37+// and we actually do verify
38+func (s *SquashfsTestSuite) TestVerify(c *C) {
39+ err := New("foo").Verify(false)
40+ c.Assert(err, IsNil)
41+}
42+
43 func (s *SquashfsTestSuite) TestReadFile(c *C) {
44 snap := makeSnap(c, "name: foo", "")
45
46@@ -73,24 +92,50 @@
47 c.Assert(string(content), Equals, "name: foo")
48 }
49
50-func (s *SquashfsTestSuite) TestUnpack(c *C) {
51+func (s *SquashfsTestSuite) TestCopyBlob(c *C) {
52+ snap := makeSnap(c, "name: foo", "")
53+ dst := filepath.Join(c.MkDir(), "blob.snap")
54+
55+ err := snap.CopyBlob(dst)
56+ c.Assert(err, IsNil)
57+ c.Assert(helpers.FilesAreEqual(snap.Name(), dst), Equals, true)
58+}
59+
60+func (s *SquashfsTestSuite) TestUnpackGlob(c *C) {
61 data := "some random data"
62 snap := makeSnap(c, "", data)
63
64 outputDir := c.MkDir()
65- err := snap.Unpack("data", outputDir)
66+ err := snap.Unpack("data*", outputDir)
67 c.Assert(err, IsNil)
68
69- content, err := ioutil.ReadFile(filepath.Join(outputDir, "data"))
70+ // this is the file we expect
71+ content, err := ioutil.ReadFile(filepath.Join(outputDir, "data.bin"))
72 c.Assert(err, IsNil)
73 c.Assert(string(content), Equals, data)
74+
75+ // ensure glob was honored
76+ c.Assert(helpers.FileExists(filepath.Join(outputDir, "meta/package.yaml")), Equals, false)
77+}
78+
79+func (s *SquashfsTestSuite) TestUnpackMeta(c *C) {
80+ snap := makeSnap(c, "", "random-data")
81+
82+ outputDir := c.MkDir()
83+ err := snap.UnpackMeta(outputDir)
84+ c.Assert(err, IsNil)
85+
86+ // we got the meta/ stuff
87+ c.Assert(helpers.FileExists(filepath.Join(outputDir, "meta/package.yaml")), Equals, true)
88+ // ... but not the data
89+ c.Assert(helpers.FileExists(filepath.Join(outputDir, "data.bin")), Equals, false)
90 }
91
92 func (s *SquashfsTestSuite) TestBuild(c *C) {
93 buildDir := c.MkDir()
94 err := os.MkdirAll(filepath.Join(buildDir, "/random/dir"), 0755)
95 c.Assert(err, IsNil)
96- err = ioutil.WriteFile(filepath.Join(buildDir, "data"), []byte("data"), 0644)
97+ err = ioutil.WriteFile(filepath.Join(buildDir, "data.bin"), []byte("data"), 0644)
98 c.Assert(err, IsNil)
99
100 snap := New(filepath.Join(c.MkDir(), "foo.snap"))
101@@ -105,7 +150,7 @@
102 split := strings.Split(string(outputWithHeader), "\n")
103 output := strings.Join(split[3:], "\n")
104 c.Assert(string(output), Equals, `squashfs-root
105-squashfs-root/data
106+squashfs-root/data.bin
107 squashfs-root/random
108 squashfs-root/random/dir
109 `)

Subscribers

People subscribed via source and target branches