-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgocon_test.go
82 lines (71 loc) · 1.61 KB
/
gocon_test.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package gocon_test
import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"github.com/gopherdojo/dojo5/kadai1/nagaa052/internal/gocon"
)
func TestRun(t *testing.T) {
errMessage := `
It was not converted properly.
Error: %v
`
streamErrMessage := `
Convert Error.
%v
`
srcDir, err := filepath.Abs(filepath.Join("testdata", t.Name()))
if err != nil {
t.Error(err)
}
destDir, err := filepath.Abs("out")
if err != nil {
t.Error(err)
}
cases := []struct {
name string
options gocon.Options
expected int
isError bool
}{
{
name: "Success Test",
options: gocon.Options{
FromFormat: gocon.JPEG,
ToFormat: gocon.PNG,
DestDir: destDir,
},
expected: gocon.ExitOK,
isError: false,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
g, err := gocon.New(srcDir, c.options, outStream, errStream)
if !c.isError && err != nil {
t.Error(fmt.Sprintf("gocon make error : %+v", err))
}
actual := g.Run()
if _, err := os.Stat(destDir); err == nil {
if err := os.RemoveAll(destDir); err != nil {
fmt.Println(err)
}
}
if c.expected != actual {
t.Error(fmt.Sprintf(errMessage, c.expected, actual))
}
if errStream.String() != "" {
t.Error(fmt.Sprintf(streamErrMessage, errStream.String()))
}
messageFmt := strings.Replace(gocon.SuccessConvertFileMessageFmt, "\n", "", -1)
expectedMessage := fmt.Sprintf(messageFmt, destDir)
if !strings.Contains(outStream.String(), expectedMessage) {
t.Error("Conversion failed")
}
})
}
}