Add tests for probe/cri/registry

Unhappy path tests try to cover three scenarios:

- When the endpoint URL scheme is not explicitly supported e.g. HTTP
- When the endpoint URL scheme is TCP which is also not supported
- When the fail to parse the given URL (to extract the scheme)

The happy path covers two scenarios:

- When we specify the supported scheme in the URL which is an unix
socket e.g. unix///var/run/dockershim.sock
- When we pass a socket address but fail to specify the scheme but our registry attempts
to use the fallback protocol e.g. var/run/dockershim.sock
This commit is contained in:
gotjosh
2018-11-01 20:17:03 +00:00
parent c70c90d2a7
commit beeb27810c

View File

@@ -7,15 +7,36 @@ import (
"github.com/weaveworks/scope/probe/cri"
)
func TestParseHttpEndpointUrl(t *testing.T) {
_, err := cri.NewCRIClient("http://xyz.com")
assert.Equal(t, "protocol \"http\" not supported", err.Error())
var nonUnixSocketsTest = []struct {
endpoint string
errorMessage string
}{
{"http://xyz.com", "protocol \"http\" not supported"},
{"tcp://var/unix.sock", "endpoint was not unix socket tcp"},
{"http://[fe80::%31]/", "parse http://[fe80::%31]/: invalid URL escape \"%31\""},
}
func TestParseTcpEndpointUrl(t *testing.T) {
client, err := cri.NewCRIClient("127.0.0.1")
func TestParseNonUnixEndpointUrl(t *testing.T) {
for _, tt := range nonUnixSocketsTest {
_, err := cri.NewCRIClient(tt.endpoint)
assert.Equal(t, tt.errorMessage, err.Error())
}
}
var unixSocketsTest = []string{
"127.0.0.1", // tests the fallback endpoint
"unix://127.0.0.1",
"unix///var/run/dockershim.sock",
"var/run/dockershim.sock",
}
func TestParseUnixEndpointUrl(t *testing.T) {
for _, tt := range unixSocketsTest {
client, err := cri.NewCRIClient(tt)
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, client)
}
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, client)
}