Files
platform/projection/helpers_test.go
T
2026-06-29 13:17:43 +02:00

59 lines
1.7 KiB
Go

// Local helpers for the snapshot / holder tests — production code does not see
// them. tProj is a stand-in stored value; the projection package is
// value-agnostic, so the tests use a small local struct instead of depending on
// catalog.Projection (the type these tests were extracted alongside).
package projection
import "os"
// tProj mirrors the fields the ported catalog snapshot tests exercise. Prices
// are plain int64 here (no money dependency in the generic package).
type tProj struct {
ID string `json:"id"`
SKU string `json:"sku"`
Title string `json:"title,omitempty"`
PriceIncVat int64 `json:"price_inc_vat"`
Currency string `json:"currency,omitempty"`
TaxClass string `json:"tax_class,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
}
func os2WriteFile(path string, data []byte, perm os.FileMode) error {
return os.WriteFile(path, data, perm)
}
func os2Stat(path string) (os.FileInfo, error) {
return os.Stat(path)
}
func os2ReadFile(path string) ([]byte, error) {
return os.ReadFile(path)
}
// appendP appends a tProj keyed by its own SKU — the producer/test pattern over
// the generic SnapshotWriter (Append takes an explicit key).
func appendP(w *SnapshotWriter[tProj], p tProj) error {
return w.Append(p.SKU, p)
}
// makeProjection builds a tProj fixture.
func makeProjection(sku string, price int64) tProj {
return tProj{
ID: "sku:" + sku,
SKU: sku,
Title: "Item " + sku,
PriceIncVat: price,
Currency: "SEK",
TaxClass: "standard",
UpdatedAt: 1,
}
}
func repeat32(s string, n int) string {
out := make([]byte, 0, n*len(s))
for i := 0; i < n; i++ {
out = append(out, s...)
}
return string(out)
}