From 5e8cdac98dba9747e4282e522ef9228d6c916c7d Mon Sep 17 00:00:00 2001 From: woky Date: Tue, 29 Aug 2023 12:30:04 +0200 Subject: [PATCH] testutil/pkgdata: Add MakeTestDeb() (#87) --- internal/testutil/pkgdata.go | 8 ++++++++ internal/testutil/pkgdata_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/internal/testutil/pkgdata.go b/internal/testutil/pkgdata.go index e1401741..0c71fa47 100644 --- a/internal/testutil/pkgdata.go +++ b/internal/testutil/pkgdata.go @@ -266,3 +266,11 @@ func MakeDeb(entries []TarEntry) ([]byte, error) { } return buf.Bytes(), nil } + +func MustMakeDeb(entries []TarEntry) []byte { + data, err := MakeDeb(entries) + if err != nil { + panic(err) + } + return data +} diff --git a/internal/testutil/pkgdata_test.go b/internal/testutil/pkgdata_test.go index 67c0a46b..5118fad0 100644 --- a/internal/testutil/pkgdata_test.go +++ b/internal/testutil/pkgdata_test.go @@ -385,3 +385,15 @@ func (s *pkgdataSuite) TestMakeDeb(c *C) { _, err = arReader.Next() c.Assert(err, Equals, io.EOF) } + +func (s *S) TestMustMakeDeb(c *C) { + defer func() { + err := recover() + c.Assert(err, ErrorMatches, `.*: cannot encode header: invalid PAX record: "path = \\x00./foo.*`) + }() + testutil.MustMakeDeb([]testutil.TarEntry{{ + Header: tar.Header{ + Name: "\000./foo", + }, + }}) +}