-
Notifications
You must be signed in to change notification settings - Fork 7
/
invoke_test.go
76 lines (62 loc) · 1.71 KB
/
invoke_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
package invoke_test
import (
"testing"
"github.com/apex/invoke"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/stretchr/testify/assert"
)
type client struct {
FunctionError *string
}
func (c *client) Invoke(in *lambda.InvokeInput) (*lambda.InvokeOutput, error) {
return &lambda.InvokeOutput{
FunctionError: c.FunctionError,
Payload: in.Payload,
}, nil
}
type input struct {
Value string `json:"name"`
}
type output struct {
Value string `json:"name"`
}
func TestInvokeSync(t *testing.T) {
c := new(client)
var out output
err := invoke.InvokeSync(c, "test", input{"hello"}, &out)
assert.NoError(t, err)
assert.Equal(t, "hello", out.Value)
}
func TestInvokeSync_noInput(t *testing.T) {
c := new(client)
var out output
err := invoke.InvokeSync(c, "test", nil, &out)
assert.NoError(t, err)
assert.Equal(t, "", out.Value)
}
func TestInvokeSync_noOutput(t *testing.T) {
c := new(client)
err := invoke.InvokeSync(c, "test", input{"hello"}, nil)
assert.NoError(t, err)
}
func TestInvokeSync_noInput_noOutput(t *testing.T) {
c := new(client)
err := invoke.InvokeSync(c, "test", nil, nil)
assert.NoError(t, err)
}
func TestInvokeSync_error(t *testing.T) {
c := new(client)
var out output
c.FunctionError = aws.String("Unhandled")
err := invoke.InvokeSync(c, "test", &invoke.Error{Message: "Task timed out after 5.00 seconds"}, &out)
assert.Equal(t, "unhandled: Task timed out after 5.00 seconds", err.Error())
e := err.(*invoke.Error)
assert.False(t, e.Handled)
assert.Equal(t, "Task timed out after 5.00 seconds", e.Message)
}
func TestInvokeAsync(t *testing.T) {
c := new(client)
err := invoke.InvokeAsync(c, "test", input{"hello"})
assert.NoError(t, err)
}