2018-06-20 08:48:50 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2018-06-22 10:26:18 -04:00
|
|
|
"io/ioutil"
|
2018-06-20 08:48:50 -04:00
|
|
|
"testing"
|
|
|
|
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/env"
|
2018-06-20 08:48:50 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOrchestratorSwitch(t *testing.T) {
|
|
|
|
var testcases = []struct {
|
|
|
|
doc string
|
2018-12-17 05:27:07 -05:00
|
|
|
globalOrchestrator string
|
2018-06-20 08:48:50 -04:00
|
|
|
envOrchestrator string
|
|
|
|
flagOrchestrator string
|
2018-12-17 05:27:07 -05:00
|
|
|
contextOrchestrator string
|
2018-06-20 08:48:50 -04:00
|
|
|
expectedOrchestrator string
|
|
|
|
expectedSwarm bool
|
|
|
|
}{
|
|
|
|
{
|
2018-12-17 05:27:07 -05:00
|
|
|
doc: "default",
|
2018-06-20 08:48:50 -04:00
|
|
|
expectedOrchestrator: "swarm",
|
|
|
|
expectedSwarm: true,
|
|
|
|
},
|
|
|
|
{
|
2018-12-17 05:27:07 -05:00
|
|
|
doc: "allOrchestratorFlag",
|
2018-06-20 08:48:50 -04:00
|
|
|
flagOrchestrator: "all",
|
|
|
|
expectedOrchestrator: "all",
|
|
|
|
expectedSwarm: true,
|
|
|
|
},
|
2018-12-17 05:27:07 -05:00
|
|
|
{
|
|
|
|
doc: "contextOverridesConfigFile",
|
|
|
|
globalOrchestrator: "kubernetes",
|
|
|
|
contextOrchestrator: "swarm",
|
|
|
|
expectedOrchestrator: "swarm",
|
|
|
|
expectedSwarm: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
doc: "envOverridesConfigFile",
|
|
|
|
globalOrchestrator: "kubernetes",
|
2018-06-20 08:48:50 -04:00
|
|
|
envOrchestrator: "swarm",
|
|
|
|
expectedOrchestrator: "swarm",
|
|
|
|
expectedSwarm: true,
|
|
|
|
},
|
|
|
|
{
|
2018-12-17 05:27:07 -05:00
|
|
|
doc: "flagOverridesEnv",
|
2018-06-20 08:48:50 -04:00
|
|
|
envOrchestrator: "kubernetes",
|
|
|
|
flagOrchestrator: "swarm",
|
|
|
|
expectedOrchestrator: "swarm",
|
|
|
|
expectedSwarm: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range testcases {
|
|
|
|
t.Run(testcase.doc, func(t *testing.T) {
|
|
|
|
if testcase.envOrchestrator != "" {
|
|
|
|
defer env.Patch(t, "DOCKER_STACK_ORCHESTRATOR", testcase.envOrchestrator)()
|
|
|
|
}
|
2018-12-17 05:27:07 -05:00
|
|
|
orchestrator, err := GetStackOrchestrator(testcase.flagOrchestrator, testcase.contextOrchestrator, testcase.globalOrchestrator, ioutil.Discard)
|
2018-06-20 08:48:50 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(testcase.expectedSwarm, orchestrator.HasSwarm()))
|
|
|
|
assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(orchestrator)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|