Move pkg/kubelet/cri/remote to cri-client

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
Sascha Grunert
2024-03-06 14:52:20 +01:00
parent 4f04dffe5b
commit 2aa9e76be1
39 changed files with 891 additions and 473 deletions

View File

@@ -25,98 +25,6 @@ import (
"github.com/stretchr/testify/assert"
)
func TestParseEndpoint(t *testing.T) {
tests := []struct {
endpoint string
expectError bool
expectedProtocol string
expectedAddr string
}{
{
endpoint: "unix:///tmp/s1.sock",
expectedProtocol: "unix",
expectedAddr: "/tmp/s1.sock",
},
{
endpoint: "tcp://localhost:15880",
expectedProtocol: "tcp",
expectedAddr: "localhost:15880",
},
{
endpoint: "npipe://./pipe/mypipe",
expectedProtocol: "npipe",
expectError: true,
},
{
endpoint: "tcp1://abc",
expectedProtocol: "tcp1",
expectError: true,
},
{
endpoint: "a b c",
expectError: true,
},
}
for _, test := range tests {
protocol, addr, err := parseEndpoint(test.endpoint)
assert.Equal(t, test.expectedProtocol, protocol)
if test.expectError {
assert.NotNil(t, err, "Expect error during parsing %q", test.endpoint)
continue
}
assert.Nil(t, err, "Expect no error during parsing %q", test.endpoint)
assert.Equal(t, test.expectedAddr, addr)
}
}
func TestGetAddressAndDialer(t *testing.T) {
tests := []struct {
endpoint string
expectError bool
expectedAddr string
}{
{
endpoint: "unix:///tmp/s1.sock",
expectError: false,
expectedAddr: "/tmp/s1.sock",
},
{
endpoint: "unix:///tmp/f6.sock",
expectError: false,
expectedAddr: "/tmp/f6.sock",
},
{
endpoint: "tcp://localhost:9090",
expectError: true,
},
{
// The misspelling is intentional to make it error
endpoint: "htta://free-test.com",
expectError: true,
},
{
endpoint: "https://www.youtube.com/",
expectError: true,
},
{
endpoint: "http://www.baidu.com/",
expectError: true,
},
}
for _, test := range tests {
// just test addr and err
addr, _, err := GetAddressAndDialer(test.endpoint)
if test.expectError {
assert.NotNil(t, err, "expected error during parsing %s", test.endpoint)
continue
}
assert.Nil(t, err, "expected no error during parsing %s", test.endpoint)
assert.Equal(t, test.expectedAddr, addr)
}
}
func TestLocalEndpoint(t *testing.T) {
tests := []struct {
path string