*: add subtests for all table driven tests

Because we use testify, this is less useful than normal, but this is
still best practice for table-driven tests.
This commit is contained in:
Jimmy Zelinskie
2017-12-29 17:44:45 -05:00
parent 5840cd3de1
commit 2004489016
8 changed files with 84 additions and 52 deletions

View File

@@ -2,6 +2,7 @@ package bencode
import (
"bytes"
"fmt"
"testing"
"time"
@@ -35,10 +36,12 @@ var marshalTests = []struct {
}
func TestMarshal(t *testing.T) {
for _, test := range marshalTests {
got, err := Marshal(test.input)
require.Nil(t, err, "marshal should not fail")
require.Contains(t, test.expected, string(got), "the marshaled result should be one of the expected permutations")
for _, tt := range marshalTests {
t.Run(fmt.Sprintf("%#v", tt.input), func(t *testing.T) {
got, err := Marshal(tt.input)
require.Nil(t, err, "marshal should not fail")
require.Contains(t, tt.expected, string(got), "the marshaled result should be one of the expected permutations")
})
}
}