-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
49 lines (44 loc) · 958 Bytes
/
main_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
package main
import (
"flag"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestMain(m *testing.M) {
flag.Parse()
os.Mkdir("test", 0777) // set up a temporary dir for generate files
// Create whatever testfiles are needed in test/
// Run all tests and clean up
exitcode := m.Run()
os.RemoveAll("test") // remove the directory and its contents.
os.Exit(exitcode)
}
func TestTest(t *testing.T) {
var testCases = []struct {
input string
expected string
failure bool
}{
{"foobar", "foobar", false},
{"a", "a", false},
}
for _, tt := range testCases {
t.Run(tt.input, func(t *testing.T) {
err := error(nil)
actual := tt.input
if tt.failure != true {
if err != nil {
t.Errorf("No error expected, got %v", err)
}
if tt.expected != "" {
assert.Equal(t, tt.expected, actual, "should be equal")
}
} else {
if err == nil {
t.Errorf("Expected to fail?")
}
}
})
}
}