test: increatse client/context.go coverage to 90%

This commit is contained in:
knoflook 2021-10-16 11:41:28 +02:00
parent 0615c3f745
commit 78460ac0ba
Signed by: knoflook
GPG Key ID: D6A1D0E8FC4FEF1C
2 changed files with 28 additions and 0 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ abra
vendor/
.envrc
dist/
*fmtcoverage.html

View File

@ -30,6 +30,33 @@ func dockerContext(host, key string) TestContext {
}
}
func TestCreateContext(t *testing.T) {
err := client.CreateContext("testCreate", "wronguser", "wrongport")
if err == nil {
t.Error("client.CreateContext(\"testCreate\", \"wronguser\", \"wrongport\") should have failed but didn't return an error")
}
err = client.CreateContext("testCreate", "", "")
if err != nil {
t.Errorf("Couldn't create context: %s", err)
}
}
func TestDeleteContext(t *testing.T) {
err := client.DeleteContext("default")
if err == nil {
t.Errorf("client.DeleteContext(\"default\") should have failed but didn't return an error")
}
err = client.DeleteContext("testCreate")
if err != nil {
t.Errorf("client.DeleteContext(\"testCreate\") failed: %s", err)
}
err = client.DeleteContext("testCreate")
if err == nil {
t.Errorf("client.DeleteContext(\"testCreate\") should have failed this time (attempt to delete non-existent context) but didn't return an error")
}
}
func TestGetContextEndpoint(t *testing.T) {
var testDockerContexts = []TestContext{
dockerContext("ssh://foobar", "docker"),