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
=== modified file 'pkg/snapfs/pkg_test.go'
--- pkg/snapfs/pkg_test.go 2015-10-08 06:48:13 +0000
+++ pkg/snapfs/pkg_test.go 2015-10-08 06:48:14 +0000
@@ -27,6 +27,8 @@
27 "strings"27 "strings"
28 "testing"28 "testing"
2929
30 "launchpad.net/snappy/helpers"
31
30 . "gopkg.in/check.v1"32 . "gopkg.in/check.v1"
31)33)
3234
@@ -53,7 +55,7 @@
53 c.Assert(err, IsNil)55 c.Assert(err, IsNil)
5456
55 // some data57 // some data
56 err = ioutil.WriteFile(filepath.Join(tmp, "data"), []byte(data), 0644)58 err = ioutil.WriteFile(filepath.Join(tmp, "data.bin"), []byte(data), 0644)
57 c.Assert(err, IsNil)59 c.Assert(err, IsNil)
5860
59 // build it61 // build it
@@ -65,6 +67,23 @@
65 return snap67 return snap
66}68}
6769
70func (s *SquashfsTestSuite) SetUpTest(c *C) {
71 err := os.Chdir(c.MkDir())
72 c.Assert(err, IsNil)
73}
74
75func (s *SquashfsTestSuite) TestName(c *C) {
76 snap := New("/path/to/foo.snap")
77 c.Assert(snap.Name(), Equals, "foo.snap")
78}
79
80// FIXME: stub that needs to be fleshed out once assertions land
81// and we actually do verify
82func (s *SquashfsTestSuite) TestVerify(c *C) {
83 err := New("foo").Verify(false)
84 c.Assert(err, IsNil)
85}
86
68func (s *SquashfsTestSuite) TestReadFile(c *C) {87func (s *SquashfsTestSuite) TestReadFile(c *C) {
69 snap := makeSnap(c, "name: foo", "")88 snap := makeSnap(c, "name: foo", "")
7089
@@ -73,24 +92,50 @@
73 c.Assert(string(content), Equals, "name: foo")92 c.Assert(string(content), Equals, "name: foo")
74}93}
7594
76func (s *SquashfsTestSuite) TestUnpack(c *C) {95func (s *SquashfsTestSuite) TestCopyBlob(c *C) {
96 snap := makeSnap(c, "name: foo", "")
97 dst := filepath.Join(c.MkDir(), "blob.snap")
98
99 err := snap.CopyBlob(dst)
100 c.Assert(err, IsNil)
101 c.Assert(helpers.FilesAreEqual(snap.Name(), dst), Equals, true)
102}
103
104func (s *SquashfsTestSuite) TestUnpackGlob(c *C) {
77 data := "some random data"105 data := "some random data"
78 snap := makeSnap(c, "", data)106 snap := makeSnap(c, "", data)
79107
80 outputDir := c.MkDir()108 outputDir := c.MkDir()
81 err := snap.Unpack("data", outputDir)109 err := snap.Unpack("data*", outputDir)
82 c.Assert(err, IsNil)110 c.Assert(err, IsNil)
83111
84 content, err := ioutil.ReadFile(filepath.Join(outputDir, "data"))112 // this is the file we expect
113 content, err := ioutil.ReadFile(filepath.Join(outputDir, "data.bin"))
85 c.Assert(err, IsNil)114 c.Assert(err, IsNil)
86 c.Assert(string(content), Equals, data)115 c.Assert(string(content), Equals, data)
116
117 // ensure glob was honored
118 c.Assert(helpers.FileExists(filepath.Join(outputDir, "meta/package.yaml")), Equals, false)
119}
120
121func (s *SquashfsTestSuite) TestUnpackMeta(c *C) {
122 snap := makeSnap(c, "", "random-data")
123
124 outputDir := c.MkDir()
125 err := snap.UnpackMeta(outputDir)
126 c.Assert(err, IsNil)
127
128 // we got the meta/ stuff
129 c.Assert(helpers.FileExists(filepath.Join(outputDir, "meta/package.yaml")), Equals, true)
130 // ... but not the data
131 c.Assert(helpers.FileExists(filepath.Join(outputDir, "data.bin")), Equals, false)
87}132}
88133
89func (s *SquashfsTestSuite) TestBuild(c *C) {134func (s *SquashfsTestSuite) TestBuild(c *C) {
90 buildDir := c.MkDir()135 buildDir := c.MkDir()
91 err := os.MkdirAll(filepath.Join(buildDir, "/random/dir"), 0755)136 err := os.MkdirAll(filepath.Join(buildDir, "/random/dir"), 0755)
92 c.Assert(err, IsNil)137 c.Assert(err, IsNil)
93 err = ioutil.WriteFile(filepath.Join(buildDir, "data"), []byte("data"), 0644)138 err = ioutil.WriteFile(filepath.Join(buildDir, "data.bin"), []byte("data"), 0644)
94 c.Assert(err, IsNil)139 c.Assert(err, IsNil)
95140
96 snap := New(filepath.Join(c.MkDir(), "foo.snap"))141 snap := New(filepath.Join(c.MkDir(), "foo.snap"))
@@ -105,7 +150,7 @@
105 split := strings.Split(string(outputWithHeader), "\n")150 split := strings.Split(string(outputWithHeader), "\n")
106 output := strings.Join(split[3:], "\n")151 output := strings.Join(split[3:], "\n")
107 c.Assert(string(output), Equals, `squashfs-root152 c.Assert(string(output), Equals, `squashfs-root
108squashfs-root/data153squashfs-root/data.bin
109squashfs-root/random154squashfs-root/random
110squashfs-root/random/dir155squashfs-root/random/dir
111`)156`)

Subscribers

People subscribed via source and target branches