mesh/delivery merged: source.main moved to novox/mesh-controller@2bcd85d2df4c
mesh/check pass ac34bce49f58 on 2bcd85d2df4c | unit 966 run, 171 kept, 2 skipped | integration 1625 run, 232 kept, 7 skipped | over bound: integration…
A catalogue merge that leaves a module's sources alone registers it at the new commit from the same done key, whose build record stands at its first commit, so the commit had no build and the module no fingerprint of the new form: it went into the node's own composition while its want named its own, and every node declared its files twice. currentFingerprints now reads the indexer's trunk value at the commit when no build points at it (1945/AC15), and a module a want or have names by its own composition is left out of the node's own (1945/AC16).
94 lines
3.8 KiB
Go
94 lines
3.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
sdkdelivery "git.novox.be/novox/mesh-sdk/go/delivery"
|
|
|
|
"github.com/novox/mesh-controller/internal/builderkeys"
|
|
)
|
|
|
|
// 1945/AC15 (unit): a module registered at a commit no build record points at (a catalogue merge re-indexed it with
|
|
// the fingerprint it had, and the take-in registered it from the done key whose record stands at its first commit)
|
|
// has, as its current fingerprint, the one the indexer's trunk value at that commit names; a module whose commit has a
|
|
// build keeps that build's; a module the indexer names nothing of the new form for has none; an indexer error is the
|
|
// answer's, never a module silently left out.
|
|
func TestACommitWithNoBuildOfItsOwnTakesTheIndexersFingerprint(t *testing.T) {
|
|
zsh, board := grantFP('a'), grantFP('b')
|
|
commits := map[string]string{"zsh": "68f7431d98d7", "board": "2167b95a1111", "legacy": "abcdef012345", "held": ""}
|
|
built := func(_ context.Context, module, commit string) (string, bool, error) {
|
|
if module == "board" {
|
|
return board, true, nil
|
|
}
|
|
return "", false, nil
|
|
}
|
|
indexed := func(_ context.Context, module, commit string) (string, error) {
|
|
switch module {
|
|
case "zsh":
|
|
return zsh, nil
|
|
case "board":
|
|
t.Errorf("the indexer was asked for board, whose commit has a build")
|
|
case "held":
|
|
t.Errorf("the indexer was asked for a module with no commit")
|
|
}
|
|
return "", nil
|
|
}
|
|
got, err := fingerprintsAt(context.Background(), commits, built, indexed)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got["zsh"] != zsh || got["board"] != board || len(got) != 2 {
|
|
t.Errorf("got %v, want zsh at %s and board at %s alone", got, zsh, board)
|
|
}
|
|
|
|
broken := func(context.Context, string, string) (string, error) { return "", errors.New("the bus is gone") }
|
|
if _, err := fingerprintsAt(context.Background(), commits, built, broken); err == nil {
|
|
t.Errorf("an indexer error was not the answer's")
|
|
}
|
|
}
|
|
|
|
// fakeTrunk is the indexer's trunk values of one module: now, and its history by commit.
|
|
type fakeTrunk struct {
|
|
now *sdkdelivery.Module
|
|
history map[string]sdkdelivery.Module
|
|
asked []string
|
|
}
|
|
|
|
func (f *fakeTrunk) ModuleAt(_ context.Context, module, commit string) (sdkdelivery.Module, error) {
|
|
f.asked = append(f.asked, commit)
|
|
if commit == "" {
|
|
if f.now == nil {
|
|
return sdkdelivery.Module{}, fmt.Errorf("%w (%s)", builderkeys.ErrNoValue, module)
|
|
}
|
|
return *f.now, nil
|
|
}
|
|
m, ok := f.history[commit]
|
|
if !ok {
|
|
return sdkdelivery.Module{}, fmt.Errorf("%w (%s at %s)", builderkeys.ErrNoValue, module, commit)
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// 1945/AC15 (unit): the indexer's fingerprint at a commit is read from the value it holds now when that is the
|
|
// commit's (one read), else from the key's history at the commit; none held is no fingerprint.
|
|
func TestTheIndexersFingerprintAtACommit(t *testing.T) {
|
|
now := sdkdelivery.Module{Commit: "68f7431d98d7a1279cba3a615b6e9f22c3295783", FP2: grantFP('a')}
|
|
f := &fakeTrunk{now: &now}
|
|
if fp, err := indexedFingerprintAt(context.Background(), f, "zsh", "68f7431d98d7a1279cba3a615b6e9f22c3295783"); err != nil || fp != grantFP('a') || len(f.asked) != 1 {
|
|
t.Errorf("now's commit: %q (%v), asked %v", fp, err, f.asked)
|
|
}
|
|
f = &fakeTrunk{now: &now, history: map[string]sdkdelivery.Module{"2167b95a": {Commit: "2167b95a", FP2: grantFP('c')}}}
|
|
if fp, err := indexedFingerprintAt(context.Background(), f, "zsh", "2167b95a"); err != nil || fp != grantFP('c') {
|
|
t.Errorf("an older commit: %q (%v)", fp, err)
|
|
}
|
|
if fp, err := indexedFingerprintAt(context.Background(), f, "zsh", "99999999"); err != nil || fp != "" {
|
|
t.Errorf("a commit the indexer never wrote: %q (%v)", fp, err)
|
|
}
|
|
if fp, err := indexedFingerprintAt(context.Background(), &fakeTrunk{}, "zsh", "68f7431d"); err != nil || fp != "" {
|
|
t.Errorf("no value at all: %q (%v)", fp, err)
|
|
}
|
|
}
|