-
Notifications
You must be signed in to change notification settings - Fork 27
/
event_test.go
49 lines (43 loc) · 975 Bytes
/
event_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
package config
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReadEnv(t *testing.T) {
const existingKey = "EXISTING_KEY"
const existingValue = "existing"
const unexistingKey = "UNEXISTING_KEY"
const defaultValue = "default"
type TestCaseGiven struct {
Key string
DefaultValue string
}
type TestCaseExpected string
type TestCase struct {
Given TestCaseGiven
Expected TestCaseExpected
}
var testCases = []TestCase{
{
Given: TestCaseGiven{
Key: existingKey,
DefaultValue: defaultValue,
},
Expected: existingValue,
},
{
Given: TestCaseGiven{
Key: unexistingKey,
DefaultValue: defaultValue,
},
Expected: defaultValue,
},
}
os.Unsetenv(unexistingKey)
os.Setenv(existingKey, existingValue)
for _, testCase := range testCases {
result := readEnv(testCase.Given.Key, testCase.Given.DefaultValue)
assert.Equal(t, string(testCase.Expected), result)
}
}