-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_test.go
60 lines (50 loc) · 1.5 KB
/
string_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
package confunc_test
import (
"errors"
"github.com/alperkose/confunc"
"testing"
)
func Test_StringFunc(t *testing.T) {
expectedValue := "some param"
configurationKey := "myConfig"
configUnderTest := confunc.
From(confunc.Map(map[string]string{configurationKey: expectedValue})).
String(configurationKey)
actualValue := configUnderTest()
if actualValue != expectedValue {
t.Errorf("expected '%v' to be '%v'", actualValue, expectedValue)
}
}
func Test_StringFunc_WhenAnInterceptorIsProvided(t *testing.T) {
configurationValue := "some param"
postfix := "Wrapped"
expectedValue := configurationValue + postfix
configurationKey := "myConfig"
configUnderTest := confunc.
From(confunc.Map(map[string]string{configurationKey: configurationValue})).
String(configurationKey, func(v confunc.Confunc) confunc.Confunc {
return func() (string, error) {
val, _ := v()
return val + postfix, nil
}
})
actualValue := configUnderTest()
if actualValue != expectedValue {
t.Errorf("expected '%v' to be '%v'", actualValue, expectedValue)
}
}
func Test_StringFunc_WhenSourceReturnedAnError(t *testing.T) {
expectedValue := ""
configurationKey := "myConfig"
configUnderTest := confunc.
From(&errorSource{}).
String(configurationKey)
actualValue := configUnderTest()
if actualValue != expectedValue {
t.Errorf("expected '%v' to be '%v'", actualValue, expectedValue)
}
}
type errorSource struct{}
func (s *errorSource) Value(k string) (string, error) {
return "", errors.New("Yassak")
}