From 996381fd60df1f1cec3c31ad48c6257684d4ef75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Virtus?= Date: Tue, 6 Jun 2023 06:17:34 +0200 Subject: [PATCH] testutil/pkgdata: Add MakeTestDeb() 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{ ... }), }, { ... }} --- 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 2b7f0221..c1e1fa3a 100644 --- a/internal/testutil/pkgdata.go +++ b/internal/testutil/pkgdata.go @@ -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 +} diff --git a/internal/testutil/pkgdata_test.go b/internal/testutil/pkgdata_test.go index 53283b3a..6db66ee8 100644 --- a/internal/testutil/pkgdata_test.go +++ b/internal/testutil/pkgdata_test.go @@ -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", + }, + }}) +}