66 lines
2.8 KiB
Go
66 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/npmpackageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/ociartifactregistry"
|
|
|
|
"mesh-delivery-builder/internal/build"
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
// TestRepublishSend: design 47 G §588, A-73: a publish again is the registry seat's publish with the digest and no parts; the
|
|
// four seats take one wire form, a call's fault or an answer that lacks parts is the holder's refusal in its words, and its
|
|
// setting is read from the file the manifest declares.
|
|
func TestRepublishSend(t *testing.T) {
|
|
p := versions.Publish{Seat: versions.SeatArtifacts, Kind: "bundle", Name: "m/prog", Version: "0.1.3", Digest: "sha256:aa", Fingerprint: "src2:m", Commit: "c", Transfer: "t"}
|
|
want, _ := json.Marshal(publishBody(p))
|
|
if strings.Contains(string(want), "parts") {
|
|
t.Errorf("the publish names parts: %s", want)
|
|
}
|
|
for name, v := range map[string]any{"container image": containerimageregistry.PublishInput{Digest: "sha256:aa"}, "oci": ociartifactregistry.PublishInput{Digest: "sha256:aa"},
|
|
"go": gopackageregistry.PublishInput{Digest: "sha256:aa"}, "npm": npmpackageregistry.PublishInput{Digest: "sha256:aa"}} {
|
|
var ref, got map[string]any
|
|
a, _ := json.Marshal(gopackageregistry.PublishInput{Digest: "sha256:aa"})
|
|
b, _ := json.Marshal(v)
|
|
_ = json.Unmarshal(a, &ref)
|
|
_ = json.Unmarshal(b, &got)
|
|
if len(ref) != len(got) {
|
|
t.Errorf("the %s seat's publish input is %s, the go seat's %s: one wire form is sent to all four", name, b, a)
|
|
}
|
|
}
|
|
var asked string
|
|
for name, c := range map[string]struct {
|
|
answer string
|
|
err error
|
|
want string
|
|
}{
|
|
"held": {`{"held":true,"transfer":"t"}`, nil, ""},
|
|
"lacks": {`{"lacks":["sha256:bb"],"transfer":"t"}`, nil, versions.NotStoredWords},
|
|
"a fault": {"", errors.New("no responders"), "no responders"},
|
|
"no sense": {`[`, nil, "no publish answer"},
|
|
} {
|
|
send := sendVia(func(key string, body any) (json.RawMessage, error) {
|
|
asked = key
|
|
return json.RawMessage(c.answer), c.err
|
|
})
|
|
err := send(context.Background(), p)
|
|
if asked != "seat:oci-artifact-registry.publish" || (c.want == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), c.want)) {
|
|
t.Errorf("%s: asked %q, error %v, want %q", name, asked, err, c.want)
|
|
}
|
|
}
|
|
if _, _, err := build.NewRepublish("", "0.1.3", "why", "me", versionsNow()); err == nil {
|
|
t.Error("a version with no module is accepted")
|
|
}
|
|
}
|
|
|
|
func versionsNow() time.Time { return time.Unix(1, 0) }
|