|
| 1 | +package events |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "io/ioutil" //nolint: staticcheck |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/aws/aws-lambda-go/events/test" |
| 9 | +) |
| 10 | + |
| 11 | +func TestIoTPreProvisionHookRequest(t *testing.T) { |
| 12 | + |
| 13 | + // read json from file |
| 14 | + inputJSON, err := ioutil.ReadFile("./testdata/iot-preprovision-hook-request.json") |
| 15 | + if err != nil { |
| 16 | + t.Errorf("could not open test file. details: %v", err) |
| 17 | + } |
| 18 | + |
| 19 | + // de-serialize into Go object |
| 20 | + var inputEvent IoTPreProvisionHookRequest |
| 21 | + if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { |
| 22 | + t.Errorf("could not unmarshal event. details: %v", err) |
| 23 | + } |
| 24 | + |
| 25 | + // serialize to json |
| 26 | + outputJSON, err := json.Marshal(inputEvent) |
| 27 | + if err != nil { |
| 28 | + t.Errorf("could not marshal event. details: %v", err) |
| 29 | + } |
| 30 | + |
| 31 | + test.AssertJsonsEqual(t, inputJSON, outputJSON) |
| 32 | +} |
| 33 | + |
| 34 | +func TestIoTPreProvisionHookRequestMalformedJson(t *testing.T) { |
| 35 | + test.TestMalformedJson(t, IoTPreProvisionHookRequest{}) |
| 36 | +} |
| 37 | + |
| 38 | +func TestIoTPreProvisionHookResponseMarshaling(t *testing.T) { |
| 39 | + |
| 40 | + // read json from file |
| 41 | + inputJSON, err := ioutil.ReadFile("./testdata/iot-preprovision-hook-response.json") |
| 42 | + if err != nil { |
| 43 | + t.Errorf("could not open test file. details: %v", err) |
| 44 | + } |
| 45 | + |
| 46 | + // de-serialize into Go object |
| 47 | + var inputEvent IoTPreProvisionHookResponse |
| 48 | + if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { |
| 49 | + t.Errorf("could not unmarshal event. details: %v", err) |
| 50 | + } |
| 51 | + |
| 52 | + // serialize to json |
| 53 | + outputJSON, err := json.Marshal(inputEvent) |
| 54 | + if err != nil { |
| 55 | + t.Errorf("could not marshal event. details: %v", err) |
| 56 | + } |
| 57 | + |
| 58 | + test.AssertJsonsEqual(t, inputJSON, outputJSON) |
| 59 | +} |
| 60 | + |
| 61 | +func TestIoTPreProvisionHookResponseMalformedJson(t *testing.T) { |
| 62 | + test.TestMalformedJson(t, IoTPreProvisionHookResponse{}) |
| 63 | +} |
0 commit comments