Skip to content

Commit

Permalink
inline func
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy shem committed Nov 18, 2024
1 parent 971b861 commit f7987c0
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions cmd/bbolt/command_buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

bolt "go.etcd.io/bbolt"
Expand Down Expand Up @@ -32,22 +31,18 @@ func TestBuckets(t *testing.T) {
db.Close()
defer requireDBNoChange(t, dbData(t, db.Path()), db.Path())

// setup the bucketscommand.
// setup the buckets command.
t.Log("Running buckets command")
rootCmd := main.NewRootCommand()
_, actualOutput, err := executeCommand(rootCmd, "buckets", db.Path()) //rootCmd, "buckets", db.Path())
require.NoError(t, err)
t.Log("Verify result")
expected := "bar\nbaz\nfoo\n"
require.EqualValues(t, expected, actualOutput)
}

// executeCommand runs the given command and returns the output and error.
func executeCommand(rootCmd *cobra.Command, args ...string) (*cobra.Command, string, error) {
var args []string = []string{"buckets", db.Path()}
outputBuf := bytes.NewBufferString("")
rootCmd.SetOut(outputBuf)
rootCmd.SetErr(outputBuf)
rootCmd.SetArgs(args)
c, err := rootCmd.ExecuteC()
return c, outputBuf.String(), err
_, err := rootCmd.ExecuteC()
actualOutput := outputBuf.String()
require.NoError(t, err)
t.Log("Verify result")
expected := "bar\nbaz\nfoo\n"
require.EqualValues(t, expected, actualOutput)
}

0 comments on commit f7987c0

Please sign in to comment.