-
Notifications
You must be signed in to change notification settings - Fork 6
/
environment_value_test.go
58 lines (51 loc) · 1.13 KB
/
environment_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 TestNewEnvironment(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{"SANDBOX", "SANDBOX", nil},
{"PRODUCTION", "PRODUCTION", nil},
{"INVALID", "", errors.New("environment value should be one of the following: SANDBOX,PRODUCTION, got INVALID")},
}
for _, c := range cases {
actual, err := newEnvironment(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 TestEnvironmentUnMarshal(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{`"SANDBOX"`, "SANDBOX", nil},
{`"PRODUCTION"`, "PRODUCTION", nil},
{`"INVALID"`, "", errors.New("")},
{`1`, "", errors.New("")},
{`null`, "", errors.New("")},
}
for _, c := range cases {
var e environment
b := []byte(c.in)
err := json.Unmarshal(b, &e)
assert.Equal(t, c.expected, e.String())
if c.err == nil {
assert.Nil(t, err)
} else {
assert.Error(t, err)
}
}
}