func (s *BuildTestSuite) TestBuildSimpleOutputDir(c *C) { sourceDir := makeExampleSnapSourceDir(c, `name: hello version: 1.0.1 architectures: ["i386", "amd64"] integration: app: apparmor-profile: meta/hello.apparmor `) outputDir := filepath.Join(c.MkDir(), "output") snapOutput := filepath.Join(outputDir, "hello_1.0.1_multi.snap") resultSnap, err := snaptest.BuildSquashfsSnap(sourceDir, outputDir) // check that there is result _, err = os.Stat(resultSnap) c.Assert(err, IsNil) c.Assert(resultSnap, Equals, snapOutput) // check that the content looks sane output, err := exec.Command("unsquashfs", "-ll", resultSnap).CombinedOutput() c.Assert(err, IsNil) for _, needle := range []string{ "meta/snap.yaml", "bin/hello-world", "symlink -> bin/hello-world", } { expr := fmt.Sprintf(`(?ms).*%s.*`, regexp.QuoteMeta(needle)) c.Assert(string(output), Matches, expr) } }
func (s *BuildTestSuite) TestBuildFailsForUnknownType(c *C) { sourceDir := makeExampleSnapSourceDir(c, `name: hello version: 1.0.1 `) err := syscall.Mkfifo(filepath.Join(sourceDir, "fifo"), 0644) c.Assert(err, IsNil) _, err = snaptest.BuildSquashfsSnap(sourceDir, "") c.Assert(err, ErrorMatches, "cannot handle type of file .*") }
func main() { if len(os.Args) != 3 { fmt.Fprintf(os.Stderr, "snapbuild: expected sourceDir and targetDir\n") os.Exit(1) } snapPath, err := snaptest.BuildSquashfsSnap(os.Args[1], os.Args[2]) if err != nil { fmt.Fprintf(os.Stderr, "snapbuild: %v\n", err) os.Exit(1) } fmt.Fprintf(os.Stdout, "built: %s\n", snapPath) }
func (s *BuildTestSuite) TestBuildNoManifestFails(c *C) { sourceDir := makeExampleSnapSourceDir(c, "") c.Assert(os.Remove(filepath.Join(sourceDir, "meta", "snap.yaml")), IsNil) _, err := snaptest.BuildSquashfsSnap(sourceDir, "") c.Assert(err, NotNil) // XXX maybe make the error more explicit }