Files
mesh-controller/cmd/mesh-controller/register_test.go
T

39 lines
1.5 KiB
Go

package main
import (
"context"
"errors"
"strings"
"testing"
sdkdelivery "git.novox.be/novox/mesh-sdk/go/delivery"
)
// A11b (ADR 0501 §4): the terminal's registration names exactly the module's repository and path the indexer holds,
// and no verb reaches it.
func TestTheTerminalsRegistrationNamesItsSourceExactlyAndNoVerbReachesIt(t *testing.T) {
trunk := sdkdelivery.Module{Repository: "someone/app", Path: sdkdelivery.RootPath, Commit: "c0ffee"}
if err := sameModuleSource("app", "someone/app", "", trunk); err != nil {
t.Fatalf("the source the indexer holds is refused: %v", err)
}
if err := sameModuleSource("app", "someone/other", "", trunk); err == nil || !strings.Contains(err.Error(), "someone/app") {
t.Fatalf("another repository is taken: %v", err)
}
if err := sameModuleSource("app", "someone/app", "modules/app", trunk); err == nil {
t.Fatal("another path is taken")
}
// The generic verb only reads; and register is the terminal's only, whatever reads.
if _, err := argvFor("command", map[string]any{"command": "register app someone/app ."}); err == nil {
t.Fatal("a verb reaches the terminal's registration")
}
var refused *heldAtTheTerminal
if err := terminalOnly([]string{"register", "app", "someone/app", "."}); !errors.As(err, &refused) {
t.Fatalf("register is not the terminal's only: %v", err)
}
t.Setenv(verbVar, "command")
var held *heldAtTheTerminal
if err := registerCommand(context.Background(), []string{"app", "someone/app", "."}); !errors.As(err, &held) {
t.Fatalf("register through a verb: %v", err)
}
}