convert: compact table test and remove t.Run use

This commit is contained in:
Jonathan Ingram
2017-09-20 17:31:50 +10:00
committed by Hamish
parent 9e7fa8a68e
commit 2228da9d5d
+10 -29
View File
@@ -1,39 +1,20 @@
package docconv
import (
"io"
"reflect"
"strings"
"testing"
)
func TestConvert(t *testing.T) {
tests := []struct {
name string
r io.Reader
mimeType string
readability bool
resp *Response
err error
}{
{
name: "trims space",
mimeType: "text/plain",
r: strings.NewReader(" \n\n\nthe file\n\n"),
resp: &Response{
Body: "the file",
},
},
func TestConvertTrimsSpace(t *testing.T) {
resp, err := Convert(
strings.NewReader(" \n\n\nthe \n file\n\n"),
"text/plain",
false,
)
if err != nil {
t.Fatalf("got error = %v, want nil", err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Convert(tt.r, tt.mimeType, tt.readability)
if err != tt.err {
t.Fatalf("Convert() error = %v, want %v", err, tt.err)
}
if !reflect.DeepEqual(got, tt.resp) {
t.Errorf("Convert() = %v, want %v", got, tt.resp)
}
})
if want := "the \n file"; resp.Body != want {
t.Errorf("body = %v, want %v", resp.Body, want)
}
}