This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
param_test.go
108 lines (90 loc) · 2.43 KB
/
param_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package regula
import (
"testing"
"github.com/heetch/regula/rule"
"github.com/stretchr/testify/require"
)
func TestGetString(t *testing.T) {
p := Params{
"string": "string",
"bool": true,
}
t.Run("GetString - OK", func(t *testing.T) {
v, err := p.GetString("string")
require.NoError(t, err)
require.Equal(t, "string", v)
})
t.Run("GetString - NOK - ErrParamNotFound", func(t *testing.T) {
_, err := p.GetString("badkey")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamNotFound)
})
t.Run("GetString - NOK - ErrParamTypeMismatch", func(t *testing.T) {
_, err := p.GetString("bool")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamTypeMismatch)
})
}
func TestGetBool(t *testing.T) {
p := Params{
"bool": true,
"string": "string",
}
t.Run("GetBool - OK", func(t *testing.T) {
v, err := p.GetBool("bool")
require.NoError(t, err)
require.Equal(t, true, v)
})
t.Run("GetBool - NOK - ErrParamNotFound", func(t *testing.T) {
_, err := p.GetBool("badkey")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamNotFound)
})
t.Run("GetBool - NOK - ErrParamTypeMismatch", func(t *testing.T) {
_, err := p.GetBool("string")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamTypeMismatch)
})
}
func TestGetInt64(t *testing.T) {
p := Params{
"int64": int64(42),
"string": "string",
}
t.Run("GetInt64 - OK", func(t *testing.T) {
v, err := p.GetInt64("int64")
require.NoError(t, err)
require.Equal(t, int64(42), v)
})
t.Run("GetInt64 - NOK - ErrParamNotFound", func(t *testing.T) {
_, err := p.GetInt64("badkey")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamNotFound)
})
t.Run("GetInt64 - NOK - ErrParamTypeMismatch", func(t *testing.T) {
_, err := p.GetInt64("string")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamTypeMismatch)
})
}
func TestGetFloat64(t *testing.T) {
p := Params{
"float64": 42.42,
"string": "string",
}
t.Run("GetFloat64 - OK", func(t *testing.T) {
v, err := p.GetFloat64("float64")
require.NoError(t, err)
require.Equal(t, 42.42, v)
})
t.Run("GetFloat64 - NOK - ErrParamNotFound", func(t *testing.T) {
_, err := p.GetFloat64("badkey")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamNotFound)
})
t.Run("GetFloat64 - NOK - ErrParamTypeMismatch", func(t *testing.T) {
_, err := p.GetFloat64("string")
require.Error(t, err)
require.Equal(t, err, rule.ErrParamTypeMismatch)
})
}