func (s *BuildTestSuite) TestCopyCopies(c *C) { sourceDir := makeExampleSnapSourceDir(c, "name: hello") // actually this'll be on /tmp so it'll be a link target := c.MkDir() c.Assert(snaptest.CopyToBuildDir(sourceDir, target), IsNil) out, err := exec.Command("diff", "-qrN", sourceDir, target).Output() c.Check(err, IsNil) c.Check(out, DeepEquals, []byte{}) }
func (s *BuildTestSuite) TestCopyExcludesBackups(c *C) { sourceDir := makeExampleSnapSourceDir(c, "name: hello") target := c.MkDir() // add a backup file c.Assert(ioutil.WriteFile(filepath.Join(sourceDir, "foo~"), []byte("hi"), 0755), IsNil) c.Assert(snaptest.CopyToBuildDir(sourceDir, target), IsNil) cmd := exec.Command("diff", "-qr", sourceDir, target) cmd.Env = append(cmd.Env, "LANG=C") out, err := cmd.Output() c.Check(err, NotNil) c.Check(string(out), Matches, `(?m)Only in \S+: foo~`) }
func (s *BuildTestSuite) TestCopyExcludesWholeDirs(c *C) { sourceDir := makeExampleSnapSourceDir(c, "name: hello") target := c.MkDir() // add a file inside a skipped dir c.Assert(os.Mkdir(filepath.Join(sourceDir, ".bzr"), 0755), IsNil) c.Assert(ioutil.WriteFile(filepath.Join(sourceDir, ".bzr", "foo"), []byte("hi"), 0755), IsNil) c.Assert(snaptest.CopyToBuildDir(sourceDir, target), IsNil) out, _ := exec.Command("find", sourceDir).Output() cmd := exec.Command("diff", "-qr", sourceDir, target) cmd.Env = append(cmd.Env, "LANG=C") out, err := cmd.Output() c.Check(err, NotNil) c.Check(string(out), Matches, `(?m)Only in \S+: \.bzr`) }
func (s *BuildTestSuite) TestCopyExcludesTopLevelDEBIAN(c *C) { sourceDir := makeExampleSnapSourceDir(c, "name: hello") target := c.MkDir() // add a toplevel DEBIAN c.Assert(os.MkdirAll(filepath.Join(sourceDir, "DEBIAN", "foo"), 0755), IsNil) // and a non-toplevel DEBIAN c.Assert(os.MkdirAll(filepath.Join(sourceDir, "bar", "DEBIAN", "baz"), 0755), IsNil) c.Assert(snaptest.CopyToBuildDir(sourceDir, target), IsNil) cmd := exec.Command("diff", "-qr", sourceDir, target) cmd.Env = append(cmd.Env, "LANG=C") out, err := cmd.Output() c.Check(err, NotNil) c.Check(string(out), Matches, `(?m)Only in \S+: DEBIAN`) // but *only one* DEBIAN is skipped c.Check(strings.Count(string(out), "Only in"), Equals, 1) }
func (s *BuildTestSuite) TestCopyActuallyCopies(c *C) { sourceDir := makeExampleSnapSourceDir(c, "name: hello") // hoping to get the non-linking behaviour via /dev/shm target, err := ioutil.TempDir("/dev/shm", "copy") // sbuild environments won't allow writing to /dev/shm, so its // ok to skip there if os.IsPermission(err) { c.Skip("/dev/shm is not writable for us") } c.Assert(err, IsNil) c.Assert(snaptest.CopyToBuildDir(sourceDir, target), IsNil) out, err := exec.Command("diff", "-qrN", sourceDir, target).Output() c.Check(err, IsNil) c.Check(out, DeepEquals, []byte{}) }