| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 | 
							- /*
 
-    Copyright 2020 Docker Compose CLI authors
 
-    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"
 
- 	"github.com/spf13/cobra"
 
- 	"gotest.tools/v3/assert"
 
- )
 
- func TestFlag(t *testing.T) {
 
- 	root := &cobra.Command{}
 
- 	root.PersistentFlags().BoolP("debug", "D", false, "debug")
 
- 	root.PersistentFlags().String("str", "str", "str")
 
- 	testCases := []struct {
 
- 		name     string
 
- 		args     []string
 
- 		expected string
 
- 	}{
 
- 		{
 
- 			name:     "with long flags",
 
- 			args:     []string{"--debug", "run"},
 
- 			expected: "run",
 
- 		},
 
- 		{
 
- 			name:     "with short flags",
 
- 			args:     []string{"-D", "run"},
 
- 			expected: "run",
 
- 		},
 
- 		{
 
- 			name:     "with flags with value",
 
- 			args:     []string{"--debug", "--str", "str-value", "run"},
 
- 			expected: "run",
 
- 		},
 
- 		{
 
- 			name:     "with --",
 
- 			args:     []string{"--debug", "--str", "str-value", "--", "run"},
 
- 			expected: "",
 
- 		},
 
- 		{
 
- 			name:     "without a command",
 
- 			args:     []string{"--debug", "--str", "str-value"},
 
- 			expected: "",
 
- 		},
 
- 		{
 
- 			name:     "with unknown short flag",
 
- 			args:     []string{"-f", "run"},
 
- 			expected: "",
 
- 		},
 
- 		{
 
- 			name:     "with unknown long flag",
 
- 			args:     []string{"--unknown-flag", "run"},
 
- 			expected: "",
 
- 		},
 
- 		{
 
- 			name:     "management command",
 
- 			args:     []string{"image", "ls"},
 
- 			expected: "image ls",
 
- 		},
 
- 		{
 
- 			name:     "management command with flag",
 
- 			args:     []string{"image", "--test", "ls"},
 
- 			expected: "image",
 
- 		},
 
- 		{
 
- 			name:     "management subcommand with flag",
 
- 			args:     []string{"image", "ls", "-q"},
 
- 			expected: "image ls",
 
- 		},
 
- 		{
 
- 			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:     "azure login with azure user",
 
- 			args:     []string{"login", "-u", "azure"},
 
- 			expected: "login",
 
- 		},
 
- 		{
 
- 			name:     "login to a registry",
 
- 			args:     []string{"login", "registry"},
 
- 			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",
 
- 		},
 
- 		{
 
- 			name:     "create a container named aci",
 
- 			args:     []string{"create", "aci"},
 
- 			expected: "create",
 
- 		},
 
- 		{
 
- 			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",
 
- 		},
 
- 		{
 
- 			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",
 
- 		},
 
- 		{
 
- 			name:     "-D compose -f xxx up",
 
- 			args:     []string{"--debug", "compose", "-f", "titi.yaml", "up"},
 
- 			expected: "compose up",
 
- 		},
 
- 	}
 
- 	for _, testCase := range testCases {
 
- 		t.Run(testCase.name, func(t *testing.T) {
 
- 			result := GetCommand(testCase.args, root.PersistentFlags())
 
- 			assert.Equal(t, testCase.expected, result)
 
- 		})
 
- 	}
 
- }
 
- func TestEcs(t *testing.T) {
 
- 	root := &cobra.Command{}
 
- 	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",
 
- 		},
 
- 		{
 
- 			name:     "setup",
 
- 			args:     []string{"ecs", "setup"},
 
- 			expected: "ecs setup",
 
- 		},
 
- 	}
 
- 	for _, testCase := range testCases {
 
- 		t.Run(testCase.name, func(t *testing.T) {
 
- 			result := GetCommand(testCase.args, root.PersistentFlags())
 
- 			assert.Equal(t, testCase.expected, result)
 
- 		})
 
- 	}
 
- }
 
- func TestScan(t *testing.T) {
 
- 	root := &cobra.Command{}
 
- 	testCases := []struct {
 
- 		name     string
 
- 		args     []string
 
- 		expected string
 
- 	}{
 
- 		{
 
- 			name:     "scan",
 
- 			args:     []string{"scan"},
 
- 			expected: "scan",
 
- 		},
 
- 		{
 
- 			name:     "scan image with long flags",
 
- 			args:     []string{"scan", "--file", "file", "image"},
 
- 			expected: "scan",
 
- 		},
 
- 		{
 
- 			name:     "scan image with short flags",
 
- 			args:     []string{"scan", "-f", "file", "image"},
 
- 			expected: "scan",
 
- 		},
 
- 		{
 
- 			name:     "scan with long flag",
 
- 			args:     []string{"scan", "--dependency-tree", "image"},
 
- 			expected: "scan",
 
- 		},
 
- 		{
 
- 			name:     "auth",
 
- 			args:     []string{"scan", "--auth"},
 
- 			expected: "scan auth",
 
- 		},
 
- 		{
 
- 			name:     "version",
 
- 			args:     []string{"scan", "--version"},
 
- 			expected: "scan version",
 
- 		},
 
- 	}
 
- 	for _, testCase := range testCases {
 
- 		t.Run(testCase.name, func(t *testing.T) {
 
- 			result := GetCommand(testCase.args, root.PersistentFlags())
 
- 			assert.Equal(t, testCase.expected, result)
 
- 		})
 
- 	}
 
- }
 
 
  |