Skip to content

Commit

Permalink
Merge pull request #1611 from 0pcom/config-test
Browse files Browse the repository at this point in the history
`skywire-cli config gen -r` test
  • Loading branch information
jdknives authored Jun 8, 2023
2 parents 5111778 + fbac7b7 commit 9ec059d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
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

0 comments on commit 9ec059d

Please sign in to comment.