57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package buckets
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"encoding/json"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// The engine's own states are named <module>_<state> by the manifest; a constant that drifts from it reads and writes a
|
|
// bucket nobody else knows (ADR 0634 §1, finding F4: the holder's name is kept in code and held to the manifest by this row).
|
|
func TestTheOwnStatesAreTheManifestsStates(t *testing.T) {
|
|
raw, err := os.ReadFile("../../module.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
Module string `json:"module"`
|
|
State []struct {
|
|
Name string `json:"name"`
|
|
} `json:"state"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
declared := map[string]bool{}
|
|
for _, s := range m.State {
|
|
declared[m.Module+"_"+s.Name] = true
|
|
}
|
|
for name, bucket := range map[string]string{"data": Data, "health": Health} {
|
|
if !declared[bucket] {
|
|
t.Errorf("the bucket %s for the state %s is not one the manifest of %s declares (%v)", bucket, name, m.Module, declared)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A group's candidate key is its name as a key part: a branch with a slash keeps it, a dot is escaped, and an empty group does not.
|
|
func TestACandidateKeyEscapesTheGroup(t *testing.T) {
|
|
for _, group := range []string{"mesh-sdk#7", "fix/940-no-retire", "fix/1.2"} {
|
|
key, err := CandidateKey(group)
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", group, err)
|
|
}
|
|
if strings.Contains(key, ".") {
|
|
t.Errorf("the key %q of %q holds a dot", key, group)
|
|
}
|
|
if back, err := keys.UnescapeName(key); err != nil || back != group {
|
|
t.Errorf("%q came back as %q (%v)", group, back, err)
|
|
}
|
|
}
|
|
if _, err := CandidateKey(""); err == nil {
|
|
t.Error("a key was made for no group")
|
|
}
|
|
}
|