github.com/Foodji/aws-lambda-go@v1.20.2/events/appsync_test.go (about)

     1  package events
     2  
     3  import (
     4  	"encoding/json"
     5  	"io/ioutil"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestAppSyncResolverTemplate_invoke(t *testing.T) {
    12  	inputJSON, err := ioutil.ReadFile("./testdata/appsync-invoke.json")
    13  	if err != nil {
    14  		t.Errorf("could not open test file. details: %v", err)
    15  	}
    16  
    17  	var inputEvent AppSyncResolverTemplate
    18  	if err = json.Unmarshal(inputJSON, &inputEvent); err != nil {
    19  		t.Errorf("could not unmarshal event. details: %v", err)
    20  	}
    21  	assert.Equal(t, OperationInvoke, inputEvent.Operation)
    22  
    23  	outputJSON, err := json.Marshal(inputEvent)
    24  	if err != nil {
    25  		t.Errorf("could not marshal event. details: %v", err)
    26  	}
    27  
    28  	assert.JSONEq(t, string(inputJSON), string(outputJSON))
    29  }
    30  
    31  func TestAppSyncResolverTemplate_batchinvoke(t *testing.T) {
    32  	inputJSON, err := ioutil.ReadFile("./testdata/appsync-batchinvoke.json")
    33  	if err != nil {
    34  		t.Errorf("could not open test file. details: %v", err)
    35  	}
    36  
    37  	var inputEvent AppSyncResolverTemplate
    38  	if err = json.Unmarshal(inputJSON, &inputEvent); err != nil {
    39  		t.Errorf("could not unmarshal event. details: %v", err)
    40  	}
    41  	assert.Equal(t, OperationBatchInvoke, inputEvent.Operation)
    42  
    43  	outputJSON, err := json.Marshal(inputEvent)
    44  	if err != nil {
    45  		t.Errorf("could not marshal event. details: %v", err)
    46  	}
    47  
    48  	assert.JSONEq(t, string(inputJSON), string(outputJSON))
    49  }
    50  
    51  func TestAppSyncIdentity_IAM(t *testing.T) {
    52  	inputJSON, err := ioutil.ReadFile("./testdata/appsync-identity-iam.json")
    53  	if err != nil {
    54  		t.Errorf("could not open test file. details: %v", err)
    55  	}
    56  
    57  	var inputIdentity AppSyncIAMIdentity
    58  	if err = json.Unmarshal(inputJSON, &inputIdentity); err != nil {
    59  		t.Errorf("could not unmarshal identity. details: %v", err)
    60  	}
    61  
    62  	outputJSON, err := json.Marshal(inputIdentity)
    63  	if err != nil {
    64  		t.Errorf("could not marshal identity. details: %v", err)
    65  	}
    66  
    67  	assert.JSONEq(t, string(inputJSON), string(outputJSON))
    68  }
    69  
    70  func TestAppSyncIdentity_Cognito(t *testing.T) {
    71  	inputJSON, err := ioutil.ReadFile("./testdata/appsync-identity-cognito.json")
    72  	if err != nil {
    73  		t.Errorf("could not open test file. details: %v", err)
    74  	}
    75  
    76  	var inputIdentity AppSyncCognitoIdentity
    77  	if err = json.Unmarshal(inputJSON, &inputIdentity); err != nil {
    78  		t.Errorf("could not unmarshal identity. details: %v", err)
    79  	}
    80  
    81  	outputJSON, err := json.Marshal(inputIdentity)
    82  	if err != nil {
    83  		t.Errorf("could not marshal identity. details: %v", err)
    84  	}
    85  
    86  	assert.JSONEq(t, string(inputJSON), string(outputJSON))
    87  }