The shared publish names the ask's own fingerprint on a publish that names none. The kit's Bed gains HoldWith, PublishWith and Held. Builds: design 47 H2 H-A-589 (4), H-A-589 (5), H-A-591, H-A-593 (2) (3), H-A-738 (1)
60 lines
2.6 KiB
Go
60 lines
2.6 KiB
Go
package steprun
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
reg "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/parts"
|
|
)
|
|
|
|
// Design 47 H2 H-A-589 (4), H-A-738 (1): a publish answered other-bytes carrying the publish's own fingerprint is answered
|
|
// as published with the held digest: the ask's record names it, the step log names both digests, and nothing is sent; with
|
|
// another or no fingerprint it is refused naming both.
|
|
func TestAPublishOfAHeldVersionIsAnsweredWithTheHeldDigest(t *testing.T) {
|
|
const built, held = "sha256:aaaa", "sha256:bbbb"
|
|
for _, c := range []struct {
|
|
name, kept, ask string
|
|
answered string
|
|
refused bool
|
|
}{
|
|
{"the same fingerprint", "src2:f1", "src2:f1", held, false},
|
|
{"another fingerprint", "src2:f2", "src2:f1", "", true},
|
|
{"no kept fingerprint", "", "src2:f1", "", true},
|
|
{"no fingerprint of its own", "src2:f1", "", "", true},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
var log []string
|
|
ctx := context.WithValue(context.Background(), phaseKey{}, &phases{logf: func(f string, a ...any) { log = append(log, fmt.Sprintf(f, a...)) }})
|
|
ctx, record := withPublish(ctx, c.ask)
|
|
calls := 0
|
|
call := func(key string, in any) (json.RawMessage, error) {
|
|
calls++
|
|
raw, _ := json.Marshal(in)
|
|
if want := c.ask; want != "" && !strings.Contains(string(raw), want) && strings.HasSuffix(key, ".publish") {
|
|
t.Errorf("the publish %s names no fingerprint %s of the ask", raw, want)
|
|
}
|
|
other := map[string]any{"digest": held}
|
|
if c.kept != "" {
|
|
other["fingerprint"] = c.kept
|
|
}
|
|
return json.Marshal(map[string]any{"other-bytes": other})
|
|
}
|
|
in := reg.PublishInput{Name: "x/y", Kind: reg.PublishInputKindArchive, Version: "0.1.0", Digest: built, Transfer: "t"}
|
|
sent, err := PublishParts(ctx, call, GoSeat, in, []parts.Part{{Digest: built, Size: 1, Open: nil}})
|
|
if (err != nil) != c.refused || record.Answered() != c.answered || calls != 1 || sent.Other == nil {
|
|
t.Fatalf("answered %q, err %v after %d calls (other %+v), want answered %q and refused %v with the one publish call", record.Answered(), err, calls, sent.Other, c.answered, c.refused)
|
|
}
|
|
if c.refused && !(strings.Contains(err.Error(), built) && strings.Contains(err.Error(), held)) {
|
|
t.Errorf("the refusal %v does not name both digests", err)
|
|
}
|
|
if !c.refused && !(strings.Contains(strings.Join(log, "\n"), built) && strings.Contains(strings.Join(log, "\n"), held)) {
|
|
t.Errorf("the step log %q does not name both digests", log)
|
|
}
|
|
})
|
|
}
|
|
}
|