func makeSnap(c *C, manifest, data string) *Snap { tmp := c.MkDir() err := os.MkdirAll(filepath.Join(tmp, "meta"), 0755) // our regular snap.yaml err = ioutil.WriteFile(filepath.Join(tmp, "meta", "snap.yaml"), []byte(manifest), 0644) c.Assert(err, IsNil) // some data err = ioutil.WriteFile(filepath.Join(tmp, "data.bin"), []byte(data), 0644) c.Assert(err, IsNil) // build it cur, _ := os.Getwd() snap := New(filepath.Join(cur, "foo.snap")) err = snap.Build(tmp) c.Assert(err, IsNil) return snap }
func (s *SquashfsTestSuite) TestBuild(c *C) { buildDir := c.MkDir() err := os.MkdirAll(filepath.Join(buildDir, "/random/dir"), 0755) c.Assert(err, IsNil) err = ioutil.WriteFile(filepath.Join(buildDir, "data.bin"), []byte("data"), 0644) c.Assert(err, IsNil) snap := New(filepath.Join(c.MkDir(), "foo.snap")) err = snap.Build(buildDir) c.Assert(err, IsNil) // unsquashfs writes a funny header like: // "Parallel unsquashfs: Using 1 processor" // "1 inodes (1 blocks) to write" outputWithHeader, err := exec.Command("unsquashfs", "-n", "-l", snap.path).Output() c.Assert(err, IsNil) split := strings.Split(string(outputWithHeader), "\n") output := strings.Join(split[3:], "\n") c.Assert(string(output), Equals, `squashfs-root squashfs-root/data.bin squashfs-root/random squashfs-root/random/dir `) }