-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
53 lines (40 loc) · 1.42 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 (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMain(t *testing.T) {
http.DefaultServeMux = new(http.ServeMux)
mockExtensionsApi := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"eventType": "SHUTDOWN"}`)
}))
defer mockExtensionsApi.Close()
t.Setenv("AWS_LAMBDA_RUNTIME_API", strings.Join(strings.Split(mockExtensionsApi.URL, ":")[1:], ":")[2:])
main()
}
func TestMainDebug(t *testing.T) {
http.DefaultServeMux = new(http.ServeMux)
mockExtensionsApi := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"eventType": "SHUTDOWN"}`)
}))
defer mockExtensionsApi.Close()
t.Setenv("AWS_LAMBDA_RUNTIME_API", strings.Join(strings.Split(mockExtensionsApi.URL, ":")[1:], ":")[2:])
t.Setenv("FIRETAIL_EXTENSION_DEBUG", "true")
main()
}
func TestMainReturnsInNoLessThan500Milliseconds(t *testing.T) {
http.DefaultServeMux = new(http.ServeMux)
mockExtensionsApi := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"eventType": "SHUTDOWN"}`)
}))
defer mockExtensionsApi.Close()
t.Setenv("AWS_LAMBDA_RUNTIME_API", strings.Join(strings.Split(mockExtensionsApi.URL, ":")[1:], ":")[2:])
startTime := time.Now()
main()
assert.Greater(t, time.Since(startTime), 500*time.Millisecond)
}