Skip to content

Commit

Permalink
update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthpun committed Jan 17, 2024
1 parent 0cd19d2 commit 82c7876
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
21 changes: 11 additions & 10 deletions internal/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package command_test
import (
"testing"

"github.com/onflow/flow-cli/internal/command"
"github.com/spf13/cobra"

"github.com/onflow/flow-cli/internal/command"
)

func TestAddToParent(t *testing.T) {
cmd := &cobra.Command{}
c := &command.Command{
Cmd: cmd,
}
cmd := &cobra.Command{}
c := &command.Command{
Cmd: cmd,
}

c.AddToParent(cmd)
c.AddToParent(cmd)

if c.Cmd.Run == nil {
t.Errorf("Run function was not initialized")
}
}
if c.Cmd.Run == nil {
t.Errorf("Run function was not initialized")
}
}
1 change: 0 additions & 1 deletion internal/command/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func InitFlags(cmd *cobra.Command) {
"Approve any prompts",
)


cmd.PersistentFlags().BoolVarP(
&Flags.SkipVersionCheck,
"skip-version-check",
Expand Down
55 changes: 28 additions & 27 deletions internal/command/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,37 @@ import (
"strings"
"testing"

"github.com/onflow/flow-cli/internal/command"
"github.com/spf13/cobra"

"github.com/onflow/flow-cli/internal/command"
)

func TestInitFlags(t *testing.T) {
cmd := &cobra.Command{}
command.InitFlags(cmd)
cmd := &cobra.Command{}
command.InitFlags(cmd)

flags := []struct {
name string
expected string
}{
{"filter", command.Flags.Filter},
{"format", command.Flags.Format},
{"save", command.Flags.Save},
{"host", command.Flags.Host},
{"network-key", command.Flags.HostNetworkKey},
{"network", command.Flags.Network},
{"log", command.Flags.Log},
{"yes", strconv.FormatBool(command.Flags.Yes)},
{"config-path", fmt.Sprintf("[%s]",strings.Join(command.Flags.ConfigPaths, ","))},
{"skip-version-check", strconv.FormatBool(command.Flags.SkipVersionCheck)},
}
flags := []struct {
name string
expected string
}{
{"filter", command.Flags.Filter},
{"format", command.Flags.Format},
{"save", command.Flags.Save},
{"host", command.Flags.Host},
{"network-key", command.Flags.HostNetworkKey},
{"network", command.Flags.Network},
{"log", command.Flags.Log},
{"yes", strconv.FormatBool(command.Flags.Yes)},
{"config-path", fmt.Sprintf("[%s]", strings.Join(command.Flags.ConfigPaths, ","))},
{"skip-version-check", strconv.FormatBool(command.Flags.SkipVersionCheck)},
}

for _, flag := range flags {
f := cmd.PersistentFlags().Lookup(flag.name)
if f == nil {
t.Errorf("Flag %s was not initialized", flag.name)
} else if f.DefValue != flag.expected {
t.Errorf("Flag %s was not initialized with correct default value. Value: %s, Expected: %s", flag.name, f.Value.String(), flag.expected)
}
}
}
for _, flag := range flags {
f := cmd.PersistentFlags().Lookup(flag.name)
if f == nil {
t.Errorf("Flag %s was not initialized", flag.name)
} else if f.DefValue != flag.expected {
t.Errorf("Flag %s was not initialized with correct default value. Value: %s, Expected: %s", flag.name, f.Value.String(), flag.expected)
}
}
}

0 comments on commit 82c7876

Please sign in to comment.