Artifact bdda048ee3d8ad3f35e32f6fdd9195e70252330fca1e0e380b93dcfe7450176a:
- File
cli/shared_test.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 1404) [annotate] [blame] [check-ins using]
package cli_test import ( "os" "path/filepath" "testing" libfossil "github.com/danmestas/libfossil" "github.com/danmestas/libfossil/cli" _ "github.com/danmestas/libfossil/internal/testdriver" ) func TestGlobalsOpenRepo(t *testing.T) { tmp := t.TempDir() repoPath := filepath.Join(tmp, "test.fossil") r, err := libfossil.Create(repoPath, libfossil.CreateOpts{User: "test"}) if err != nil { t.Fatalf("Create: %v", err) } r.Close() g := &cli.Globals{Repo: repoPath} opened, err := g.OpenRepo() if err != nil { t.Fatalf("OpenRepo: %v", err) } defer opened.Close() if opened.Path() != repoPath { t.Errorf("Path() = %q, want %q", opened.Path(), repoPath) } } func TestGlobalsOpenRepoNotFound(t *testing.T) { g := &cli.Globals{Repo: "/nonexistent/repo.fossil"} _, err := g.OpenRepo() if err == nil { t.Fatal("expected error for nonexistent repo") } } func TestGlobalsOpenRepoAutoFind(t *testing.T) { tmp := t.TempDir() repoPath := filepath.Join(tmp, "auto.fossil") r, err := libfossil.Create(repoPath, libfossil.CreateOpts{User: "test"}) if err != nil { t.Fatalf("Create: %v", err) } r.Close() // Change to the temp dir so findRepo can discover the .fossil file. orig, _ := os.Getwd() defer os.Chdir(orig) os.Chdir(tmp) g := &cli.Globals{} opened, err := g.OpenRepo() if err != nil { t.Fatalf("OpenRepo auto-find: %v", err) } defer opened.Close() }