distribution's tag of mesh-delivery-pipeline 0.1.6 was refused: reserved answered 'no entry carries the name mesh-delivery-pipeline/program', since the lookup matched only an artifact's package name and a bundle's entry names none. A bundle's or an archive's name is <module>/<artifact>, read from its reference through NameOf; a name no entry carries is said in the builder's log with the entries looked at. Builds: design 47 G A-418, §478, §572
51 lines
2.5 KiB
Go
51 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
// Design 47 G A-115, A-127: the builder's process answers the verb reserved, given a name, from the catalog half's carriers and the
|
|
// seat mesh-catalog's versions, and given a module from its reservations.
|
|
func TestTheProcessAnswersReserved(t *testing.T) {
|
|
none := versions.Reader{Keys: func() ([]string, error) { return nil, nil }, Get: func(string) (json.RawMessage, bool, error) { return nil, false, nil }}
|
|
carriers := func(_ context.Context, name string) ([]versions.Built, error) {
|
|
if name == "@novox/mesh-sdk" {
|
|
return []versions.Built{{Module: "mesh-sdk", Artifact: "ts"}}, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
var asked []string
|
|
released := catalogReleased(func(key string, _ any) (json.RawMessage, error) {
|
|
asked = append(asked, key)
|
|
return json.Marshal(meshcatalog.VersionsAnswer{Versions: []meshcatalog.VersionEntry{{Module: "mesh-sdk", Version: "0.1.2",
|
|
Artifacts: []meshcatalog.VersionArtifact{{Artifact: "mesh-sdk:ts", Digest: "sha256:dd"}}}}})
|
|
})
|
|
var missed []string
|
|
handle := reservedVerb(context.Background(), none, carriers, released, func(name string) { missed = append(missed, name) })
|
|
got, err := handle("", json.RawMessage(`{"name":"@novox/mesh-sdk","version":"0.1.2"}`))
|
|
a, ok := got.(meshbuilds.ReservedAnswer)
|
|
if err != nil || !ok || !a.Released || a.Module != "mesh-sdk" || len(a.Artifacts) != 1 || a.Artifacts[0].Digest != "sha256:dd" {
|
|
t.Fatalf("reserved by name = %+v (%v)", got, err)
|
|
}
|
|
if len(asked) != 1 || asked[0] != "seat:mesh-catalog.versions" {
|
|
t.Errorf("the released versions were asked of %v, want the seat mesh-catalog's versions", asked)
|
|
}
|
|
// Design 47 G A-418: a name no entry carries is answered error and told for the builder's log.
|
|
if got, err := handle("", json.RawMessage(`{"name":"nobody/program","version":"0.1.6"}`)); err != nil || got.(meshbuilds.ReservedAnswer).Error == "" || len(missed) != 1 || missed[0] != "nobody/program" {
|
|
t.Errorf("a name no entry carries: %+v (%v), told %v", got, err, missed)
|
|
}
|
|
if _, err := handle("", json.RawMessage(`{"module":"mesh-sdk"}`)); err == nil {
|
|
t.Error("a module with no reservation was answered")
|
|
}
|
|
if _, err := handle("", json.RawMessage(`{"module":`)); err == nil {
|
|
t.Error("arguments that are no JSON were answered")
|
|
}
|
|
}
|