mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 03:49:52 +00:00
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
43 lines
941 B
Go
43 lines
941 B
Go
package cri_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/bmizerany/assert"
|
|
"github.com/weaveworks/scope/probe/cri"
|
|
)
|
|
|
|
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 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)
|
|
}
|
|
|
|
}
|