func (s *imageSuite) TestDownloadUnpackGadget(c *C) { files := [][]string{ {"subdir/canary.txt", "I'm a canary"}, } s.downloadedSnaps["pc"] = snaptest.MakeTestSnapWithFiles(c, packageGadget, files) s.storeSnapInfo["pc"] = infoFromSnapYaml(c, packageGadget, snap.R(99)) gadgetUnpackDir := filepath.Join(c.MkDir(), "gadget-unpack-dir") opts := &image.Options{ GadgetUnpackDir: gadgetUnpackDir, } local, err := image.LocalSnaps(opts) c.Assert(err, IsNil) err = image.DownloadUnpackGadget(s, s.model, opts, local) c.Assert(err, IsNil) // verify the right data got unpacked for _, t := range []struct{ file, content string }{ {"meta/snap.yaml", packageGadget}, {files[0][0], files[0][1]}, } { fn := filepath.Join(gadgetUnpackDir, t.file) content, err := ioutil.ReadFile(fn) c.Assert(err, IsNil) c.Check(content, DeepEquals, []byte(t.content)) } }
func (s *imageSuite) TestMissingGadgetUnpackDir(c *C) { err := image.DownloadUnpackGadget(s, s.model, &image.Options{}, nil) c.Assert(err, ErrorMatches, `cannot create gadget unpack dir "": mkdir : no such file or directory`) }