Added error handler for empty runtime entry
If there is no container runtime defined in the airshipctl config then the error message is not clear. New handler shows specific error description Change-Id: Ib5b735ddaa1556a8a88fdb15c4b3942cd010db9b
This commit is contained in:
parent
f555af3bf6
commit
611d73a2ee
@ -37,6 +37,8 @@ type Container interface {
|
||||
// * docker
|
||||
func NewContainer(ctx *context.Context, driver string, url string) (Container, error) {
|
||||
switch driver {
|
||||
case "":
|
||||
return nil, ErrNoContainerDriver{}
|
||||
case "docker":
|
||||
cli, err := NewDockerClient(ctx)
|
||||
if err != nil {
|
||||
|
@ -16,20 +16,25 @@ package container
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
ctx := context.Background()
|
||||
_, actualErr := NewContainer(&ctx, "test_drv", "")
|
||||
expectedErr := ErrContainerDrvNotSupported{Driver: "test_drv"}
|
||||
errS := fmt.Sprintf(
|
||||
"Call NewContainer should have returned error %s, got %s",
|
||||
expectedErr,
|
||||
actualErr,
|
||||
)
|
||||
assert.Equal(t, actualErr, expectedErr, errS)
|
||||
|
||||
t.Run("not-supported-container", func(t *testing.T) {
|
||||
cnt, err := NewContainer(&ctx, "test_drv", "")
|
||||
assert.Equal(nil, cnt)
|
||||
assert.Equal(ErrContainerDrvNotSupported{Driver: "test_drv"}, err)
|
||||
})
|
||||
|
||||
t.Run("empty-container", func(t *testing.T) {
|
||||
cnt, err := NewContainer(&ctx, "", "")
|
||||
assert.Equal(nil, cnt)
|
||||
assert.Equal(ErrNoContainerDriver{}, err)
|
||||
})
|
||||
}
|
||||
|
@ -44,3 +44,11 @@ type ErrContainerDrvNotSupported struct {
|
||||
func (e ErrContainerDrvNotSupported) Error() string {
|
||||
return fmt.Sprintf("Driver %s is not supported", e.Driver)
|
||||
}
|
||||
|
||||
// ErrNoContainerDriver returned if no runtime defined in config
|
||||
type ErrNoContainerDriver struct {
|
||||
}
|
||||
|
||||
func (e ErrNoContainerDriver) Error() string {
|
||||
return fmt.Sprintf("container runtime is not defined in airshipctl config")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user