-
Notifications
You must be signed in to change notification settings - Fork 4
/
util_test.go
58 lines (49 loc) · 1.44 KB
/
util_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
package quiz
import (
"path/filepath"
"strings"
"testing"
)
func TestFileArgs(t *testing.T) {
//Need to check
// 1 - Files have been passed in
// 2 - files exist
file1 := filepath.Join("test_data", "abcd.csv")
file2 := filepath.Join("test_data", "true_false.csv")
file3 := filepath.Join("test_data", "fill_in_the_blank.csv")
notAFile := filepath.Join("test_data", "notAFile")
emptyString := ""
error1 := "No files were passed in"
error2 := "empty string cannot be used as a file"
error3 := "test_data/notAFile does not exist"
tests := []struct {
Files []string
ExpectedError bool
Error string
}{
{[]string{}, true, error1},
{[]string{emptyString}, true, error2},
{[]string{notAFile}, true, error3},
{[]string{file1}, false, ""},
{[]string{file1, file2}, false, ""},
{[]string{file1, file2, file3}, false, ""},
{[]string{file1, emptyString, file2}, true, error2},
{[]string{file1, notAFile, file2}, true, error3},
}
for _, test := range tests {
err := FileArgs(test.Files)
if test.ExpectedError && err == nil {
t.Error("Was expecting an error but no error was received")
}
if !test.ExpectedError && err != nil {
t.Errorf("Unexpected Error: %s", err.Error())
}
if test.ExpectedError && err != nil {
if !strings.Contains(err.Error(), test.Error) {
t.Errorf("Expected error to contain %s, but the error was actually '%s'", test.Error, err.Error())
} else {
continue
}
}
}
}