-
Notifications
You must be signed in to change notification settings - Fork 6
/
price_value_test.go
73 lines (65 loc) · 1.23 KB
/
price_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package revcatgo
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/guregu/null.v4"
)
func TestNewPrice(t *testing.T) {
cases := []struct {
in float64
expected float64
err error
}{
{500, 500, nil},
{0, 0, nil},
}
for _, c := range cases {
actual, err := newPrice(null.FloatFrom(c.in))
assert.Equal(t, c.expected, actual.Float64())
if c.err == nil {
assert.Nil(t, err)
} else {
assert.EqualError(t, err, c.err.Error())
}
}
cases2 := []struct {
in float64
expected bool
err error
}{
{500, false, nil},
{0, true, nil},
}
for _, c := range cases2 {
actual, err := newPrice(null.FloatFrom(c.in))
if err == nil {
assert.Equal(t, c.expected, actual.IsFreeTrial())
assert.Nil(t, err)
} else {
assert.EqualError(t, err, c.err.Error())
}
}
}
func TestPriceUnMarshal(t *testing.T) {
cases := []struct {
in string
expected float64
err error
}{
{`500`, 500, nil},
{`0`, 0, nil},
{`null`, 0, nil},
}
for _, c := range cases {
var p price
b := []byte(c.in)
err := json.Unmarshal(b, &p)
assert.Equal(t, c.expected, p.Float64())
if c.err == nil {
assert.Nil(t, err)
} else {
assert.Error(t, err)
}
}
}