diff --git a/Makefile b/Makefile index ff08311f1..ace5669e0 100644 --- a/Makefile +++ b/Makefile @@ -150,12 +150,12 @@ lint-windows: ## Run linters. Use make install-linters-windows first test: ## Run tests -go clean -testcache &>/dev/null - ${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... + ${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... ./cmd/... ${OPTS} go test ${TEST_OPTS} test-windows: ## Run tests on windows @go clean -testcache - ${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... + ${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... ./cmd/... install-linters: ## Install linters - VERSION=latest ./ci_scripts/install-golangci-lint.sh diff --git a/cmd/skywire-cli/commands/config/gen_test.go b/cmd/skywire-cli/commands/config/gen_test.go new file mode 100644 index 000000000..aa001b01e --- /dev/null +++ b/cmd/skywire-cli/commands/config/gen_test.go @@ -0,0 +1,77 @@ +package cliconfig + +import ( + "os" + "os/exec" + "runtime" + "testing" + + "github.com/bitfield/script" +) + +var ( + shell string +) + +func init() { + switch runtime.GOOS { + case "windows": + if _, err := exec.LookPath("bash"); err == nil { + shell = "bash" + } else if _, err := exec.LookPath("powershell"); err == nil { + shell = "powershell" + } else { + panic("Required binaries 'bash' and 'powershell' not found") + } + case "linux", "darwin": + if _, err := exec.LookPath("bash"); err != nil { + panic("Required binary 'bash' not found") + } + shell = "bash" + default: + panic("Unsupported operating system: " + runtime.GOOS) + } +} + +// Reference Issue https://github.com/skycoin/skywire/issues/1606 + +func TestConfigGenCmdFunc(t *testing.T) { + tests := []struct { + name string + command string + expectedErr bool + }{ + { + name: "first config gen -r", + command: "config gen -r -o test-config.json", + expectedErr: false, + }, + { + name: "second config gen -r", + command: "config gen -r -o test-config.json", + expectedErr: false, + }, + { + name: "config gen -rf", + command: "config gen -rf -o test-config.json", + expectedErr: true, + }, + } + _ = os.Remove("test-config.json") //nolint + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + _, err := script.Exec(shell + ` -c "go run ../../skywire-cli.go ` + test.command + `"`).Stdout() + if err != nil { + if !test.expectedErr { + t.Fatalf("Expected error: %v, but got: %v", test.expectedErr, err) + } + } + if err == nil { + if test.expectedErr { + t.Fatalf("Expected error: %v, but got: %v", test.expectedErr, err) + } + } + }) + } + _ = os.Remove("test-config.json") //nolint +} diff --git a/cmd/skywire-cli/commands/visor/info.go b/cmd/skywire-cli/commands/visor/info.go index bf9bc2fc3..9a5ebca74 100644 --- a/cmd/skywire-cli/commands/visor/info.go +++ b/cmd/skywire-cli/commands/visor/info.go @@ -24,7 +24,7 @@ var pk string func init() { RootCmd.AddCommand(pkCmd) pkCmd.Flags().StringVarP(&path, "input", "i", "", "path of input config file.") - pkCmd.Flags().BoolVarP(&pkg, "pkg", "p", false, "read from "+fmt.Sprintf("%s", visorconfig.PackageConfig())) //nolint + pkCmd.Flags().BoolVarP(&pkg, "pkg", "p", false, "read from "+fmt.Sprintf("%v", visorconfig.PackageConfig())) //nolint pkCmd.Flags().BoolVarP(&web, "http", "w", false, "serve public key via http") pkCmd.Flags().StringVarP(&webPort, "prt", "x", "7998", "serve public key via http") RootCmd.AddCommand(summaryCmd)