mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
v2: App rewritten in Go (#25)
This commit is contained in:
24
internal/cli/version/command.go
Normal file
24
internal/cli/version/command.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Package version contains CLI `version` command implementation.
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewCommand creates `version` command.
|
||||
func NewCommand(ver string) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "version",
|
||||
Aliases: []string{"v", "ver"},
|
||||
Short: "Display application version",
|
||||
RunE: func(*cobra.Command, []string) (err error) {
|
||||
_, err = fmt.Fprintf(os.Stdout, "app version:\t%s (%s)\n", ver, runtime.Version())
|
||||
|
||||
return
|
||||
},
|
||||
}
|
||||
}
|
30
internal/cli/version/command_test.go
Normal file
30
internal/cli/version/command_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
package version_test
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tarampampam/error-pages/internal/cli/version"
|
||||
)
|
||||
|
||||
func TestProperties(t *testing.T) {
|
||||
cmd := version.NewCommand("")
|
||||
|
||||
assert.Equal(t, "version", cmd.Use)
|
||||
assert.ElementsMatch(t, []string{"v", "ver"}, cmd.Aliases)
|
||||
assert.NotNil(t, cmd.RunE)
|
||||
}
|
||||
|
||||
func TestCommandRun(t *testing.T) {
|
||||
cmd := version.NewCommand("1.2.3@foobar")
|
||||
cmd.SetArgs([]string{})
|
||||
|
||||
output := capturer.CaptureStdout(func() {
|
||||
assert.NoError(t, cmd.Execute())
|
||||
})
|
||||
|
||||
assert.Contains(t, output, "1.2.3@foobar")
|
||||
assert.Contains(t, output, runtime.Version())
|
||||
}
|
Reference in New Issue
Block a user