A module's name may contain a dot, so the derived step adds none
A resource's id is `<module>.<its own id>` and a module's name may itself contain a dot — novox.be is one — so the owner of a resource is everything before the *last* dot. The preparation step's id used a dot, which made its owner unreadable by that rule; it uses a hyphen, and the id says what it belongs to whichever way a reader splits it.
This commit is contained in:
@@ -1685,7 +1685,10 @@ func prepared(from map[string]any) map[string]any {
|
|||||||
for k, v := range from {
|
for k, v := range from {
|
||||||
step[k] = v
|
step[k] = v
|
||||||
}
|
}
|
||||||
step["id"] = fmt.Sprint(from["id"]) + ".prepare"
|
// **A hyphen, not a dot.** A resource's id is `<module>.<its own id>`, and a module's name may
|
||||||
|
// itself contain a dot (`novox.be`), so the module is everything before the *last* dot — which
|
||||||
|
// only works if what the mesh derives adds no dot of its own.
|
||||||
|
step["id"] = fmt.Sprint(from["id"]) + "-prepare"
|
||||||
step["name"] = fmt.Sprint(from["name"]) + "-prepare"
|
step["name"] = fmt.Sprint(from["name"]) + "-prepare"
|
||||||
step["run-once"] = true
|
step["run-once"] = true
|
||||||
step["args"] = []any{PreparationArgument}
|
step["args"] = []any{PreparationArgument}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package catalogue
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,13 +58,18 @@ func TestThePreparationRunsTheModulesOwnCodeAndComesRightBeforeIt(t *testing.T)
|
|||||||
ids := idsOf(out)
|
ids := idsOf(out)
|
||||||
at := -1
|
at := -1
|
||||||
for i, id := range ids {
|
for i, id := range ids {
|
||||||
if id == "gitea.runtime.prepare" {
|
if id == "gitea.runtime-prepare" {
|
||||||
at = i
|
at = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if at < 0 {
|
if at < 0 {
|
||||||
t.Fatalf("nothing prepares this module's state: %v", ids)
|
t.Fatalf("nothing prepares this module's state: %v", ids)
|
||||||
}
|
}
|
||||||
|
// A module's name may contain a dot, so a resource's module is everything before the last one —
|
||||||
|
// which the derived id must not add to, or a machine reads the wrong owner from it.
|
||||||
|
if strings.Count("gitea.runtime-prepare", ".") != 1 {
|
||||||
|
t.Fatal("the derived id adds a dot, so what owns it cannot be read from it")
|
||||||
|
}
|
||||||
if ids[at+1] != "gitea.runtime" {
|
if ids[at+1] != "gitea.runtime" {
|
||||||
t.Fatalf("the preparation is not immediately before the module's own code: %v", ids)
|
t.Fatalf("the preparation is not immediately before the module's own code: %v", ids)
|
||||||
}
|
}
|
||||||
@@ -79,7 +85,7 @@ func TestThePreparationRunsTheModulesOwnCodeAndComesRightBeforeIt(t *testing.T)
|
|||||||
func TestThePreparationIsGivenWhatTheModuleIsGiven(t *testing.T) {
|
func TestThePreparationIsGivenWhatTheModuleIsGiven(t *testing.T) {
|
||||||
out := declaredFor(t, aPreparingModule())
|
out := declaredFor(t, aPreparingModule())
|
||||||
declared := byID(out)
|
declared := byID(out)
|
||||||
step, workload := declared["gitea.runtime.prepare"], declared["gitea.runtime"]
|
step, workload := declared["gitea.runtime-prepare"], declared["gitea.runtime"]
|
||||||
if step == nil || workload == nil {
|
if step == nil || workload == nil {
|
||||||
t.Fatalf("expected both, got %v", idsOf(out))
|
t.Fatalf("expected both, got %v", idsOf(out))
|
||||||
}
|
}
|
||||||
@@ -108,7 +114,7 @@ func TestAModuleThatPreparesNothingGetsNoStep(t *testing.T) {
|
|||||||
m := aPreparingModule()
|
m := aPreparingModule()
|
||||||
m.Prepares = false
|
m.Prepares = false
|
||||||
for _, id := range idsOf(declaredFor(t, m)) {
|
for _, id := range idsOf(declaredFor(t, m)) {
|
||||||
if id == "gitea.runtime.prepare" {
|
if id == "gitea.runtime-prepare" {
|
||||||
t.Fatal("a module that prepares nothing was given a preparation")
|
t.Fatal("a module that prepares nothing was given a preparation")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user