2017-04-12 19:26:15 +00:00
|
|
|
package config
|
2017-02-03 15:22:02 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-04-12 19:35:15 +00:00
|
|
|
func TestURLConfig(t *testing.T) {
|
2017-04-12 21:29:11 +00:00
|
|
|
u := NewURLConfig(EnvironmentOf(MapFetcher(map[string][]string{
|
|
|
|
"http.key": []string{"root"},
|
|
|
|
"http.https://host.com.key": []string{"host"},
|
|
|
|
"http.https://user@host.com/a.key": []string{"user-a"},
|
|
|
|
"http.https://user@host.com.key": []string{"user"},
|
|
|
|
"http.https://host.com/a.key": []string{"host-a"},
|
|
|
|
"http.https://host.com:8080.key": []string{"port"},
|
2017-04-12 19:26:15 +00:00
|
|
|
})))
|
2017-02-03 15:22:02 +00:00
|
|
|
|
|
|
|
tests := map[string]string{
|
|
|
|
"https://root.com/a/b/c": "root",
|
|
|
|
"https://host.com/": "host",
|
|
|
|
"https://host.com/a/b/c": "host-a",
|
|
|
|
"https://user:pass@host.com/a/b/c": "user-a",
|
|
|
|
"https://user:pass@host.com/z/b/c": "user",
|
|
|
|
"https://host.com:8080/a": "port",
|
|
|
|
}
|
|
|
|
|
|
|
|
for rawurl, expected := range tests {
|
2017-04-12 19:35:15 +00:00
|
|
|
value, _ := u.Get("http", "key", rawurl)
|
2017-02-03 15:22:02 +00:00
|
|
|
assert.Equal(t, expected, value, rawurl)
|
|
|
|
}
|
|
|
|
}
|