Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunderl committed Apr 26, 2020
1 parent 2f0b3b8 commit af087e4
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions sample-apps/blank-go/function/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ import (
"os"
"encoding/json"
"time"
"context"
"testing"
"strings"
"context"
"testing"
"strings"
"io/ioutil"
"github.com/aws/aws-lambda-go/lambdacontext"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambdacontext"
"github.com/aws/aws-lambda-go/events"
)

func TestMain(t *testing.T) {
d := time.Now().Add(50 * time.Millisecond)
os.Setenv("AWS_LAMBDA_FUNCTION_NAME","blank-go")
ctx, _ := context.WithDeadline(context.Background(), d)
ctx = lambdacontext.NewContext(ctx, &lambdacontext.LambdaContext{
AwsRequestID: "495b12a8-xmpl-4eca-8168-160484189f99",
InvokedFunctionArn: "arn:aws:lambda:us-east-2:123456789012:function:blank-go",
})
inputJson := ReadJSONFromFile(t, "../event.json")
var event events.SQSEvent
err := json.Unmarshal(inputJson, &event)
if err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}
//var inputEvent SQSEvent
result, err := handleRequest(ctx, event)
if err != nil {
t.Log(err)
}
t.Log(result)
if !strings.Contains(result, "FunctionCount") {
t.Errorf("Output does not contain FunctionCode.")
}
d := time.Now().Add(50 * time.Millisecond)
os.Setenv("AWS_LAMBDA_FUNCTION_NAME","blank-go")
ctx, _ := context.WithDeadline(context.Background(), d)
ctx = lambdacontext.NewContext(ctx, &lambdacontext.LambdaContext{
AwsRequestID: "495b12a8-xmpl-4eca-8168-160484189f99",
InvokedFunctionArn: "arn:aws:lambda:us-east-2:123456789012:function:blank-go",
})
inputJson := ReadJSONFromFile(t, "../event.json")
var event events.SQSEvent
err := json.Unmarshal(inputJson, &event)
if err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}
//var inputEvent SQSEvent
result, err := handleRequest(ctx, event)
if err != nil {
t.Log(err)
}
t.Log(result)
if !strings.Contains(result, "FunctionCount") {
t.Errorf("Output does not contain FunctionCode.")
}
}
func ReadJSONFromFile(t *testing.T, inputFile string) []byte {
inputJSON, err := ioutil.ReadFile(inputFile)
Expand Down

0 comments on commit af087e4

Please sign in to comment.