-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetenv_test.go
More file actions
50 lines (46 loc) · 858 Bytes
/
getenv_test.go
File metadata and controls
50 lines (46 loc) · 858 Bytes
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
package gowebly
import (
"os"
"testing"
)
func TestGetenv(t *testing.T) {
// Set the needed env.
err := os.Setenv("GOWEBLY_HELPERS_TEST_1", "test")
if err != nil {
return
}
type args struct {
key string
fallback string
}
tests := []struct {
name string
args args
want string
}{
{
name: "env is found, not set fallback value",
args: args{
key: "GOWEBLY_HELPERS_TEST_1",
fallback: "fallback",
},
want: "test",
},
{
name: "env is not found, set fallback value",
args: args{
key: "GOWEBLY_HELPERS_TEST_2",
fallback: "fallback",
},
want: "fallback",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Getenv(tt.args.key, tt.args.fallback); got != tt.want {
t.Errorf("Getenv() = %v, want %v", got, tt.want)
}
})
}
os.Clearenv()
}