package bot import ( "encoding/json" "os" "testing" ) // TestCardVectors pins the Go card validator to the shared contract file the // web (test/cards.test.mjs) and native (CardVectorTests) suites also consume — // three implementations, one spec. encoding/json marshals maps with sorted // keys, so marshalled comparison is canonical. func TestCardVectors(t *testing.T) { raw, err := os.ReadFile("../../test/event-vectors/cards.json") if err != nil { t.Fatalf("read vectors: %v", err) } var file struct { Schema int `json:"schema"` Vectors []struct { Name string `json:"name"` Card any `json:"card"` Want any `json:"want"` } `json:"vectors"` } if err := json.Unmarshal(raw, &file); err != nil { t.Fatalf("parse vectors: %v", err) } if file.Schema != cardSchema { t.Fatalf("vector schema %d != cardSchema %d", file.Schema, cardSchema) } for _, v := range file.Vectors { got, err := normalizeCard(v.Card) if v.Want == nil { if err == nil { t.Errorf("%s: want fail-closed, got %v", v.Name, got) } continue } if err != nil { t.Errorf("%s: %v", v.Name, err) continue } gotJSON, _ := json.Marshal(got) wantJSON, _ := json.Marshal(v.Want) if string(gotJSON) != string(wantJSON) { t.Errorf("%s:\n got %s\n want %s", v.Name, gotJSON, wantJSON) } } }