Files
Bose-SoundTouch/cmd/soundtouch-backup/cmd_updatecheck_test.go
T
Tobias Gesellchen 97caea112f feat(cli): add on-demand update-check command to soundtouch-cli and soundtouch-backup
Answers #591's open question 2: CLI-only users get no update notice
from soundtouch-service's periodic background check. Both binaries
gain a soundtouch-cli/soundtouch-backup update-check command that
does a single, on-demand GitHub Releases check via the existing
pkg/service/updatecheck package. Running the command is itself the
opt-in, so unlike the service there's no config flag or persisted
state.

pkg/service/updatecheck.Checker was already designed decoupled from
handlers.Server/main.go specifically so other binaries could import
it directly; this is that follow-through.
2026-08-11 09:27:54 +02:00

43 lines
1.3 KiB
Go

package main
import (
"testing"
"github.com/gesellix/bose-soundtouch/pkg/service/updatecheck"
)
// TestUpdateCheckCommand_Registered checks the command is wired up with the
// expected name and an Action, without making any real GitHub API calls.
func TestUpdateCheckCommand_Registered(t *testing.T) {
cmd := updateCheckCommand()
if cmd.Name != "update-check" {
t.Errorf("command name = %q; want %q", cmd.Name, "update-check")
}
if cmd.Action == nil {
t.Error("expected an Action to be set")
}
}
// TestPrintUpdateCheckResult_DoesNotPanic exercises all three result shapes
// (unparseable current version, update available, up to date) purely for
// the "does not panic" guarantee; updatecheck.Checker's own tests already
// cover the comparison logic itself.
func TestPrintUpdateCheckResult_DoesNotPanic(t *testing.T) {
cases := []struct {
name string
result updatecheck.Result
}{
{"unparseable current version", updatecheck.Result{CurrentVersion: "dev"}},
{"update available", updatecheck.Result{CurrentVersion: "v1.0.0", LatestVersion: "v1.1.0", Available: true, ReleaseURL: "https://example.invalid"}},
{"up to date", updatecheck.Result{CurrentVersion: "v1.1.0", LatestVersion: "v1.1.0", Available: false}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
printUpdateCheckResult(tc.result)
})
}
}