-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Renaming DOCKER_ORCHESTRATOR to DOCKER_STACK_ORCHESTRATOR
* Renaming config file option "orchestrator" to "stackOrchestrator" * "--orchestrator" flag is no more global but local to stack command and subcommands * Cleaning all global orchestrator code * Replicating Hidden flags in help and Supported flags from root command to stack command Signed-off-by: Silvin Lubecki <[email protected]>
- Loading branch information
1 parent
8de0753
commit 0e358b6
Showing
22 changed files
with
317 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package command | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
cliconfig "github.com/docker/cli/cli/config" | ||
"github.com/docker/cli/cli/flags" | ||
"gotest.tools/assert" | ||
is "gotest.tools/assert/cmp" | ||
"gotest.tools/env" | ||
"gotest.tools/fs" | ||
) | ||
|
||
func TestOrchestratorSwitch(t *testing.T) { | ||
defaultVersion := "v0.00" | ||
|
||
var testcases = []struct { | ||
doc string | ||
configfile string | ||
envOrchestrator string | ||
flagOrchestrator string | ||
expectedOrchestrator string | ||
expectedKubernetes bool | ||
expectedSwarm bool | ||
}{ | ||
{ | ||
doc: "default", | ||
configfile: `{ | ||
}`, | ||
expectedOrchestrator: "swarm", | ||
expectedKubernetes: false, | ||
expectedSwarm: true, | ||
}, | ||
{ | ||
doc: "kubernetesConfigFile", | ||
configfile: `{ | ||
"stackOrchestrator": "kubernetes" | ||
}`, | ||
expectedOrchestrator: "kubernetes", | ||
expectedKubernetes: true, | ||
expectedSwarm: false, | ||
}, | ||
{ | ||
doc: "kubernetesEnv", | ||
configfile: `{ | ||
}`, | ||
envOrchestrator: "kubernetes", | ||
expectedOrchestrator: "kubernetes", | ||
expectedKubernetes: true, | ||
expectedSwarm: false, | ||
}, | ||
{ | ||
doc: "kubernetesFlag", | ||
configfile: `{ | ||
}`, | ||
flagOrchestrator: "kubernetes", | ||
expectedOrchestrator: "kubernetes", | ||
expectedKubernetes: true, | ||
expectedSwarm: false, | ||
}, | ||
{ | ||
doc: "allOrchestratorFlag", | ||
configfile: `{ | ||
}`, | ||
flagOrchestrator: "all", | ||
expectedOrchestrator: "all", | ||
expectedKubernetes: true, | ||
expectedSwarm: true, | ||
}, | ||
{ | ||
doc: "envOverridesConfigFile", | ||
configfile: `{ | ||
"stackOrchestrator": "kubernetes" | ||
}`, | ||
envOrchestrator: "swarm", | ||
expectedOrchestrator: "swarm", | ||
expectedKubernetes: false, | ||
expectedSwarm: true, | ||
}, | ||
{ | ||
doc: "flagOverridesEnv", | ||
configfile: `{ | ||
}`, | ||
envOrchestrator: "kubernetes", | ||
flagOrchestrator: "swarm", | ||
expectedOrchestrator: "swarm", | ||
expectedKubernetes: false, | ||
expectedSwarm: true, | ||
}, | ||
} | ||
|
||
for _, testcase := range testcases { | ||
t.Run(testcase.doc, func(t *testing.T) { | ||
dir := fs.NewDir(t, testcase.doc, fs.WithFile("config.json", testcase.configfile)) | ||
defer dir.Remove() | ||
apiclient := &fakeClient{ | ||
version: defaultVersion, | ||
} | ||
if testcase.envOrchestrator != "" { | ||
defer env.Patch(t, "DOCKER_STACK_ORCHESTRATOR", testcase.envOrchestrator)() | ||
} | ||
|
||
cli := &DockerCli{client: apiclient, err: os.Stderr} | ||
cliconfig.SetDir(dir.Path()) | ||
options := flags.NewClientOptions() | ||
if testcase.flagOrchestrator != "" { | ||
options.Common.StackOrchestrator = testcase.flagOrchestrator | ||
} | ||
err := cli.Initialize(options) | ||
assert.NilError(t, err) | ||
|
||
orchestrator, err := GetStackOrchestrator(testcase.flagOrchestrator, cli.ConfigFile().StackOrchestrator) | ||
assert.NilError(t, err) | ||
assert.Check(t, is.Equal(testcase.expectedKubernetes, orchestrator.HasKubernetes())) | ||
assert.Check(t, is.Equal(testcase.expectedSwarm, orchestrator.HasSwarm())) | ||
assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(orchestrator))) | ||
}) | ||
} | ||
} |
Oops, something went wrong.