-
Notifications
You must be signed in to change notification settings - Fork 6
/
period_type_value_test.go
58 lines (51 loc) · 1.11 KB
/
period_type_value_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 revcatgo
import (
"encoding/json"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewPeriodType(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{"TRIAL", "TRIAL", nil},
{"NORMAL", "NORMAL", nil},
{"INVALID", "", errors.New("periodType value should be one of the following: TRIAL,INTRO,NORMAL,PROMOTIONAL, got INVALID")},
}
for _, c := range cases {
actual, err := newPeriodType(c.in)
assert.Equal(t, c.expected, actual.String())
if c.err == nil {
assert.Nil(t, err)
} else {
assert.EqualError(t, err, c.err.Error())
}
}
}
func TestPeriodTypeUnMarshal(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{`"TRIAL"`, "TRIAL", nil},
{`"NORMAL"`, "NORMAL", nil},
{`"INVALID"`, "", errors.New("")},
{`1`, "", errors.New("")},
{`null`, "", errors.New("")},
}
for _, c := range cases {
var p periodType
b := []byte(c.in)
err := json.Unmarshal(b, &p)
if err == nil {
assert.Equal(t, c.expected, p.String())
assert.Nil(t, err)
} else {
assert.Error(t, err)
}
}
}