-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_test.go
125 lines (111 loc) · 2.55 KB
/
env_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package env
import (
"testing"
)
func TestEnvironmentString(t *testing.T) {
tests := []struct {
env Environment
expected string
}{
{PROD, "Production"},
{STAGE, "Staging"},
{DEV, "Development"},
{"UNKNOWN", "Unknown"},
{"", "Unknown"}, // Edge case: empty string
}
for _, test := range tests {
result := test.env.String()
if result != test.expected {
t.Errorf("For env %v, expected %s, got %s", test.env, test.expected, result)
}
}
}
func TestIsDev(t *testing.T) {
tests := []struct {
env Environment
expected bool
}{
{DEV, true},
{PROD, false},
{STAGE, false},
{"UNKNOWN", false},
{"", false}, // Edge case: empty string
}
for _, test := range tests {
result := test.env.IsDev()
if result != test.expected {
t.Errorf("For env %v, expected IsDev to be %v, got %v", test.env, test.expected, result)
}
}
}
func TestIsStage(t *testing.T) {
tests := []struct {
env Environment
expected bool
}{
{STAGE, true},
{DEV, false},
{PROD, false},
{"UNKNOWN", false},
{"", false}, // Edge case: empty string
}
for _, test := range tests {
result := test.env.IsStage()
if result != test.expected {
t.Errorf("For env %v, expected IsStage to be %v, got %v", test.env, test.expected, result)
}
}
}
func TestIsProd(t *testing.T) {
tests := []struct {
env Environment
expected bool
}{
{PROD, true},
{STAGE, false},
{DEV, false},
{"UNKNOWN", false},
{"", false}, // Edge case: empty string
}
for _, test := range tests {
result := test.env.IsProd()
if result != test.expected {
t.Errorf("For env %v, expected IsProd to be %v, got %v", test.env, test.expected, result)
}
}
}
func TestParse(t *testing.T) {
tests := []struct {
input string
expected Environment
}{
{"PROD", PROD},
{"production", PROD},
{"STAGE", STAGE},
{"staging", STAGE},
{"DEV", DEV},
{"development", DEV},
{"invalid", PROD}, // default case
{"", PROD}, // Edge case: empty string
}
for _, test := range tests {
result := Parse(test.input)
if result != test.expected {
t.Errorf("For input %s, expected %v, got %v", test.input, test.expected, result)
}
}
}
func TestSetAndCurrent(t *testing.T) {
environments := []Environment{DEV, STAGE, PROD}
for _, env := range environments {
Set(env)
if Current() != env {
t.Errorf("Expected current environment to be %v, got %v", env, Current())
}
}
// Edge case: setting an unknown environment
Set("UNKNOWN")
if Current() != "UNKNOWN" {
t.Errorf("Expected current environment to be UNKNOWN, got %v", Current())
}
}