Skip to content

Commit

Permalink
testutil: Add MakeTestDeb()
Browse files Browse the repository at this point in the history
Add MakeTestDeb() function to testutil/pkgdata. This function is just
like MakeDeb() except that it doesn't return an error. Instead, it
panics on errors.

This is useful in tests where package data is created in top-level test
case structures where we don't need to handle the error, e.g.:

	var testCases = []TestCase{{
		pkg: MakeTestDeb([]TarEntry{
			...
		}),
	}, {
		...
	}}
  • Loading branch information
woky committed Jun 21, 2023
1 parent afad3d2 commit 3555931
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/testutil/pkgdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,11 @@ func MakeDeb(entries []TarEntry) ([]byte, error) {
}
return buf.Bytes(), nil
}

func MakeTestDeb(entries []TarEntry) []byte {
data, err := MakeDeb(entries)
if err != nil {
panic(err)
}
return data
}
12 changes: 12 additions & 0 deletions internal/testutil/pkgdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,15 @@ func (s *pkgdataSuite) TestMakeDeb(c *C) {
_, err = arReader.Next()
c.Assert(err, Equals, io.EOF)
}

func (s *S) TestMakeTestDeb(c *C) {
defer func() {
err := recover()
c.Assert(err, ErrorMatches, `.*: cannot encode header: invalid PAX record: "path = \\x00./foo.*`)
}()
testutil.MakeTestDeb([]testutil.TarEntry{{
Header: tar.Header{
Name: "\000./foo",
},
}})
}

0 comments on commit 3555931

Please sign in to comment.