test: make version output captureable
Route the version subcommand through Cobra's configured output stream and cover it with a focused command-output test. Extracted as a narrow, low-risk slice from #78 by @nikolasdehor. Co-authored-by: Nikolas de Hor <116851567+nikolasdehor@users.noreply.github.com>
This commit is contained in:
parent
a2c78030f6
commit
c912668b21
@ -101,6 +101,7 @@
|
||||
### Chore
|
||||
|
||||
- CI: compile-test the Windows lock package to catch platform regressions. (#188 — thanks @dinakars777)
|
||||
- CLI: route `version` output through Cobra's configured output stream for easier command tests. (#78 — thanks @nikolasdehor)
|
||||
- Dependencies: update Go modules including `whatsmeow`, `go-sqlite3`, `x/*`, and related runtime libs.
|
||||
- Refactor: split WhatsApp message parsing into focused text, media, business, and context helpers.
|
||||
- Refactor: inject clocks in app/store paths for deterministic tests.
|
||||
|
||||
@ -11,7 +11,7 @@ func newVersionCmd() *cobra.Command {
|
||||
Use: "version",
|
||||
Short: "Print version",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(version)
|
||||
fmt.Fprintln(cmd.OutOrStdout(), version)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
20
cmd/wacli/version_test.go
Normal file
20
cmd/wacli/version_test.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVersionCommandUsesConfiguredOutput(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
cmd := newVersionCmd()
|
||||
cmd.SetOut(&out)
|
||||
cmd.SetArgs(nil)
|
||||
|
||||
if err := cmd.Execute(); err != nil {
|
||||
t.Fatalf("version command: %v", err)
|
||||
}
|
||||
if got, want := out.String(), version+"\n"; got != want {
|
||||
t.Fatalf("version output = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user