Artifact b6ea8f2b45d5ac37f0b46186cc7183763d7d037555309848b85582e52a7e7e31:
- File
internal/xfer/card_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: 3304) [annotate] [blame] [check-ins using]
package xfer import "testing" // TestCardTypeConstants verifies the enum values are correct. func TestCardTypeConstants(t *testing.T) { tests := []struct { ct CardType want int }{ {CardFile, 0}, {CardCFile, 1}, {CardIGot, 2}, {CardGimme, 3}, {CardLogin, 4}, {CardPush, 5}, {CardPull, 6}, {CardCookie, 7}, {CardClone, 8}, {CardCloneSeqNo, 9}, {CardConfig, 10}, {CardReqConfig, 11}, {CardPrivate, 12}, {CardUVFile, 13}, {CardUVGimme, 14}, {CardUVIGot, 15}, {CardPragma, 16}, {CardError, 17}, {CardMessage, 18}, {CardUnknown, 19}, } for _, tt := range tests { if int(tt.ct) != tt.want { t.Errorf("CardType %d: got %d, want %d", tt.want, int(tt.ct), tt.want) } } } // TestCardInterface verifies that every card struct implements the Card interface // and returns the correct CardType. func TestCardInterface(t *testing.T) { cards := []struct { name string card Card want CardType }{ {"FileCard", &FileCard{}, CardFile}, {"CFileCard", &CFileCard{}, CardCFile}, {"IGotCard", &IGotCard{}, CardIGot}, {"GimmeCard", &GimmeCard{}, CardGimme}, {"LoginCard", &LoginCard{}, CardLogin}, {"PushCard", &PushCard{}, CardPush}, {"PullCard", &PullCard{}, CardPull}, {"CookieCard", &CookieCard{}, CardCookie}, {"CloneCard", &CloneCard{}, CardClone}, {"CloneSeqNoCard", &CloneSeqNoCard{}, CardCloneSeqNo}, {"ConfigCard", &ConfigCard{}, CardConfig}, {"ReqConfigCard", &ReqConfigCard{}, CardReqConfig}, {"PrivateCard", &PrivateCard{}, CardPrivate}, {"UVFileCard", &UVFileCard{}, CardUVFile}, {"UVGimmeCard", &UVGimmeCard{}, CardUVGimme}, {"UVIGotCard", &UVIGotCard{}, CardUVIGot}, {"PragmaCard", &PragmaCard{}, CardPragma}, {"ErrorCard", &ErrorCard{}, CardError}, {"MessageCard", &MessageCard{}, CardMessage}, {"UnknownCard", &UnknownCard{}, CardUnknown}, } for _, tt := range cards { t.Run(tt.name, func(t *testing.T) { if got := tt.card.Type(); got != tt.want { t.Errorf("%s.Type() = %d, want %d", tt.name, got, tt.want) } }) } } // TestCardFieldAccess verifies that card structs hold their field values. func TestCardFieldAccess(t *testing.T) { fc := &FileCard{UUID: "abc123", DeltaSrc: "def456", Content: []byte("data")} if fc.UUID != "abc123" || fc.DeltaSrc != "def456" || string(fc.Content) != "data" { t.Error("FileCard fields not set correctly") } igot := &IGotCard{UUID: "abc123", IsPrivate: true} if igot.UUID != "abc123" || !igot.IsPrivate { t.Error("IGotCard fields not set correctly") } login := &LoginCard{User: "test user", Nonce: "nonce1", Signature: "sig1"} if login.User != "test user" || login.Nonce != "nonce1" || login.Signature != "sig1" { t.Error("LoginCard fields not set correctly") } pragma := &PragmaCard{Name: "sym-pressure", Values: []string{"100"}} if pragma.Name != "sym-pressure" || len(pragma.Values) != 1 || pragma.Values[0] != "100" { t.Error("PragmaCard fields not set correctly") } uvig := &UVIGotCard{Name: "file.txt", MTime: 1700000000, Hash: "abc", Size: 42} if uvig.MTime != 1700000000 || uvig.Size != 42 { t.Error("UVIGotCard fields not set correctly") } unk := &UnknownCard{Command: "foobar", Args: []string{"a", "b"}} if unk.Command != "foobar" || len(unk.Args) != 2 { t.Error("UnknownCard fields not set correctly") } }