-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_test.go
117 lines (96 loc) · 2.72 KB
/
create_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"errors"
log "github.com/sirupsen/logrus"
"testing"
)
func TestCreateScheme(t *testing.T) {
testCases := []struct {
name string
input string
output string
expectSchemeError bool
}{
{
name: "bad input scheme",
input: "badscheme://path/to/data/",
output: "scheme://path/to/data/",
expectSchemeError: true,
},
{
name: "bad output scheme",
input: "file:///path/to/data/",
output: "badscheme://path/to/data/",
expectSchemeError: true,
},
{
name: "good schemes",
input: "file:///path/to/data/",
output: "scheme://path/to/data/",
expectSchemeError: false,
},
}
jm := NewMockJobManager()
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, err := jm.Create(tc.input, tc.output)
var got *schemeError
isSchemeError := errors.As(err, &got)
if tc.expectSchemeError && (!isSchemeError) {
t.Fatalf("[%s] expected scheme error %v, got %T", tc.name, tc.expectSchemeError, err)
} else if (!tc.expectSchemeError) && isSchemeError {
t.Fatalf("[%s] did not expect scheme error %v, got %T", tc.name, tc.expectSchemeError, err)
}
})
}
}
func TestCreateSourceError(t *testing.T) {
testCases := []struct {
name string
input string
output string
expectSourceError bool
}{
{
name: "good source",
input: "file:///path/to/data/",
output: "scheme://path/to/data/",
expectSourceError: false,
},
{
name: "bad source",
input: "file:///non-existing-path/to/data/",
output: "scheme://path/to/data/",
expectSourceError: true,
},
}
jm := NewMockJobManager()
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, err := jm.Create(tc.input, tc.output)
var got *sourceError
isSourceError := errors.As(err, &got)
if tc.expectSourceError && (!isSourceError) {
t.Fatalf("[%s] expected source error %v, got %T", tc.name, tc.expectSourceError, err)
} else if (!tc.expectSourceError) && isSourceError {
t.Fatalf("[%s] did not expect source error %v, got %T", tc.name, tc.expectSourceError, err)
}
})
}
}
func TestCreateDuplicate(t *testing.T) {
jm := NewMockJobManager()
MakeCompletedJob(jm)
_, err := MakeCompletedJob(jm)
var got *duplicateJobError
isDuplicate := errors.As(err, &got)
if !isDuplicate {
t.Fatalf("expected to receive duplicateJobError but got %v", err)
}
}
func TestLogger(t *testing.T) {
jm := NewMockJobManager()
jm.logger.WithFields(log.Fields{
"in": "test",
"out": "test"}).Info("transferred")
}