Add proxy env test (#1569)
This commit is contained in:
parent
d62ae23a9c
commit
edee3b6765
@ -2,6 +2,7 @@ package net
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,3 +25,39 @@ func TestListen(t *testing.T) {
|
|||||||
// Expect addr DO NOT has extra ":" at the end!
|
// Expect addr DO NOT has extra ":" at the end!
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestProxyEnv checks whether we have proxy/network settings in env
|
||||||
|
func TestProxyEnv(t *testing.T) {
|
||||||
|
service := "foo"
|
||||||
|
address := []string{"bar"}
|
||||||
|
|
||||||
|
s, a, ok := Proxy(service, address)
|
||||||
|
if ok {
|
||||||
|
t.Fatal("Should not have proxy", s, a, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
test := func(key, val, expectSrv, expectAddr string) {
|
||||||
|
// set env
|
||||||
|
os.Setenv(key, val)
|
||||||
|
|
||||||
|
s, a, ok := Proxy(service, address)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("Expected proxy")
|
||||||
|
}
|
||||||
|
if len(expectSrv) > 0 && s != expectSrv {
|
||||||
|
t.Fatal("Expected proxy service", expectSrv, "got", s)
|
||||||
|
}
|
||||||
|
if len(expectAddr) > 0 {
|
||||||
|
if len(a) == 0 || a[0] != expectAddr {
|
||||||
|
t.Fatal("Expected proxy address", expectAddr, "got", a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Unsetenv(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
test("MICRO_PROXY", "service", "go.micro.proxy", "")
|
||||||
|
test("MICRO_PROXY_ADDRESS", "10.0.0.1:8080", "", "10.0.0.1:8080")
|
||||||
|
test("MICRO_NETWORK", "service", "go.micro.network", "")
|
||||||
|
test("MICRO_NETWORK_ADDRESS", "10.0.0.1:8081", "", "10.0.0.1:8081")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user