Documentation
¶
Overview ¶
Package contracttest is shared by the conformance tests and the PostgreSQL tests: where the contract is, how a fixture runs, and how two JSON values are compared.
Index ¶
- Variables
- func AsWritten(value any) any
- func Cases(family string) []string
- func CheckContractVersion(lock any) (string, error)
- func Difference(expected, actual any, path string, options Options) string
- func EvidenceOf(value any) ae.Evidence
- func MustReadJSON(path string) any
- func ReadJSON(path string) (any, error)
- func RunFinalizeCase(input any) (ae.FinalizedExperience, *ae.Object, error)
- func ScopeOf(value any) ae.Scope
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( Contract = filepath.Join(Repository, "contract") Fixtures = filepath.Join(Contract, "fixtures") Schema = filepath.Join(Contract, "schema", "experience-record.v1.json") Migrations = filepath.Join(Repository, "src", "AgentExperience.Storage.Postgres", "Migrations") )
Paths into the repository.
var ErrUnsupportedContractVersion = errors.New("unsupported contract version")
ErrUnsupportedContractVersion is a lock naming a contract version this package does not support.
var Repository = func() string { _, file, _, ok := runtime.Caller(0) if !ok { panic("contracttest: cannot locate the repository") } return filepath.Clean(filepath.Join(filepath.Dir(file), "..", "..", "..")) }()
Repository is the repository's root directory.
Functions ¶
func AsWritten ¶
AsWritten is a value as this package writes it, read back: what is compared is what the package would write.
func CheckContractVersion ¶
CheckContractVersion is the lock's contract version, when this package supports it; a clear failure otherwise.
func Difference ¶
Difference is the first difference between two JSON values (as ae.DecodeJSON reads them), compared by value; "" when they are equal. Member order is ignored.
func EvidenceOf ¶
EvidenceOf reads one piece of a fixture's evidence.
func MustReadJSON ¶
MustReadJSON is ReadJSON, panicking on failure: for fixtures, which are known to exist.
func ReadJSON ¶
ReadJSON reads a JSON file, keeping every number exactly as written and every object's member order.
func RunFinalizeCase ¶
RunFinalizeCase runs a finalize case's input.json through capture and finalization. It returns the result and what capture answered, in expected-capture.json's form.
Types ¶
type Options ¶
type Options struct {
// Tolerance is the largest difference two numbers may have; 0 compares them exactly.
Tolerance float64
// IgnoreKind compares numbers by value only. By default an integer literal (no fraction, no exponent) never
// equals a number written with a fraction or an exponent, so a double is never written as an integer or the
// other way round. PostgreSQL's jsonb rewrites numbers in its own form (1E2 as 100), so a value read back from
// it is compared by value only.
IgnoreKind bool
}
Options change how Difference compares numbers.