forked from gobuffalo/genny
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransformer_test.go
More file actions
45 lines (39 loc) · 902 Bytes
/
transformer_test.go
File metadata and controls
45 lines (39 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package genny
import (
"io/ioutil"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Transformer(t *testing.T) {
table := []struct {
in File
out File
}{
{
in: NewFile("hi.txt.bar", strings.NewReader("hi")),
out: NewFile("hello.txt", strings.NewReader("hi")),
},
{
in: NewFile("hi.txt", strings.NewReader("hi")),
out: NewFile("hi.txt", strings.NewReader("hi")),
},
}
tf := NewTransformer(".bar", func(f File) (File, error) {
return NewFile("hello.txt.bar", f), nil
})
tf.StripExt = true
for _, tt := range table {
t.Run(tt.in.Name()+"|"+tt.out.Name(), func(st *testing.T) {
r := require.New(st)
f, err := tf.Transform(tt.in)
r.NoError(err)
r.Equal(tt.out.Name(), f.Name())
ob, err := ioutil.ReadAll(tt.out)
r.NoError(err)
fb, err := ioutil.ReadAll(f)
r.NoError(err)
r.Equal(string(ob), string(fb))
})
}
}