Skip to content

Commit

Permalink
fix context tests as kubernetes orchestrator has been removed
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Feb 18, 2022
1 parent be80af9 commit 1926be1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
13 changes: 8 additions & 5 deletions cli/command/context/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import (

// CreateOptions are the options used for creating a context
type CreateOptions struct {
Name string
Description string
Name string
Description string
Docker map[string]string
From string

// Deprecated
DefaultStackOrchestrator string
Docker map[string]string
Kubernetes map[string]string
From string
// Deprecated
Kubernetes map[string]string
}

func longCreateDescription() string {
Expand Down
8 changes: 6 additions & 2 deletions cli/command/context/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,18 @@ func TestCreateInvalids(t *testing.T) {
DefaultStackOrchestrator: "all",
Docker: map[string]string{},
},
expecterErr: `cannot specify orchestrator "all" without configuring a Kubernetes endpoint`,
expecterErr: "",
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.options.Name, func(t *testing.T) {
err := RunCreate(cli, &tc.options)
assert.ErrorContains(t, err, tc.expecterErr)
if tc.expecterErr == "" {
assert.NilError(t, err)
} else {
assert.ErrorContains(t, err, tc.expecterErr)
}
})
}
}
Expand Down
13 changes: 13 additions & 0 deletions cli/command/context/export-import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"testing"

"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/streams"
"gotest.tools/v3/assert"
)
Expand All @@ -19,6 +20,7 @@ func TestExportImportWithFile(t *testing.T) {
contextFile := filepath.Join(contextDir, "exported")
cli, cleanup := makeFakeCli(t)
defer cleanup()
createTestContext(t, cli)
cli.ErrBuffer().Reset()
assert.NilError(t, RunExport(cli, &ExportOptions{
ContextName: "test",
Expand All @@ -44,6 +46,7 @@ func TestExportImportWithFile(t *testing.T) {
func TestExportImportPipe(t *testing.T) {
cli, cleanup := makeFakeCli(t)
defer cleanup()
createTestContext(t, cli)
cli.ErrBuffer().Reset()
cli.OutBuffer().Reset()
assert.NilError(t, RunExport(cli, &ExportOptions{
Expand Down Expand Up @@ -80,3 +83,13 @@ func TestExportExistingFile(t *testing.T) {
err = RunExport(cli, &ExportOptions{ContextName: "test", Dest: contextFile})
assert.Assert(t, os.IsExist(err))
}

func createTestContext(t *testing.T, cli command.Cli) {
t.Helper()

err := RunCreate(cli, &CreateOptions{
Name: "test",
Docker: map[string]string{},
})
assert.NilError(t, err)
}

0 comments on commit 1926be1

Please sign in to comment.