-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentities_test.go
44 lines (41 loc) · 1 KB
/
entities_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
package calc_test
import (
"testing"
"github.com/antklim/go-calc"
"github.com/stretchr/testify/assert"
)
func TestRequestValidation(t *testing.T) {
testCases := []struct {
desc string
req calc.Request
assert func(t *testing.T, err error)
}{
{
desc: "returns error when unsupported operation provided",
req: calc.Request{Operation: "foo"},
assert: func(t *testing.T, err error) {
assert.EqualError(t, err, "unsupported operation 'foo'")
},
},
{
desc: "propagates operation validation error",
req: calc.Request{Operation: "add"},
assert: func(t *testing.T, err error) {
assert.EqualError(t, err, "arguments list cannot be nil")
},
},
{
desc: "returns nil when request is valid",
req: calc.Request{Operation: "add", Arguments: []float64{1, 2}},
assert: func(t *testing.T, err error) {
assert.NoError(t, err)
},
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
err := tC.req.Validate()
tC.assert(t, err)
})
}
}