Artifact c6627e422538bdd49b39d2f608e9d3a83536fb102046394f013a4ab86a1a78dc:
- File
simio/env_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: 1275) [annotate] [blame] [check-ins using]
package simio import ( "testing" ) func TestRealEnv(t *testing.T) { env := RealEnv() if env.Clock == nil { t.Fatal("Clock should not be nil") } if env.Rand == nil { t.Fatal("Rand should not be nil") } // RealClock.Now should return a reasonable time now := env.Clock.Now() if now.Year() < 2024 { t.Fatalf("RealClock.Now returned suspicious time: %v", now) } // CryptoRand should read bytes buf := make([]byte, 16) n, err := env.Rand.Read(buf) if err != nil { t.Fatal(err) } if n != 16 { t.Fatalf("expected 16 bytes, got %d", n) } } func TestSimEnv(t *testing.T) { env := SimEnv(99) if env.Clock == nil { t.Fatal("Clock should not be nil") } if env.Rand == nil { t.Fatal("Rand should not be nil") } // SimClock should be a *SimClock sc, ok := env.Clock.(*SimClock) if !ok { t.Fatalf("expected *SimClock, got %T", env.Clock) } if !sc.Now().IsZero() && sc.Now().Unix() != 0 { t.Fatalf("SimClock should start at epoch, got %v", sc.Now()) } // SeededRand should be deterministic env2 := SimEnv(99) buf1 := make([]byte, 32) buf2 := make([]byte, 32) env.Rand.Read(buf1) env2.Rand.Read(buf2) for i := range buf1 { if buf1[i] != buf2[i] { t.Fatal("SimEnv with same seed should produce identical Rand output") } } }