-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
53 lines (47 loc) · 1.09 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"testing"
"github.com/aws/aws-lambda-go/events"
)
func TestHandler(t *testing.T) {
// Define test cases
testCases := []struct {
input events.APIGatewayProxyRequest
expected string
shouldError bool
}{
// Test Case 1: Valid input
{
input: events.APIGatewayProxyRequest{
QueryStringParameters: map[string]string{
"name": "John",
},
},
expected: "Hello John!",
shouldError: false,
},
}
// Iterate over test cases
for _, tc := range testCases {
t.Run("Test Handler", func(t *testing.T) {
// Call the handler function with the test input
response, err := handler(context.Background(), tc.input)
if tc.shouldError {
// Ensure an error occurred
if err == nil {
t.Errorf("Expected an error, but got nil")
}
} else {
// Ensure no error occurred
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
// Ensure the response matches the expected result
if response.Body != tc.expected {
t.Errorf("Expected %s, but got %s", tc.expected, response.Body)
}
}
})
}
}