forked from open-horizon/anax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
67 lines (55 loc) · 2.23 KB
/
config_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
// +build unit
package config
import (
"os"
"testing"
)
func Test_enrichFromEnvvars_success(t *testing.T) {
// to be enriched
config := HorizonConfig{
Edge: Config{
ExchangeURL: "goo",
FileSyncService: FSSConfig{
CSSURL: "https://mycomp/css/",
},
},
AgreementBot: AGConfig{
ExchangeURL: "zoo",
},
}
// Save the current env var value for restoration at the end.
saveEURL := os.Getenv(ExchangeURLEnvvarName)
saveCSSURL := os.Getenv(FileSyncServiceCSSURLEnvvarName)
restore := func() {
// Restore the env var to what it was at the beginning of the test
if err := os.Setenv(ExchangeURLEnvvarName, saveEURL); err != nil {
t.Errorf("Failed to set envvar in test environment. Error: %v", err)
}
if err := os.Setenv(FileSyncServiceCSSURLEnvvarName, saveCSSURL); err != nil {
t.Errorf("Failed to set envvar in test environment. Error: %v", err)
}
}
defer restore()
// Clear it for the test
if err := os.Unsetenv(ExchangeURLEnvvarName); err != nil {
t.Errorf("Failed to clear %v for test environment. Error: %v", ExchangeURLEnvvarName, err)
}
if err := os.Unsetenv(FileSyncServiceCSSURLEnvvarName); err != nil {
t.Errorf("Failed to clear %v for test environment. Error: %v", FileSyncServiceCSSURLEnvvarName, err)
}
// test that there is no error produced by enriching w/ an unset exchange URL value until the time that we require it
if err := enrichFromEnvvars(&config); err != nil || config.Edge.ExchangeURL != "goo" || config.AgreementBot.ExchangeURL != "zoo" || config.Edge.FileSyncService.CSSURL != "https://mycomp/css/" {
t.Errorf("Config enrichment failed passthrough test")
}
exVal := "fooozzzzz"
exCSSUTL := "edge.cssurl"
if err := os.Setenv(ExchangeURLEnvvarName, exVal); err != nil {
t.Errorf("Failed to set envvar in test environment. Error: %v", err)
}
if err := os.Setenv(FileSyncServiceCSSURLEnvvarName, exCSSUTL); err != nil {
t.Errorf("Failed to set envvar in test environment. Error: %v", err)
}
if err := enrichFromEnvvars(&config); err != nil || config.Edge.ExchangeURL != exVal || config.AgreementBot.ExchangeURL != exVal || config.Edge.FileSyncService.CSSURL != exCSSUTL {
t.Errorf("Config enrichment did not set exchange URL or File Sync Server css url from envvar as expected")
}
}