-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_test.go
46 lines (43 loc) · 833 Bytes
/
component_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
package portfolio
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestComponent_Validate(t *testing.T) {
for _, tt := range []struct {
Name string
Component Component
ErrorSubstring string
}{
{
Name: "with undefined ID",
Component: Component{
ID: "undefined",
},
ErrorSubstring: "undefined",
},
{
Name: "with ID not set",
Component: Component{
ID: "",
},
ErrorSubstring: "component ID must be set",
},
{
Name: "with disallowed character in ID",
Component: Component{
ID: "#banana",
},
ErrorSubstring: "pattern",
},
} {
t.Run(tt.Name, func(t *testing.T) {
err := tt.Component.Validate()
if tt.ErrorSubstring != "" {
assert.ErrorContains(t, err, tt.ErrorSubstring)
} else {
assert.NoError(t, err)
}
})
}
}