Taken over from the join's 473f9323, 5f40d230, 159a679b; the events are the seat's pull-updated, pull-merged, pull-closed and forge-delete. Builds: design 47 G §252, §310, §312, §317 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Package gitfixture reads the seat git's own fixtures (contracts/seats/git/fixtures/verbs.json), so the bridge's unit
|
|
// fakes answer what the seat's holder answers and nothing the contract does not say (design 47 *The seat `git`*).
|
|
package gitfixture
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
// All is every fixture's body named name of of (such as "file answers", "verb:file.answer"), in the file's order; a
|
|
// name with none fails the test.
|
|
func All(t testing.TB, name, of string) []json.RawMessage {
|
|
t.Helper()
|
|
_, here, _, _ := runtime.Caller(0)
|
|
raw, err := os.ReadFile(filepath.Join(filepath.Dir(here), "../../../../contracts/seats/git/fixtures/verbs.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var all []struct {
|
|
Name, Of string
|
|
Given json.RawMessage
|
|
}
|
|
if err := json.Unmarshal(raw, &all); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var out []json.RawMessage
|
|
for _, f := range all {
|
|
if f.Name == name && f.Of == of {
|
|
out = append(out, f.Given)
|
|
}
|
|
}
|
|
if len(out) == 0 {
|
|
t.Fatalf("no fixture %q of %s", name, of)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Given is the first fixture's body named name of of.
|
|
func Given(t testing.TB, name, of string) json.RawMessage { t.Helper(); return All(t, name, of)[0] }
|