The delivery repository's contracts and SDK live under modules/ as mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths renamed to match the folders (the TypeScript names already did), and every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools and mesh-sdk follows in the same group: a design as it should be, one path per module, checked by the group's check building every importer. Builds: design 47 G §427, §88 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
58 lines
2.4 KiB
Go
58 lines
2.4 KiB
Go
package meshbuildsclient
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
)
|
|
|
|
func answers(raw string, err error) Call {
|
|
return func(address string, body any) (json.RawMessage, error) {
|
|
if address != "seat:mesh-builds.reserved" {
|
|
return nil, errors.New("asked " + address)
|
|
}
|
|
return json.RawMessage(raw), err
|
|
}
|
|
}
|
|
|
|
// TestReservedReadsEachAnswer is design 47 G §586's check: the client's input and each answer read (§679's three).
|
|
func TestReservedReadsEachAnswer(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
call Call
|
|
want Reservation
|
|
refusal string
|
|
failedOn string
|
|
}{
|
|
{name: "a reservation", call: answers(`{"module":"m","version":"0.1.2","artifacts":[{"artifact":"m:go-m","digest":"sha256:aa"}]}`, nil),
|
|
want: Reservation{Module: "m", Version: "0.1.2", Artifacts: []seat.ReservedAnswerArtifactsItem{{Artifact: "m:go-m", Digest: "sha256:aa"}}}},
|
|
{name: "a release", call: answers(`{"module":"m","version":"0.1.1","artifacts":[{"artifact":"m:go-m","digest":"sha256:bb"}],"released":true}`, nil),
|
|
want: Reservation{Module: "m", Version: "0.1.1", Artifacts: []seat.ReservedAnswerArtifactsItem{{Artifact: "m:go-m", Digest: "sha256:bb"}}, Released: true}},
|
|
{name: "an error alone", call: answers(`{"error":"no entry carries the name x"}`, nil), refusal: "no entry carries the name x"},
|
|
{name: "no module and no error", call: answers(`{}`, nil), failedOn: "answered no reservation"},
|
|
{name: "a call that fails", call: answers("", errors.New("no responders")), failedOn: "did not answer"},
|
|
{name: "what cannot be read", call: answers(`[1]`, nil), failedOn: "cannot be read"},
|
|
} {
|
|
got, err := Reserved(tc.call, seat.ReservedInput{Name: "x", Version: "0.1.1"})
|
|
var r Refusal
|
|
switch {
|
|
case tc.refusal != "":
|
|
if !errors.As(err, &r) || r.Words != tc.refusal {
|
|
t.Errorf("%s: %v, want a refusal %q", tc.name, err, tc.refusal)
|
|
}
|
|
case tc.failedOn != "":
|
|
if err == nil || !strings.Contains(err.Error(), tc.failedOn) {
|
|
t.Errorf("%s: %v, want an error saying %q", tc.name, err, tc.failedOn)
|
|
}
|
|
default:
|
|
if err != nil || got.Module != tc.want.Module || got.Version != tc.want.Version || got.Released != tc.want.Released ||
|
|
len(got.Artifacts) != 1 || got.Artifacts[0] != tc.want.Artifacts[0] {
|
|
t.Errorf("%s: %+v %v, want %+v", tc.name, got, err, tc.want)
|
|
}
|
|
}
|
|
}
|
|
}
|