-
Notifications
You must be signed in to change notification settings - Fork 6
/
store_value_test.go
58 lines (51 loc) · 1.15 KB
/
store_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 TestNewStore(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{"PLAY_STORE", "PLAY_STORE", nil},
{"APP_STORE", "APP_STORE", nil},
{"INVALID", "", errors.New("store value should be one of the following: PLAY_STORE, APP_STORE, STRIPE, MAC_APP_STORE, PROMOTIONAL, got INVALID")},
}
for _, c := range cases {
actual, err := newStore(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 TestStoreUnMarshal(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{`"PLAY_STORE"`, "PLAY_STORE", nil},
{`"APP_STORE"`, "APP_STORE", nil},
{`"INVALID"`, "", errors.New("")},
{`1`, "", errors.New("")},
{`null`, "", errors.New("")},
}
for _, c := range cases {
var s store
b := []byte(c.in)
err := json.Unmarshal(b, &s)
if err == nil {
assert.Equal(t, c.expected, s.String())
assert.Nil(t, err)
} else {
assert.Error(t, err)
}
}
}