- Remove fmt from updater.go, service.go, http_client.go, cmd.go, github.go, generic_http.go; replace with string concat, coreerr.E, cli.Print
- Remove strings from updater.go (inline byte comparisons) and service.go (inline helpers)
- Replace fmt.Sprintf in error paths with string concatenation throughout
- Add cli.Print for all stdout output in updater.go (CheckForUpdates, CheckOnly, etc.)
- Fix service_examples_test.go: restore original CheckForUpdates instead of setting nil
- Test naming: all test files now follow TestFile_Function_{Good,Bad,Ugly} with all three variants mandatory
- Comments: replace prose descriptions with usage-example style on all exported functions
- Remaining banned: strings/encoding/json in github.go and generic_http.go (no Core replacement in direct deps); os/os.exec in platform files (syscall-level, unavoidable without go-process)
Co-Authored-By: Virgil <virgil@lethean.io>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package updater_test
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
updater "forge.lthn.ai/core/go-update"
|
|
)
|
|
|
|
func ExampleNewUpdateService() {
|
|
// Mock the update check functions to prevent actual updates during tests
|
|
originalCheckForUpdates := updater.CheckForUpdates
|
|
updater.CheckForUpdates = func(owner, repo, channel string, forceSemVerPrefix bool, releaseURLFormat string) error {
|
|
fmt.Println("CheckForUpdates called")
|
|
return nil
|
|
}
|
|
defer func() {
|
|
updater.CheckForUpdates = originalCheckForUpdates
|
|
}()
|
|
|
|
config := updater.UpdateServiceConfig{
|
|
RepoURL: "https://github.com/owner/repo",
|
|
Channel: "stable",
|
|
CheckOnStartup: updater.CheckAndUpdateOnStartup,
|
|
}
|
|
updateService, err := updater.NewUpdateService(config)
|
|
if err != nil {
|
|
log.Fatalf("Failed to create update service: %v", err)
|
|
}
|
|
if err := updateService.Start(); err != nil {
|
|
log.Printf("Update check failed: %v", err)
|
|
}
|
|
// Output: CheckForUpdates called
|
|
}
|
|
|
|
func ExampleParseRepoURL() {
|
|
owner, repo, err := updater.ParseRepoURL("https://github.com/owner/repo")
|
|
if err != nil {
|
|
log.Fatalf("Failed to parse repo URL: %v", err)
|
|
}
|
|
fmt.Printf("Owner: %s, Repo: %s", owner, repo)
|
|
// Output: Owner: owner, Repo: repo
|
|
}
|