/
fetcher_test.go
75 lines (57 loc) · 2.07 KB
/
fetcher_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
package config
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
//userConfig supplies user data for fetching user-specific configuration.
type userConfig struct {
}
func (uc *userConfig) GetToken() string {
return "token"
}
func (uc *userConfig) GetUserID() int64 {
return 10
}
// TestFetcher actually fetches a config file over the network.
func TestFetcher(t *testing.T) {
// This will actually fetch the cloud config over the network.
rt := &http.Transport{}
flags := make(map[string]interface{})
configFetcher := NewFetcher(&userConfig{}, rt, flags)
cfg := &Config{}
cfg.ApplyDefaults()
mutate, waitTime, err := configFetcher.pollForConfig(cfg)
assert.NoError(t, err)
assert.NotNil(t, mutate)
assert.NotNil(t, waitTime)
err = mutate(cfg)
assert.Nil(t, err)
}
// TestStagingSetup tests to make sure our staging config flag sets the
// appropriate URLs for staging servers.
func TestStagingSetup(t *testing.T) {
flags := make(map[string]interface{})
flags["staging"] = false
rt := &http.Transport{}
var fetch *fetcher
fetch = NewFetcher(&userConfig{}, rt, flags).(*fetcher)
assert.Equal(t, defaultChainedCloudConfigURL, fetch.chainedURL)
assert.Equal(t, defaultFrontedCloudConfigURL, fetch.frontedURL)
// Test that setting the URLs to use from the command line still works.
flags["cloudconfig"] = "testconfig"
flags["frontedconfig"] = "testconfig"
fetch = NewFetcher(&userConfig{}, rt, flags).(*fetcher)
assert.Equal(t, "testconfig", fetch.chainedURL)
assert.Equal(t, "testconfig", fetch.frontedURL)
// Blank flags should mean we use the default
flags["cloudconfig"] = ""
flags["frontedconfig"] = ""
fetch = NewFetcher(&userConfig{}, rt, flags).(*fetcher)
assert.Equal(t, defaultChainedCloudConfigURL, fetch.chainedURL)
assert.Equal(t, defaultFrontedCloudConfigURL, fetch.frontedURL)
flags["staging"] = true
fetch = NewFetcher(&userConfig{}, rt, flags).(*fetcher)
assert.Equal(t, "http://config-staging.getiantem.org/cloud.yaml.gz", fetch.chainedURL)
assert.Equal(t, "http://d33pfmbpauhmvd.cloudfront.net/cloud.yaml.gz", fetch.frontedURL)
}