Artifact 30e0c5e29f58a9afd7197930d5d85f59f72244b6cfc41ed6f068ffbf5f5bceab:
- File
transport_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: 1435) [annotate] [blame] [check-ins using]
package libfossil import ( "context" "io" "net/http" "net/http/httptest" "testing" ) func TestHTTPTransportRoundTrip(t *testing.T) { echo := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if ct := r.Header.Get("Content-Type"); ct != "application/x-fossil" { t.Errorf("Content-Type = %q, want application/x-fossil", ct) } body, _ := io.ReadAll(r.Body) w.Write(body) })) defer echo.Close() tr := NewHTTPTransport(echo.URL) resp, err := tr.RoundTrip(context.Background(), []byte("hello")) if err != nil { t.Fatal(err) } if string(resp) != "hello" { t.Errorf("got %q, want %q", resp, "hello") } } func TestMockTransportRoundTrip(t *testing.T) { tr := &MockTransport{ Handler: func(req []byte) []byte { return []byte("mock") }, } resp, err := tr.RoundTrip(context.Background(), []byte("req")) if err != nil { t.Fatal(err) } if string(resp) != "mock" { t.Errorf("got %q, want %q", resp, "mock") } } func TestTransportFunc(t *testing.T) { called := false fn := TransportFunc(func(ctx context.Context, payload []byte) ([]byte, error) { called = true return []byte("response"), nil }) resp, err := fn.RoundTrip(context.Background(), []byte("request")) if err != nil { t.Fatalf("RoundTrip: %v", err) } if !called { t.Error("handler function was not called") } if string(resp) != "response" { t.Errorf("got %q, want %q", resp, "response") } }