-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_spec_test.go
139 lines (136 loc) · 3.03 KB
/
model_spec_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package gogh_test
import (
"testing"
testtarget "github.com/kyoh86/gogh/v2"
)
func TestSpec(t *testing.T) {
const (
validHost = "example.com"
validOwner = "kyoh86"
validName = "gogh"
)
for _, testcase := range []struct {
title string
host string
owner string
name string
expect error
}{
{
title: "valid",
host: validHost,
owner: validOwner,
name: validName,
expect: nil,
},
{
title: "empty-name",
host: validHost,
owner: validOwner,
name: "",
expect: testtarget.ErrEmptyName,
},
{
title: "empty-owner",
host: validHost,
owner: "",
name: validName,
expect: testtarget.ErrEmptyOwner,
},
{
title: "empty-host",
host: "",
owner: validOwner,
name: validName,
expect: testtarget.ErrEmptyHost,
},
{
title: "slashed-name",
host: validHost,
owner: validOwner,
name: "go/gh",
expect: testtarget.ErrInvalidName("invalid name: go/gh"),
},
{
title: "slashed-owner",
host: validHost,
owner: "kyoh/86",
name: validName,
expect: testtarget.ErrInvalidOwner("invalid owner: kyoh/86"),
},
{
title: "slashed-host",
host: "example.com/example",
owner: validOwner,
name: validName,
expect: testtarget.ErrInvalidHost("invalid host: example.com/example"),
},
{
title: "dotted-owner",
host: validHost,
owner: "kyoh.86",
name: validName,
expect: testtarget.ErrInvalidOwner("invalid owner: kyoh.86"),
},
{
title: "dot-name",
host: validHost,
owner: validOwner,
name: ".",
expect: testtarget.ErrInvalidName("'.' is reserved name"),
},
{
title: "dot-owner",
host: validHost,
owner: ".",
name: validName,
expect: testtarget.ErrInvalidOwner("invalid owner: ."),
},
{
title: "dotdot-name",
host: validHost,
owner: validOwner,
name: "..",
expect: testtarget.ErrInvalidName("'..' is reserved name"),
},
{
title: "dotdot-owner",
host: validHost,
owner: "..",
name: validName,
expect: testtarget.ErrInvalidOwner("invalid owner: .."),
},
{
title: "ported-host",
host: "127.0.0.1:9000",
owner: validOwner,
name: validName,
expect: nil,
},
} {
t.Run(testcase.title, func(t *testing.T) {
spec, err := testtarget.NewSpec(testcase.host, testcase.owner, testcase.name)
if testcase.expect == nil {
if err != nil {
t.Fatalf("failed to create new spec: %s", err)
}
if testcase.host != spec.Host() {
t.Errorf("expect host %q but %q gotten", testcase.host, spec.Host())
}
if testcase.owner != spec.Owner() {
t.Errorf("expect owner %q but %q gotten", testcase.owner, spec.Owner())
}
if testcase.name != spec.Name() {
t.Errorf("expect name %q but %q gotten", testcase.name, spec.Name())
}
} else {
if err == nil {
t.Fatal("expect failure to create new spec, but not")
}
if testcase.expect.Error() != err.Error() {
t.Fatalf("expect error %s, but actual %s is gottten", testcase.expect, err)
}
}
})
}
}