Skip to content
Open
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
19 changes: 19 additions & 0 deletions cmd/af/cmd/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var helloCmd = &cobra.Command{
Use: "hello",
Short: "Print a greeting",
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(cmd.OutOrStdout(), "hello world")

Check failure on line 13 in cmd/af/cmd/hello.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `fmt.Fprintln` is not checked (errcheck)
},
}

func init() {
rootCmd.AddCommand(helloCmd)
}
20 changes: 20 additions & 0 deletions cmd/af/cmd/hello_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"bytes"
"testing"
)

func TestHelloCmdPrintsHelloWorld(t *testing.T) {
var buf bytes.Buffer
helloCmd.SetOut(&buf)
t.Cleanup(func() { helloCmd.SetOut(nil) })

helloCmd.Run(helloCmd, nil)

got := buf.String()
want := "hello world\n"
if got != want {
t.Fatalf("hello output = %q, want %q", got, want)
}
}
Loading