...
1 package entrypoint
2
3 import (
4 "os"
5 "testing"
6
7 "github.com/stretchr/testify/assert"
8 )
9
10 func TestGetEnvoyFlags(t *testing.T) {
11 foundFlag := false
12 foundValue := false
13
14 os.Setenv("ENVOY_CONCURRENCY", "4")
15
16 flags := GetEnvoyFlags()
17 for idx, flag := range flags {
18 if flag == "--concurrency" {
19 foundFlag = true
20 t.Logf("flags[idx] = %v", flags[idx])
21 if idx+1 < len(flags) && flags[idx+1] == "4" {
22 foundValue = true
23 }
24 break
25 }
26 }
27
28 os.Setenv("ENVOY_CONCURRENCY", "")
29
30 assert.True(t, foundFlag)
31 assert.True(t, foundValue)
32 }
33
34 func TestGetHealthCheckIPNetworkFamily(t *testing.T) {
35 type testCase struct {
36 description string
37 inputFamily string
38 expected string
39 }
40
41 testcases := []testCase{
42 {
43 description: "non-supported value",
44 inputFamily: "not-a-good-value",
45 expected: "tcp",
46 },
47 {
48 description: "ipv6 only",
49 inputFamily: "IPV6_ONLY",
50 expected: "tcp6",
51 },
52 {
53 description: "ipv4 only",
54 inputFamily: "IPV4_ONLY",
55 expected: "tcp4",
56 },
57 {
58 description: "case-insensitve",
59 inputFamily: "ipv4_oNly",
60 expected: "tcp4",
61 },
62 {
63 description: "env var not set",
64 inputFamily: "",
65 expected: "tcp",
66 },
67 }
68
69 for _, tc := range testcases {
70 t.Run(tc.description, func(t *testing.T) {
71 if tc.inputFamily != "" {
72 t.Setenv("AMBASSADOR_HEALTHCHECK_IP_FAMILY", tc.inputFamily)
73 }
74
75 result := getHealthCheckIPNetworkFamily()
76 assert.Equal(t, tc.expected, result)
77 })
78 }
79 }
80
View as plain text