-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathwrapper_test.go
More file actions
65 lines (55 loc) · 1.54 KB
/
wrapper_test.go
File metadata and controls
65 lines (55 loc) · 1.54 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package lambda
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestExecAwsLambdaExecWrapperNotSet(t *testing.T) {
var called bool
callback := func() { called = true }
exec, execCalled := mockExec(t, "<nope>")
execAWSLambdaExecWrapper(
mockedGetenv(t, ""),
exec,
[]func(){callback},
)
require.False(t, *execCalled)
require.False(t, called)
}
func TestExecAwsLambdaExecWrapperSet(t *testing.T) {
var called bool
callback := func() { called = true }
wrapper := "/path/to/wrapper/entry/point"
exec, execCalled := mockExec(t, wrapper)
execAWSLambdaExecWrapper(
mockedGetenv(t, wrapper),
exec,
[]func(){callback},
)
require.True(t, *execCalled)
require.True(t, called)
}
func mockExec(t *testing.T, value string) (mock func(string, []string, []string) error, called *bool) {
mock = func(argv0 string, argv []string, envv []string) error {
*called = true
require.Equal(t, value, argv0)
require.Equal(t, append([]string{value}, os.Args...), argv)
require.Equal(t, awsLambdaExecWrapper+"=", envv[len(envv)-1])
return nil
}
called = ptrTo(false)
return
}
func mockedGetenv(t *testing.T, value string) func(string) string {
return func(key string) string {
require.Equal(t, awsLambdaExecWrapper, key)
return value
}
}
func ptrTo(val bool) *bool {
return &val
}