test: added the first test
I am not very good at unit testing but we need to start writing them
This commit is contained in:
parent
38f610bdec
commit
a2bb0ed027
|
@ -0,0 +1,52 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue