45 lines
1.7 KiB
Go
45 lines
1.7 KiB
Go
package link
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/novox/mesh-controller/internal/broker"
|
|
)
|
|
|
|
// The move's ask and answer keep the engine's field names (mesh-host internal/link,
|
|
// TestTheMovesAskKeepsItsFieldNamesAndContext): the row's fields beside a hand-over's, under a context of its own.
|
|
func TestTheMovesAskAndAnswerKeepTheirFieldNames(t *testing.T) {
|
|
keys := func(v any) string {
|
|
raw, _ := json.Marshal(v)
|
|
var m map[string]any
|
|
_ = json.Unmarshal(raw, &m)
|
|
var out []string
|
|
for k := range m {
|
|
out = append(out, k)
|
|
}
|
|
sort.Strings(out)
|
|
return strings.Join(out, " ")
|
|
}
|
|
ask := MoveSecretAsk{Module: "m", Name: "n", Provider: "p", Provision: "q", Consumer: "c", ConsumerModule: "cm",
|
|
Local: "l", Origin: "made", Generation: "g", MadeAt: time.Unix(1, 0).UTC(), Sealed: "s", SealedTo: "k"}
|
|
if got := keys(ask); got != "consumer consumer_module generation local made_at module name origin provider "+
|
|
"provision sealed sealed_to" {
|
|
t.Fatalf("the ask's fields are %q", got)
|
|
}
|
|
answer := MoveSecretAnswer{Said: "s", Refused: "r", Secret: "own/a/b/c", Generation: 1, Unchanged: true}
|
|
if got := keys(answer); got != "generation refused said secret unchanged" {
|
|
t.Fatalf("the answer's fields are %q", got)
|
|
}
|
|
if broker.AskMoveSecretSubject("laptop") != "mesh.node.laptop.ask.move-secret" ||
|
|
MoveSecretContext != "novox-mesh move-secret v1\n" {
|
|
t.Fatalf("the subject %q, the context %q", broker.AskMoveSecretSubject("laptop"), MoveSecretContext)
|
|
}
|
|
}
|
|
|
|
// A move is asked of the machine on its own subject, signed under its own context — never a hand-over's — naming
|
|
// no path and carrying the row beside the hand-over's fields; the engine's answer comes back whole.
|