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:
Dinakar Sarbada 2026-05-05 17:57:07 -07:00 committed by GitHub
parent a2c78030f6
commit c912668b21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 1 deletions

View File

@ -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.

View File

@ -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
View 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)
}
}