mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-10-04 04:31:00 +00:00
test: migrate most tests to testify
testify makes most bog-standard test checks much easier to read and maintain, and is quite widely used. It wasn't really well known back when go-mtree was first written, but the migration is fairly straight-forward for most tests. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
parent
f2b48a0e2f
commit
3252a4ad82
55 changed files with 22620 additions and 886 deletions
|
@ -3,13 +3,20 @@ package mtree
|
|||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var checklist = []struct {
|
||||
blob string
|
||||
set []Keyword
|
||||
}{
|
||||
{blob: `
|
||||
func TestUsedKeywords(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
blob string
|
||||
set []Keyword
|
||||
}{
|
||||
{
|
||||
name: "NonHomogenous",
|
||||
blob: `
|
||||
# machine: bananaboat
|
||||
# tree: .git
|
||||
# date: Wed Nov 16 14:54:17 2016
|
||||
|
@ -19,8 +26,12 @@ var checklist = []struct {
|
|||
. size=4096 type=dir mode=0755 nlink=8 time=1479326055.423853146
|
||||
.COMMIT_EDITMSG.un~ size=1006 mode=0644 time=1479325423.450468662 sha1digest=dead0face
|
||||
.TAG_EDITMSG.un~ size=1069 mode=0600 time=1471362316.801317529 sha256digest=dead0face
|
||||
`, set: []Keyword{"size", "mode", "time", "sha256digest"}},
|
||||
{blob: `
|
||||
`,
|
||||
set: []Keyword{"type", "nlink", "mode", "uid", "gid", "size", "time", "sha1digest", "sha256digest"},
|
||||
},
|
||||
{
|
||||
name: "xattrs",
|
||||
blob: `
|
||||
# user: cyphar
|
||||
# machine: ryuk
|
||||
# tree: xattr
|
||||
|
@ -32,20 +43,15 @@ var checklist = []struct {
|
|||
. size=8 type=dir mode=0755 time=1506666472.255992830
|
||||
file size=0 mode=0644 time=1506666472.255992830 xattr.user.something=dGVzdA==
|
||||
..
|
||||
`, set: []Keyword{"size", "type", "uid", "gid", "mode", "nlink", "time", "xattr"}},
|
||||
}
|
||||
|
||||
func TestUsedKeywords(t *testing.T) {
|
||||
for i, item := range checklist {
|
||||
dh, err := ParseSpec(strings.NewReader(item.blob))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
used := dh.UsedKeywords()
|
||||
for _, k := range item.set {
|
||||
if !InKeywordSlice(k, used) {
|
||||
t.Errorf("%d: expected to find %q in %q", i, k, used)
|
||||
}
|
||||
}
|
||||
`,
|
||||
set: []Keyword{"size", "type", "uid", "gid", "mode", "nlink", "time", "xattr"},
|
||||
},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
dh, err := ParseSpec(strings.NewReader(test.blob))
|
||||
require.NoError(t, err, "parse spec")
|
||||
used := dh.UsedKeywords()
|
||||
assert.ElementsMatch(t, used, test.set, "UsedKeywords should contain all keywords used")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue