forked from nzoschke/gofaas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
46 lines (36 loc) · 945 Bytes
/
user_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
package gofaas
import (
"context"
"encoding/json"
"testing"
"github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
func TestUserCreate(t *testing.T) {
DynamoDB = &MockDynamoDB{
GetItemOutput: &dynamodb.GetItemOutput{},
}
KMS = &MockKMS{}
UUIDGen = func() uuid.UUID {
return uuid.Must(uuid.FromString("26f0dc9f-4483-4b65-8724-3d1598ff6d14"))
}
r, err := UserCreate(context.Background(), events.APIGatewayProxyRequest{
Body: `{"username": "test"}`,
})
assert.NoError(t, err)
u := User{}
err = json.Unmarshal([]byte(r.Body), &u)
assert.NoError(t, err)
assert.EqualValues(t,
events.APIGatewayProxyResponse{
Body: "{\n \"id\": \"26f0dc9f-4483-4b65-8724-3d1598ff6d14\",\n \"username\": \"test\"\n}\n",
Headers: map[string]string{
"Content-Type": "application/json",
},
StatusCode: 200,
},
r,
)
}