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

     1  // Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
     2  
     3  package events
     4  
     5  import (
     6  	"encoding/json"
     7  	"testing"
     8  
     9  	"github.com/aws/aws-lambda-go/events/test"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestS3BatchJobEventMarshaling(t *testing.T) {
    14  
    15  	// 1. read JSON from file
    16  	inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request.json")
    17  
    18  	// 2. de-serialize into Go object
    19  	var inputEvent S3BatchJobEvent
    20  	if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
    21  		t.Errorf("could not unmarshal event. details: %v", err)
    22  	}
    23  
    24  	// 3. serialize to JSON
    25  	outputJSON, err := json.Marshal(inputEvent)
    26  	if err != nil {
    27  		t.Errorf("could not marshal event. details: %v", err)
    28  	}
    29  
    30  	// 4. check result
    31  	assert.JSONEq(t, string(inputJSON), string(outputJSON))
    32  }
    33  
    34  func TestS3BatchJobResponseMarshaling(t *testing.T) {
    35  
    36  	// 1. read JSON from file
    37  	inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-response.json")
    38  
    39  	// 2. de-serialize into Go object
    40  	var inputEvent S3BatchJobResponse
    41  	if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
    42  		t.Errorf("could not unmarshal event. details: %v", err)
    43  	}
    44  
    45  	// 3. serialize to JSON
    46  	outputJSON, err := json.Marshal(inputEvent)
    47  	if err != nil {
    48  		t.Errorf("could not marshal event. details: %v", err)
    49  	}
    50  
    51  	// 4. check result
    52  	assert.JSONEq(t, string(inputJSON), string(outputJSON))
    53  }