-
Notifications
You must be signed in to change notification settings - Fork 0
/
env-source_test.go
44 lines (33 loc) · 915 Bytes
/
env-source_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
package confunc_test
import (
"github.com/alperkose/confunc"
"os"
"testing"
)
func Test_EnvSource(t *testing.T) {
expectedValue := "TEST_VALUE"
configurationKey := "TEST_PARAM"
os.Setenv(configurationKey, expectedValue)
var sut confunc.Source
sut = confunc.Env()
actualValue, err := sut.Value(configurationKey)
if err != nil {
t.Errorf("error should not have occurred : %v", err.Error())
}
if actualValue != expectedValue {
t.Errorf("expected %v to be %v", actualValue, expectedValue)
}
}
func Test_EnvSource_WhenTheConfigurationDoesNotExist(t *testing.T) {
expectedValue := ""
configurationKey := "TEST_NOT_EXISTING_PARAM"
var sut confunc.Source
sut = confunc.Env()
actualValue, err := sut.Value(configurationKey)
if err == nil {
t.Errorf("an error should have occurred")
}
if actualValue != expectedValue {
t.Errorf("expected %v to be %v", actualValue, expectedValue)
}
}