forked from coop-cloud/abra
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package client_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"coopcloud.tech/abra/client"
|
|
dContext "github.com/docker/cli/cli/context"
|
|
dCliContextStore "github.com/docker/cli/cli/context/store"
|
|
)
|
|
|
|
type TestContext struct {
|
|
context dCliContextStore.Metadata
|
|
expected_endpoint string
|
|
}
|
|
|
|
func dockerContext(host, key string) TestContext {
|
|
dockerContext := dCliContextStore.Metadata{
|
|
Name: "foo",
|
|
Metadata: nil,
|
|
Endpoints: map[string]interface{}{
|
|
key: dContext.EndpointMetaBase{
|
|
Host: host,
|
|
SkipTLSVerify: false,
|
|
},
|
|
},
|
|
}
|
|
return TestContext{
|
|
context: dockerContext,
|
|
expected_endpoint: host,
|
|
}
|
|
}
|
|
|
|
func TestGetContextEndpoint(t *testing.T) {
|
|
var testDockerContexts = []TestContext{
|
|
dockerContext("ssh://foobar", "docker"),
|
|
dockerContext("ssh://foobar", "k8"),
|
|
}
|
|
for _, context := range testDockerContexts {
|
|
endpoint, err := client.GetContextEndpoint(context.context)
|
|
if err != nil {
|
|
if err.Error() != "context lacks Docker endpoint" {
|
|
t.Error(err)
|
|
}
|
|
} else {
|
|
if endpoint != context.expected_endpoint {
|
|
t.Errorf("did not get correct context endpoint. Expected: %s, received: %s", context.expected_endpoint, endpoint)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|