diff --git a/internal/testutil/pkgdata.go b/internal/testutil/pkgdata.go index 682b1ea9..ff42f9fc 100644 --- a/internal/testutil/pkgdata.go +++ b/internal/testutil/pkgdata.go @@ -277,3 +277,35 @@ func MustMakeDeb(entries []TarEntry) []byte { } return data } + +func Reg(mode int64, path, content string) TarEntry { + return TarEntry{ + Header: tar.Header{ + Typeflag: tar.TypeReg, + Name: path, + Mode: mode, + }, + Content: []byte(content), + } +} + +func Dir(mode int64, path string) TarEntry { + return TarEntry{ + Header: tar.Header{ + Typeflag: tar.TypeDir, + Name: path, + Mode: mode, + }, + } +} + +func Lnk(mode int64, path, target string) TarEntry { + return TarEntry{ + Header: tar.Header{ + Typeflag: tar.TypeSymlink, + Name: path, + Mode: mode, + Linkname: target, + }, + } +} diff --git a/internal/testutil/pkgdata_test.go b/internal/testutil/pkgdata_test.go index 30136c3d..fb38b24a 100644 --- a/internal/testutil/pkgdata_test.go +++ b/internal/testutil/pkgdata_test.go @@ -398,3 +398,42 @@ func (s *S) TestMustMakeDeb(c *C) { }, }}) } + +func (s *S) TestTarEntryShortHands(c *C) { + var testCases = []struct { + shorthand testutil.TarEntry + result testutil.TarEntry + }{{ + testutil.Reg(0600, "./document.txt", "cats are best"), + testutil.TarEntry{ + Header: tar.Header{ + Typeflag: tar.TypeReg, + Name: "./document.txt", + Mode: 0600, + }, + Content: []byte("cats are best"), + }, + }, { + testutil.Dir(0755, "./home/user"), + testutil.TarEntry{ + Header: tar.Header{ + Typeflag: tar.TypeDir, + Name: "./home/user", + Mode: 0755, + }, + }, + }, { + testutil.Lnk(0755, "./lib", "./usr/lib/"), + testutil.TarEntry{ + Header: tar.Header{ + Typeflag: tar.TypeSymlink, + Name: "./lib", + Mode: 0755, + Linkname: "./usr/lib/", + }, + }, + }} + for _, test := range testCases { + c.Assert(test.shorthand, DeepEquals, test.result) + } +}