From 5f7c284d58c0a774a1b5c13c5771e6ec76462413 Mon Sep 17 00:00:00 2001 From: aiordache Date: Wed, 29 Jul 2020 16:05:13 +0200 Subject: [PATCH] update delegation test to check all context types Signed-off-by: aiordache --- .vscode/launch.json | 19 ------------------- aci/backend.go | 3 +-- aci/context.go | 2 +- aci/resourcegroup.go | 8 ++++---- cli/mobycli/exec_test.go | 22 +++++++++++++++++++--- 5 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index ac2097b07..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Launch", - "type": "go", - "request": "launch", - "mode": "auto", - "program": "${workspaceRoot}/cli/main.go", - "env": {}, - "cwd": "${workspaceRoot}/test/", - //"args": ["context", "create", "aws", "ecs", --profile", "sandbox.devtools.developer", "--region", "eu-west-3", "--description", "My ECS account"] - "args":["compose", "up"] - } - ] -} \ No newline at end of file diff --git a/aci/backend.go b/aci/backend.go index abd8956bf..359d5ef64 100644 --- a/aci/backend.go +++ b/aci/backend.go @@ -41,9 +41,8 @@ import ( "github.com/docker/api/errdefs" ) -const backendType = store.AciContextType - const ( + backendType = store.AciContextType singleContainerTag = "docker-single-container" composeContainerTag = "docker-compose-application" composeContainerSeparator = "_" diff --git a/aci/context.go b/aci/context.go index f3923a096..86ade3a87 100644 --- a/aci/context.go +++ b/aci/context.go @@ -33,7 +33,7 @@ import ( type contextCreateACIHelper struct { selector prompt.UI - resourceGroupHelper ACIResourceGroupHelper + resourceGroupHelper ResourceGroupHelper } func newContextCreateHelper() contextCreateACIHelper { diff --git a/aci/resourcegroup.go b/aci/resourcegroup.go index 91a82ba89..d461936c2 100644 --- a/aci/resourcegroup.go +++ b/aci/resourcegroup.go @@ -26,8 +26,8 @@ import ( "github.com/docker/api/errdefs" ) -// ACIResourceGroupHelper interface to manage resource groups and subscription IDs -type ACIResourceGroupHelper interface { +// ResourceGroupHelper interface to manage resource groups and subscription IDs +type ResourceGroupHelper interface { GetSubscriptionIDs(ctx context.Context) ([]subscription.Model, error) ListGroups(ctx context.Context, subscriptionID string) ([]resources.Group, error) GetGroup(ctx context.Context, subscriptionID string, groupName string) (resources.Group, error) @@ -38,8 +38,8 @@ type ACIResourceGroupHelper interface { type aciResourceGroupHelperImpl struct { } -// NewACIResourceGroupHelper create a new ACIResourceGroupHelper -func NewACIResourceGroupHelper() ACIResourceGroupHelper { +// NewACIResourceGroupHelper create a new ResourceGroupHelper +func NewACIResourceGroupHelper() ResourceGroupHelper { return aciResourceGroupHelperImpl{} } diff --git a/cli/mobycli/exec_test.go b/cli/mobycli/exec_test.go index f9ab85efd..96e7cf103 100644 --- a/cli/mobycli/exec_test.go +++ b/cli/mobycli/exec_test.go @@ -6,6 +6,7 @@ import ( . "github.com/onsi/gomega" "github.com/stretchr/testify/suite" + "github.com/docker/api/context/store" "github.com/docker/api/tests/framework" ) @@ -14,9 +15,24 @@ type MobyExecSuite struct { } func (sut *MobyExecSuite) TestDelegateContextTypeToMoby() { - Expect(mustDelegateToMoby("moby")).To(BeTrue()) - Expect(mustDelegateToMoby("aws")).To(BeFalse()) - Expect(mustDelegateToMoby("aci")).To(BeFalse()) + + isDelegated := func(val string) bool { + for _, ctx := range delegatedContextTypes { + if ctx == val { + return true + } + } + return false + } + + allCtx := []string{store.AciContextType, store.EcsContextType, store.AwsContextType, store.DefaultContextType} + for _, ctx := range allCtx { + if isDelegated(ctx) { + Expect(mustDelegateToMoby(ctx)).To(BeTrue()) + continue + } + Expect(mustDelegateToMoby(ctx)).To(BeFalse()) + } } func TestExec(t *testing.T) {