|
5 | 5 | "io/ioutil"
|
6 | 6 | "testing"
|
7 | 7 |
|
| 8 | + "github.com/aws/aws-lambda-go/events/test" |
8 | 9 | "github.com/stretchr/testify/assert"
|
9 | 10 | )
|
10 | 11 |
|
@@ -85,3 +86,49 @@ func TestAppSyncIdentity_Cognito(t *testing.T) {
|
85 | 86 |
|
86 | 87 | assert.JSONEq(t, string(inputJSON), string(outputJSON))
|
87 | 88 | }
|
| 89 | + |
| 90 | +func TestAppSyncLambdaAuthorizerRequestMarshalling(t *testing.T) { |
| 91 | + inputJSON, err := ioutil.ReadFile("./testdata/appsync-lambda-auth-request.json") |
| 92 | + if err != nil { |
| 93 | + t.Errorf("could not open test file. details: %v", err) |
| 94 | + } |
| 95 | + |
| 96 | + var inputEvent AppSyncLambdaAuthorizerRequest |
| 97 | + if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { |
| 98 | + t.Errorf("could not unmarshal event. details: %v", err) |
| 99 | + } |
| 100 | + |
| 101 | + outputJSON, err := json.Marshal(inputEvent) |
| 102 | + if err != nil { |
| 103 | + t.Errorf("could not marshal event. details: %v", err) |
| 104 | + } |
| 105 | + |
| 106 | + assert.JSONEq(t, string(inputJSON), string(outputJSON)) |
| 107 | +} |
| 108 | + |
| 109 | +func TestAppSyncLambdaAuthorizerRequestMalformedJson(t *testing.T) { |
| 110 | + test.TestMalformedJson(t, AppSyncLambdaAuthorizerRequest{}) |
| 111 | +} |
| 112 | + |
| 113 | +func TestAppSyncLambdaAuthorizerResponseMarshalling(t *testing.T) { |
| 114 | + inputJSON, err := ioutil.ReadFile("./testdata/appsync-lambda-auth-response.json") |
| 115 | + if err != nil { |
| 116 | + t.Errorf("could not open test file. details: %v", err) |
| 117 | + } |
| 118 | + |
| 119 | + var inputEvent AppSyncLambdaAuthorizerResponse |
| 120 | + if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { |
| 121 | + t.Errorf("could not unmarshal event. details: %v", err) |
| 122 | + } |
| 123 | + |
| 124 | + outputJSON, err := json.Marshal(inputEvent) |
| 125 | + if err != nil { |
| 126 | + t.Errorf("could not marshal event. details: %v", err) |
| 127 | + } |
| 128 | + |
| 129 | + assert.JSONEq(t, string(inputJSON), string(outputJSON)) |
| 130 | +} |
| 131 | + |
| 132 | +func TestAppSyncLambdaAuthorizerResponseMalformedJson(t *testing.T) { |
| 133 | + test.TestMalformedJson(t, AppSyncLambdaAuthorizerResponse{}) |
| 134 | +} |
0 commit comments