2020-06-22 09:55:28 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-06-22 09:55:28 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-07-31 18:51:02 +02:00
|
|
|
"gotest.tools/v3/assert"
|
2020-06-22 09:55:28 +02:00
|
|
|
)
|
|
|
|
|
2020-10-07 23:29:55 +02:00
|
|
|
func TestGetCommand(t *testing.T) {
|
2020-06-22 09:55:28 +02:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
2020-07-01 14:57:08 +02:00
|
|
|
args []string
|
2020-06-22 09:55:28 +02:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "with long flags",
|
2020-07-01 14:57:08 +02:00
|
|
|
args: []string{"--debug", "run"},
|
2020-06-22 09:55:28 +02:00
|
|
|
expected: "run",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "with short flags",
|
2020-09-30 11:42:06 +02:00
|
|
|
args: []string{"-D", "run"},
|
2020-06-22 09:55:28 +02:00
|
|
|
expected: "run",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "with flags with value",
|
2020-07-01 14:57:08 +02:00
|
|
|
args: []string{"--debug", "--str", "str-value", "run"},
|
2020-06-22 09:55:28 +02:00
|
|
|
expected: "run",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "with --",
|
2020-07-01 14:57:08 +02:00
|
|
|
args: []string{"--debug", "--str", "str-value", "--", "run"},
|
2020-06-22 09:55:28 +02:00
|
|
|
expected: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "without a command",
|
2020-07-01 14:57:08 +02:00
|
|
|
args: []string{"--debug", "--str", "str-value"},
|
2020-06-22 09:55:28 +02:00
|
|
|
expected: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "management command",
|
2020-07-01 14:57:08 +02:00
|
|
|
args: []string{"image", "ls"},
|
2020-06-22 09:55:28 +02:00
|
|
|
expected: "image ls",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "management subcommand with flag",
|
2020-07-01 14:57:08 +02:00
|
|
|
args: []string{"image", "ls", "-q"},
|
2020-06-22 09:55:28 +02:00
|
|
|
expected: "image ls",
|
|
|
|
},
|
2020-07-03 16:57:07 +02:00
|
|
|
{
|
|
|
|
name: "azure login",
|
|
|
|
args: []string{"login", "azure"},
|
|
|
|
expected: "login azure",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "azure login with flags",
|
|
|
|
args: []string{"login", "-u", "test", "azure"},
|
|
|
|
expected: "login azure",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "login to a registry",
|
2020-10-07 23:29:55 +02:00
|
|
|
args: []string{"login", "myregistry"},
|
2020-07-03 16:57:07 +02:00
|
|
|
expected: "login",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "context create aci",
|
|
|
|
args: []string{"context", "create", "aci"},
|
|
|
|
expected: "context create aci",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "create a context from another context",
|
|
|
|
args: []string{"context", "create", "test-context", "--from=default"},
|
|
|
|
expected: "context create",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "create a container",
|
|
|
|
args: []string{"create"},
|
|
|
|
expected: "create",
|
|
|
|
},
|
|
|
|
{
|
2020-10-07 23:29:55 +02:00
|
|
|
name: "start a container named aci",
|
|
|
|
args: []string{"start", "aci"},
|
|
|
|
expected: "start",
|
2020-07-03 16:57:07 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "create a container named test-container",
|
|
|
|
args: []string{"create", "test-container"},
|
|
|
|
expected: "create",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "create with flags",
|
|
|
|
args: []string{"create", "--rm", "test"},
|
|
|
|
expected: "create",
|
|
|
|
},
|
2020-09-30 10:44:10 +02:00
|
|
|
{
|
|
|
|
name: "compose up -f xxx",
|
|
|
|
args: []string{"compose", "up", "-f", "titi.yaml"},
|
|
|
|
expected: "compose up",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose -f xxx up",
|
|
|
|
args: []string{"compose", "-f", "titi.yaml", "up"},
|
|
|
|
expected: "compose up",
|
|
|
|
},
|
2020-09-30 11:42:06 +02:00
|
|
|
{
|
|
|
|
name: "-D compose -f xxx up",
|
|
|
|
args: []string{"--debug", "compose", "-f", "titi.yaml", "up"},
|
|
|
|
expected: "compose up",
|
|
|
|
},
|
2020-06-22 09:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2020-10-07 23:29:55 +02:00
|
|
|
result := GetCommand(testCase.args)
|
2020-07-01 14:57:08 +02:00
|
|
|
assert.Equal(t, testCase.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:29:55 +02:00
|
|
|
func TestFlags(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
args: []string{"--help"},
|
|
|
|
expected: "--help",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "help on run",
|
|
|
|
args: []string{"run", "--help"},
|
|
|
|
expected: "run --help",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "-h on run",
|
|
|
|
args: []string{"run", "-h"},
|
|
|
|
expected: "run -h",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "help on compose up",
|
|
|
|
args: []string{"compose", "up", "--help"},
|
|
|
|
expected: "compose up --help",
|
|
|
|
},
|
|
|
|
}
|
2020-07-01 14:57:08 +02:00
|
|
|
|
2020-10-07 23:29:55 +02:00
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
|
|
result := GetCommand(testCase.args)
|
|
|
|
assert.Equal(t, testCase.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEcs(t *testing.T) {
|
2020-07-01 14:57:08 +02:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "compose up",
|
|
|
|
args: []string{"ecs", "compose", "-f", "test", "up"},
|
|
|
|
expected: "ecs compose up",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose up",
|
|
|
|
args: []string{"ecs", "compose", "--file", "test", "up"},
|
|
|
|
expected: "ecs compose up",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose up",
|
|
|
|
args: []string{"ecs", "compose", "--file", "test", "-n", "test", "up"},
|
|
|
|
expected: "ecs compose up",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose up",
|
|
|
|
args: []string{"ecs", "compose", "--file", "test", "--project-name", "test", "up"},
|
|
|
|
expected: "ecs compose up",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose up",
|
|
|
|
args: []string{"ecs", "compose", "up"},
|
|
|
|
expected: "ecs compose up",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose down",
|
|
|
|
args: []string{"ecs", "compose", "-f", "test", "down"},
|
|
|
|
expected: "ecs compose down",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose down",
|
|
|
|
args: []string{"ecs", "compose", "down"},
|
|
|
|
expected: "ecs compose down",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose ps",
|
|
|
|
args: []string{"ecs", "compose", "-f", "test", "ps"},
|
|
|
|
expected: "ecs compose ps",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose ps",
|
|
|
|
args: []string{"ecs", "compose", "ps"},
|
|
|
|
expected: "ecs compose ps",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compose logs",
|
|
|
|
args: []string{"ecs", "compose", "-f", "test", "logs"},
|
|
|
|
expected: "ecs compose logs",
|
|
|
|
},
|
|
|
|
{
|
2020-10-07 23:29:55 +02:00
|
|
|
name: "ecs",
|
|
|
|
args: []string{"ecs", "anything"},
|
|
|
|
expected: "ecs",
|
2020-07-01 14:57:08 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2020-10-07 23:29:55 +02:00
|
|
|
result := GetCommand(testCase.args)
|
2020-06-22 09:55:28 +02:00
|
|
|
assert.Equal(t, testCase.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-07-03 10:55:28 +02:00
|
|
|
|
|
|
|
func TestScan(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "scan",
|
|
|
|
args: []string{"scan"},
|
|
|
|
expected: "scan",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scan image with long flags",
|
2020-10-07 23:29:55 +02:00
|
|
|
args: []string{"scan", "--file", "file", "myimage"},
|
2020-07-03 10:55:28 +02:00
|
|
|
expected: "scan",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scan image with short flags",
|
2020-10-07 23:29:55 +02:00
|
|
|
args: []string{"scan", "-f", "file", "myimage"},
|
2020-07-03 10:55:28 +02:00
|
|
|
expected: "scan",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scan with long flag",
|
2020-10-07 23:29:55 +02:00
|
|
|
args: []string{"scan", "--dependency-tree", "myimage"},
|
2020-07-03 10:55:28 +02:00
|
|
|
expected: "scan",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "auth",
|
2020-10-07 23:29:55 +02:00
|
|
|
args: []string{"scan", "--login"},
|
|
|
|
expected: "scan --login",
|
2020-07-03 10:55:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "version",
|
|
|
|
args: []string{"scan", "--version"},
|
2020-10-07 23:29:55 +02:00
|
|
|
expected: "scan --version",
|
2020-07-03 10:55:28 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2020-10-07 23:29:55 +02:00
|
|
|
result := GetCommand(testCase.args)
|
2020-07-03 10:55:28 +02:00
|
|
|
assert.Equal(t, testCase.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|