Codebase list golang-github-go-kit-kit / f54b457
replace aws lambda structs with stubs Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com> Mark Sagi-Kazar 2 years ago
3 changed file(s) with 25 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
55 github.com/VividCortex/gohistogram v1.0.0
66 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
77 github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a
8 github.com/aws/aws-lambda-go v1.13.3
98 github.com/aws/aws-sdk-go v1.38.65
109 github.com/aws/aws-sdk-go-v2 v1.6.0
1110 github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.4.1
2020 github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
2121 github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a h1:pv34s756C4pEXnjgPfGYgdhg/ZdajGhyOvzx8k+23nw=
2222 github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
23 github.com/aws/aws-lambda-go v1.13.3 h1:SuCy7H3NLyp+1Mrfp+m80jcbi9KYWAs9/BXwppwRDzY=
24 github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
2523 github.com/aws/aws-sdk-go v1.38.65 h1:umGu5gjIOKxzhi34T0DIA1TWupUDjV2aAW5vK6154Gg=
2624 github.com/aws/aws-sdk-go v1.38.65/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
2725 github.com/aws/aws-sdk-go-v2 v1.6.0 h1:r20hdhm8wZmKkClREfacXrKfX0Y7/s0aOoeraFbf/sY=
5351 github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
5452 github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
5553 github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
56 github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
5754 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5855 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5956 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
284281 github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
285282 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
286283 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
287 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
288284 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
289285 github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da h1:p3Vo3i64TCLY7gIfzeQaUJ+kppEO5WQG3cL8iE8tGHU=
290286 github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
291287 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
292288 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
293 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
294289 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
295290 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
296291 github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
314309 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
315310 github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
316311 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
317 github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
318312 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
319313 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
320314 github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
55 "fmt"
66 "testing"
77
8 "github.com/aws/aws-lambda-go/events"
98 "github.com/go-kit/kit/endpoint"
109 "github.com/go-kit/kit/log"
1110 "github.com/go-kit/kit/transport"
2019 KeyEncMode key = iota
2120 )
2221
22 // Created based on github.com/aws/aws-lambda-go@v1.13.3/events.APIGatewayProxyRequest for the purposes of the tests below.
23 type apiGatewayProxyRequest struct {
24 Body string `json:"body"`
25 }
26
27 // Created based on github.com/aws/aws-lambda-go@v1.13.3/events.APIGatewayProxyResponse for the purposes of the tests below.
28 type apiGatewayProxyResponse struct {
29 StatusCode int `json:"statusCode"`
30 Body string `json:"body"`
31 }
32
2333 func TestDefaultErrorEncoder(t *testing.T) {
2434 ctx := context.Background()
2535 rootErr := fmt.Errorf("root")
7585 resp []byte,
7686 _ error,
7787 ) {
78 apigwResp := events.APIGatewayProxyResponse{}
88 apigwResp := apiGatewayProxyResponse{}
7989 err := json.Unmarshal(resp, &apigwResp)
8090 if err != nil {
8191 t.Fatalf("Should have no error, but got: %+v", err)
96106 )
97107
98108 ctx := context.Background()
99 req, _ := json.Marshal(events.APIGatewayProxyRequest{
109 req, _ := json.Marshal(apiGatewayProxyRequest{
100110 Body: `{"name":"john doe"}`,
101111 })
102112 resp, err := helloHandler.Invoke(ctx, req)
105115 t.Fatalf("Should have no error, but got: %+v", err)
106116 }
107117
108 apigwResp := events.APIGatewayProxyResponse{}
118 apigwResp := apiGatewayProxyResponse{}
109119 err = json.Unmarshal(resp, &apigwResp)
110120 if err != nil {
111121 t.Fatalf("Should have no error, but got: %+v", err)
135145 ctx context.Context,
136146 err error,
137147 ) ([]byte, error) {
138 apigwResp := events.APIGatewayProxyResponse{}
148 apigwResp := apiGatewayProxyResponse{}
139149 apigwResp.Body = `{"error":"yes"}`
140150 apigwResp.StatusCode = 500
141151 resp, err := json.Marshal(apigwResp)
144154 )
145155
146156 ctx := context.Background()
147 req, _ := json.Marshal(events.APIGatewayProxyRequest{
157 req, _ := json.Marshal(apiGatewayProxyRequest{
148158 Body: `{"name":"john doe"}`,
149159 })
150160 resp, err := helloHandler.Invoke(ctx, req)
153163 t.Fatalf("Should have no error, but got: %+v", err)
154164 }
155165
156 apigwResp := events.APIGatewayProxyResponse{}
166 apigwResp := apiGatewayProxyResponse{}
157167 json.Unmarshal(resp, &apigwResp)
158168 if apigwResp.StatusCode != 500 {
159169 t.Fatalf("Expect status code of 500, instead of %d", apigwResp.StatusCode)
185195 ctx context.Context,
186196 err error,
187197 ) ([]byte, error) {
188 apigwResp := events.APIGatewayProxyResponse{}
198 apigwResp := apiGatewayProxyResponse{}
189199 apigwResp.Body = `{"error":"yes"}`
190200 apigwResp.StatusCode = 500
191201 resp, err := json.Marshal(apigwResp)
194204 )
195205
196206 ctx := context.Background()
197 req, _ := json.Marshal(events.APIGatewayProxyRequest{
207 req, _ := json.Marshal(apiGatewayProxyRequest{
198208 Body: `{"name":"john doe"}`,
199209 })
200210 resp, err := helloHandler.Invoke(ctx, req)
203213 t.Fatalf("Should have no error, but got: %+v", err)
204214 }
205215
206 apigwResp := events.APIGatewayProxyResponse{}
216 apigwResp := apiGatewayProxyResponse{}
207217 json.Unmarshal(resp, &apigwResp)
208218 if apigwResp.StatusCode != 500 {
209219 t.Fatalf("Expect status code of 500, instead of %d", apigwResp.StatusCode)
243253 err error,
244254 ) ([]byte, error) {
245255 // convert error into proper APIGateway response.
246 apigwResp := events.APIGatewayProxyResponse{}
256 apigwResp := apiGatewayProxyResponse{}
247257 apigwResp.Body = `{"error":"yes"}`
248258 apigwResp.StatusCode = 500
249259 resp, err := json.Marshal(apigwResp)
252262 )
253263
254264 ctx := context.Background()
255 req, _ := json.Marshal(events.APIGatewayProxyRequest{
265 req, _ := json.Marshal(apiGatewayProxyRequest{
256266 Body: `{"name":"john doe"}`,
257267 })
258268 resp, err := helloHandler.Invoke(ctx, req)
261271 t.Fatalf("Should have no error, but got: %+v", err)
262272 }
263273
264 apigwResp := events.APIGatewayProxyResponse{}
274 apigwResp := apiGatewayProxyResponse{}
265275 json.Unmarshal(resp, &apigwResp)
266276 if apigwResp.StatusCode != 500 {
267277 t.Fatalf("Expect status code of 500, instead of %d", apigwResp.StatusCode)
271281 func decodeHelloRequestWithTwoBefores(
272282 ctx context.Context, req []byte,
273283 ) (interface{}, error) {
274 apigwReq := events.APIGatewayProxyRequest{}
284 apigwReq := apiGatewayProxyRequest{}
275285 err := json.Unmarshal([]byte(req), &apigwReq)
276286 if err != nil {
277287 return apigwReq, err
302312 func encodeResponse(
303313 ctx context.Context, response interface{},
304314 ) ([]byte, error) {
305 apigwResp := events.APIGatewayProxyResponse{}
315 apigwResp := apiGatewayProxyResponse{}
306316
307317 mode, ok := ctx.Value(KeyEncMode).(string)
308318 if ok && mode == "fail_encode" {