Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skywire-cli config gen -r test #1611

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions cmd/skywire-cli/commands/config/gen_test.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/visor/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down