71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
// Helpers the tests of the deleted plan machinery shared with tests that remain.
|
|
|
|
func nodeID(t *testing.T, open *stores, name string) string {
|
|
t.Helper()
|
|
n, err := open.inventory.NodeByName(context.Background(), name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return n.ID
|
|
}
|
|
|
|
func bodyKeys(t *testing.T, s sendable) map[string]any {
|
|
t.Helper()
|
|
raw, err := s.Body()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var keys map[string]any
|
|
if err := json.Unmarshal(raw, &keys); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return keys
|
|
}
|
|
|
|
// theDeliveryClaims is a catalogue whose one module claiming the seat is today's mesh-delivery, for the tests that
|
|
// announce a merge from it.
|
|
func theDeliveryClaims(context.Context) ([]inventory.Entry, error) {
|
|
return []inventory.Entry{claimingTheSeat("mesh-delivery")}, nil
|
|
}
|
|
|
|
func claimingTheSeat(module string) inventory.Entry {
|
|
return inventory.Entry{Manifest: catalogue.Manifest{Module: module,
|
|
Claims: []catalogue.Claim{{Name: catalogue.DeliverySeat, Scope: catalogue.ScopeMesh}}}, On: []string{"anchor"}}
|
|
}
|
|
|
|
func aContainer(name string) catalogue.Manifest {
|
|
return catalogue.Manifest{Module: name, Version: "1",
|
|
Resources: []map[string]any{{"id": name, "type": "container", "image": name}}}
|
|
}
|
|
|
|
// pushedBy composes a machine's declaration as the compositions are made, so its own secrets are made, and answers its digest.
|
|
// Nothing records a send: there is none (ADR 0539 §5).
|
|
func pushedBy(t *testing.T, open *stores, node string) string {
|
|
t.Helper()
|
|
ctx := t.Context()
|
|
plan, settings, err := resolveNode(ctx, open, node)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
declared, err := declarationFor(ctx, open, node, plan, settings)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body, err := declared.Body()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return digestOf(body)
|
|
}
|