-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_call_test.go
72 lines (59 loc) · 1.32 KB
/
rest_call_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
var restCallTestCases = []struct {
restCall RestCall
str string
}{
{
restCall: Tle,
str: "tle",
},
{
restCall: Cdm,
str: "cdm",
},
{
restCall: Decay,
str: "dec",
},
{
restCall: All,
str: "all",
},
}
func TestRestCall(t *testing.T) {
t.Run("restCall set returns nil when text exists", func(t *testing.T) {
for _, rc := range restCallTestCases {
var restCall RestCall
assert.Nil(t, restCall.Set(rc.str))
}
})
t.Run("restCall set returns error when text don't exist", func(t *testing.T) {
var restCall RestCall
got := restCall.Set("notexistent")
want := ErrParsingRestCall
assert.ErrorIs(t, got, want)
})
t.Run("parse restCall returns the right restCall when exist", func(t *testing.T) {
for _, want := range restCallTestCases {
got, err := parseRestCall(want.str)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, want.restCall, got)
}
})
t.Run("parse restCall returns error when not exist", func(t *testing.T) {
_, got := parseRestCall("notexistent")
want := ErrParsingRestCall
assert.ErrorIs(t, got, want)
})
t.Run("restCall type is string", func(t *testing.T) {
for _, f := range restCallTestCases {
assert.Equal(t, "string", f.restCall.Type())
}
})
}