diff --git a/.gitignore b/.gitignore index 8b996d74f..42525aab2 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ mgc/spec_manipulator/cli_specs/specs.go.tmp terraform.tfstate terraform.tfstate.backup terraform.tfstate.d +mgc/cli_tester/cli_tester diff --git a/go.work b/go.work index 0f5dc8b9f..e8225941e 100644 --- a/go.work +++ b/go.work @@ -2,6 +2,7 @@ go 1.23.0 use ( ./mgc/cli + ./mgc/cli_tester ./mgc/codegen ./mgc/core ./mgc/lib diff --git a/mgc/cli_tester/cmd/add.go b/mgc/cli_tester/cmd/add.go new file mode 100644 index 000000000..1eb86b0fa --- /dev/null +++ b/mgc/cli_tester/cmd/add.go @@ -0,0 +1,50 @@ +package cmd + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +func add(cmd *cobra.Command, args []string) { + var toSave []commandsList + + module := strings.Split(args[0], " ")[1] + if module == "" { + fmt.Println(`fail! Command syntax eg.: "mgc auth login"`) + return + } + toSave = append(toSave, commandsList{Command: args[0], Module: module}) + + currentConfig, err := loadList() + if err != nil { + fmt.Println(err) + return + } + + for _, x := range currentConfig { + if x.Command == args[0] { + fmt.Println(`fail! command already exists`) + return + } + } + + toSave = append(toSave, currentConfig...) + viper.Set("commands", toSave) + err = viper.WriteConfigAs(VIPER_FILE) + if err != nil { + fmt.Println(err) + } + fmt.Println("done") +} + +var addCommandCmd = &cobra.Command{ + Use: "add [command]", + Short: "Add new command", + Example: "specs add 'mgc auth login'", + Args: cobra.MinimumNArgs(1), + Hidden: false, + Run: add, +} diff --git a/mgc/cli_tester/cmd/common.go b/mgc/cli_tester/cmd/common.go new file mode 100644 index 000000000..190a758c2 --- /dev/null +++ b/mgc/cli_tester/cmd/common.go @@ -0,0 +1,148 @@ +package cmd + +import ( + "bytes" + "errors" + "fmt" + "os" + "path/filepath" + "regexp" + "strings" + + "github.com/spf13/viper" +) + +type commandsList struct { + Module string `yaml:"module"` + Command string `yaml:"command"` +} + +func interfaceToMap(i interface{}) (map[string]interface{}, bool) { + mapa, ok := i.(map[string]interface{}) + if !ok { + fmt.Println("A interface não é um mapa ou mapa de interfaces.") + return nil, false + } + return mapa, true +} + +func loadList() ([]commandsList, error) { + var currentConfig []commandsList + config := viper.Get("commands") + + if config != nil { + for _, v := range config.([]interface{}) { + vv, ok := interfaceToMap(v) + if !ok { + return currentConfig, fmt.Errorf("fail to load current config") + } + currentConfig = append(currentConfig, commandsList{ + Module: vv["module"].(string), + Command: vv["command"].(string), + }) + } + + } + return currentConfig, nil +} + +func ensureDirectoryExists(dirPath string) error { + if _, err := os.Stat(dirPath); os.IsNotExist(err) { + return os.MkdirAll(dirPath, 0755) + } + return nil +} + +func createFile(content []byte, dir, filePath string) error { + return os.WriteFile(filepath.Join(dir, filePath), content, 0644) +} + +func loadFile(dir, filePath string) ([]byte, error) { + return os.ReadFile(filepath.Join(dir, filePath)) +} + +func writeSnapshot(output []byte, dir string, id string) error { + _ = createFile(output, dir, fmt.Sprintf("%s.cli", id)) + return nil +} + +func compareBytes(expected, actual []byte, ignoreDateUUID bool) error { + if bytes.Equal(expected, actual) { + return nil + } + + allEqual := true + + expectedLines := strings.Split(string(expected), "\n") + actualLines := strings.Split(string(actual), "\n") + + var diff strings.Builder + diff.WriteString("\nDiferenças encontradas:\n") + + dateRegex := regexp.MustCompile(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`) + uuidRegex := regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`) + + i, j := 0, 0 + for i < len(expectedLines) && j < len(actualLines) { + expectedLine := expectedLines[i] + actualLine := actualLines[j] + + if ignoreDateUUID { + expectedLine = dateRegex.ReplaceAllString(expectedLine, "DATE") + expectedLine = uuidRegex.ReplaceAllString(expectedLine, "UUID") + actualLine = dateRegex.ReplaceAllString(actualLine, "DATE") + actualLine = uuidRegex.ReplaceAllString(actualLine, "UUID") + } + + if expectedLine == actualLine { + diff.WriteString(" " + expectedLines[i] + "\n") + i++ + j++ + } else { + allEqual = false + diff.WriteString("- " + expectedLines[i] + "\n") + diff.WriteString("+ " + actualLines[j] + "\n") + i++ + j++ + } + } + + for ; i < len(expectedLines); i++ { + diff.WriteString("- " + expectedLines[i] + "\n") + } + for ; j < len(actualLines); j++ { + diff.WriteString("+ " + actualLines[j] + "\n") + } + + if allEqual { + return nil + } + + return fmt.Errorf("%s", diff.String()) +} + +func compareSnapshot(output []byte, dir string, id string) error { + snapContent, err := loadFile(dir, fmt.Sprintf("%s.cli", id)) + if err == nil { + return compareBytes(snapContent, output, true) + } + + if errors.Is(err, os.ErrNotExist) { + _ = writeSnapshot(output, dir, id) + return nil + } + + return fmt.Errorf("Diosmio") +} + +func normalizeCommandToFile(input string) string { + words := strings.Fields(input) + var filteredWords []string + for _, word := range words { + if !strings.HasPrefix(word, "--") { + filteredWords = append(filteredWords, word) + } + } + result := strings.Join(filteredWords, "-") + return result +} diff --git a/mgc/cli_tester/cmd/list.go b/mgc/cli_tester/cmd/list.go new file mode 100644 index 000000000..c9ccacb4a --- /dev/null +++ b/mgc/cli_tester/cmd/list.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "gopkg.in/yaml.v3" +) + +var lisCommandsCmd = &cobra.Command{ + Use: "list", + Short: "List all available commands", + Hidden: true, + Run: func(cmd *cobra.Command, args []string) { + currentCommands, err := loadList() + + if err != nil { + fmt.Println(err) + return + } + + out, err := yaml.Marshal(currentCommands) + if err == nil { + fmt.Println(string(out)) + } + + }, +} diff --git a/mgc/cli_tester/cmd/mock/create.go b/mgc/cli_tester/cmd/mock/create.go new file mode 100644 index 000000000..4ec2dc251 --- /dev/null +++ b/mgc/cli_tester/cmd/mock/create.go @@ -0,0 +1,16 @@ +package mock + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var mockCreateCmd = &cobra.Command{ + Use: "create", + Short: "create", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("xpto") + + }, +} diff --git a/mgc/cli_tester/cmd/mock/group.go b/mgc/cli_tester/cmd/mock/group.go new file mode 100644 index 000000000..c4541c074 --- /dev/null +++ b/mgc/cli_tester/cmd/mock/group.go @@ -0,0 +1,16 @@ +package mock + +import "github.com/spf13/cobra" + +func MockCmd() *cobra.Command { + + mockCmd := &cobra.Command{ + CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, + Use: "mock", + Short: "Mock", + } + + mockCmd.AddCommand(mockCreateCmd) + + return mockCmd +} diff --git a/mgc/cli_tester/cmd/root.go b/mgc/cli_tester/cmd/root.go new file mode 100644 index 000000000..ece9a3196 --- /dev/null +++ b/mgc/cli_tester/cmd/root.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + "os" + "path/filepath" + + mock "magalu.cloud/cli_tester/cmd/mock" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var ( + rootCmd = &cobra.Command{ + CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, + Use: "cli_tester", + Short: "Utilitário para auxiliar nos testes da CLI", + } +) + +const ( + VIPER_FILE = "commands.yaml" + SNAP_DIR = "snapshot" +) + +var currentDir = func() string { + ex, err := os.Executable() + if err != nil { + panic(err) + } + return filepath.Dir(ex) +} + +func Execute() error { + return rootCmd.Execute() +} + +func init() { + cobra.OnInitialize(initConfig) + rootCmd.AddCommand(lisCommandsCmd) + rootCmd.AddCommand(addCommandCmd) + rootCmd.AddCommand(runTestsCmd) + rootCmd.AddCommand(mock.MockCmd()) +} + +func initConfig() { + + ex, err := os.Executable() + home := filepath.Dir(ex) + cobra.CheckErr(err) + + viper.AddConfigPath(home) + viper.SetConfigType("yaml") + viper.SetConfigName(VIPER_FILE) + + viper.AutomaticEnv() + if err := viper.ReadInConfig(); err == nil { + fmt.Println("Command list at file:", viper.ConfigFileUsed()) + } + +} diff --git a/mgc/cli_tester/cmd/run.go b/mgc/cli_tester/cmd/run.go new file mode 100644 index 000000000..4e68ea39a --- /dev/null +++ b/mgc/cli_tester/cmd/run.go @@ -0,0 +1,100 @@ +package cmd + +import ( + "fmt" + "os" + "os/exec" + "path" + "strconv" + "sync" + + "github.com/spf13/cobra" +) + +type resultError struct { + commandsList + Error string +} + +type result struct { + errors []resultError + success []commandsList +} + +var runTestsCmd = &cobra.Command{ + Use: "test", + Short: "Run all available tests", + Hidden: false, + Run: func(cmd *cobra.Command, args []string) { + + if os.Getenv("MGC_API_KEY") == "" { + // TODO: Validar object storage também + fmt.Println("Se faz necessário a variavel de ambiente MGC_API_KEY") + return + } + + rewriteSnap := false + if len(args) > 0 { + rewriteSnap, _ = strconv.ParseBool(args[0]) + } + + _ = ensureDirectoryExists(path.Join(currentDir(), SNAP_DIR)) + + currentCommands, err := loadList() + + if err != nil { + fmt.Println(err) + return + + } + result := result{} + var wg sync.WaitGroup + + for _, cmmd := range currentCommands { + wg.Add(1) + go func() { + defer wg.Done() + output, err := exec.Command("sh", "-c", cmmd.Command+" --raw").CombinedOutput() + if err != nil { + result.errors = append(result.errors, resultError{ + commandsList: cmmd, + Error: err.Error(), + }) + return + } + + snapshotFile := normalizeCommandToFile(cmmd.Command) + if rewriteSnap { + _ = writeSnapshot(output, SNAP_DIR, snapshotFile) + } + + err = compareSnapshot(output, SNAP_DIR, snapshotFile) + + if err != nil { + result.errors = append(result.errors, resultError{ + commandsList: cmmd, + Error: err.Error(), + }) + return + } + + result.success = append(result.success, cmmd) + }() + } + + wg.Wait() + + //TODO: Fazer um output bonitinho =) + if len(result.errors) == 0 { + fmt.Println("Sucesso! Todos os comandos executados sem alterações.") + return + } + + fmt.Print("\nErros encontrados:\n\n") + for _, er := range result.errors { + + fmt.Println("Command: ", er.Command) + fmt.Println("Error: ", er.Error) + } + }, +} diff --git a/mgc/cli_tester/commands.yaml b/mgc/cli_tester/commands.yaml new file mode 100644 index 000000000..72731f1a2 --- /dev/null +++ b/mgc/cli_tester/commands.yaml @@ -0,0 +1,11 @@ +commands: + - module: vm + command: mgc vm instances list -o table + - module: vm + command: mgc vm instances list -o json + - module: vm + command: mgc vm instances list -o yaml + - module: vm + command: mgc vm instances list + - module: auth + command: mgc auth tenant current diff --git a/mgc/cli_tester/go.mod b/mgc/cli_tester/go.mod new file mode 100644 index 000000000..1b96b8be0 --- /dev/null +++ b/mgc/cli_tester/go.mod @@ -0,0 +1,31 @@ +module magalu.cloud/cli_tester + +go 1.23.0 + +require ( + github.com/spf13/cobra v1.8.1 + github.com/spf13/viper v1.19.0 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect +) diff --git a/mgc/cli_tester/go.sum b/mgc/cli_tester/go.sum new file mode 100644 index 000000000..aba916345 --- /dev/null +++ b/mgc/cli_tester/go.sum @@ -0,0 +1,77 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/mgc/cli_tester/main.go b/mgc/cli_tester/main.go new file mode 100644 index 000000000..12f881959 --- /dev/null +++ b/mgc/cli_tester/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "os" + + "magalu.cloud/cli_tester/cmd" +) + +func main() { + err := cmd.Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", err) + os.Exit(1) + } +} diff --git a/mgc/cli_tester/snapshot/mgc-auth-tenant-current.cli b/mgc/cli_tester/snapshot/mgc-auth-tenant-current.cli new file mode 100644 index 000000000..87a811484 --- /dev/null +++ b/mgc/cli_tester/snapshot/mgc-auth-tenant-current.cli @@ -0,0 +1,8 @@ +WARN magalu.cloud/core/auth Failed to get detailed info about Tenant, returning only ID {"err": "Get \"https://id.magalu.com/account/api/v2/whoami/tenants\": unable to get access token: RefreshToken is not set. Did you forget to log-in?"} +{ + "email": "", + "is_delegated": false, + "is_managed": false, + "legal_name": "", + "uuid": "" +} diff --git a/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-json.cli b/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-json.cli new file mode 100644 index 000000000..9abaaa023 --- /dev/null +++ b/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-json.cli @@ -0,0 +1,26 @@ +{ + "instances": [ + { + "created_at": "2024-10-01T18:14:53Z", + "id": "e6063fe8-3ead-4453-b4fb-969dfce59c2e", + "image": { + "id": "f4895a9d-b71c-4d20-a740-ac8467e8b446" + }, + "machine_type": { + "id": "fb634f1c-4280-4acb-b9a4-24dea423a9a6" + }, + "name": "10", + "network": { + "ports": [ + { + "id": "54503ab9-9021-461c-9a59-cb01f22ab193" + } + ] + }, + "ssh_key_name": "geff", + "state": "running", + "status": "completed", + "updated_at": "2024-10-01T18:15:30Z" + } + ] +} diff --git a/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-table.cli b/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-table.cli new file mode 100644 index 000000000..e2e44b2e3 --- /dev/null +++ b/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-table.cli @@ -0,0 +1,6 @@ + ≈ + CREATED_AT ID IMAGE MACHINE_TYPE NAME NETWORK ≈ + ID ID ID ≈ + ≈ + 2024-10-01T18:14:53Z e6063fe8-3ead-4453-b4fb-969dfce59c2e f4895a9d-b71c-4d20-a740-ac8467e8b446 fb634f1c-4280-4acb-b9a4-24dea423a9a6 10 54503ab9-9021-4 ≈ + ≈ diff --git a/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-yaml.cli b/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-yaml.cli new file mode 100644 index 000000000..5e39eaa3d --- /dev/null +++ b/mgc/cli_tester/snapshot/mgc-vm-instances-list--o-yaml.cli @@ -0,0 +1,16 @@ +instances: +- created_at: 2024-10-01T18:14:53Z + id: e6063fe8-3ead-4453-b4fb-969dfce59c2e + image: + id: f4895a9d-b71c-4d20-a740-ac8467e8b446 + machine_type: + id: fb634f1c-4280-4acb-b9a4-24dea423a9a6 + name: "10" + network: + ports: + - id: 54503ab9-9021-461c-9a59-cb01f22ab193 + ssh_key_name: geff + state: running + status: completed + updated_at: 2024-10-01T18:15:30Z + diff --git a/mgc/cli_tester/snapshot/mgc-vm-instances-list.cli b/mgc/cli_tester/snapshot/mgc-vm-instances-list.cli new file mode 100644 index 000000000..9abaaa023 --- /dev/null +++ b/mgc/cli_tester/snapshot/mgc-vm-instances-list.cli @@ -0,0 +1,26 @@ +{ + "instances": [ + { + "created_at": "2024-10-01T18:14:53Z", + "id": "e6063fe8-3ead-4453-b4fb-969dfce59c2e", + "image": { + "id": "f4895a9d-b71c-4d20-a740-ac8467e8b446" + }, + "machine_type": { + "id": "fb634f1c-4280-4acb-b9a4-24dea423a9a6" + }, + "name": "10", + "network": { + "ports": [ + { + "id": "54503ab9-9021-461c-9a59-cb01f22ab193" + } + ] + }, + "ssh_key_name": "geff", + "state": "running", + "status": "completed", + "updated_at": "2024-10-01T18:15:30Z" + } + ] +}