A delivery and the five-minute reconcile were two paths that applied, ordered only by a lock, and each order it allowed was met live (issues 257, 261, 267). Now both only enqueue: one worker takes the newest declaration held when it starts, applies it once and makes one report, and reports leave in the order they are made. A declaration may carry the controller's lease epoch beside its sequence; one older than what this node applied is refused before anything is touched, counted, logged and reported. A report carries the declaration's epoch and sequence and the host's own report sequence, kept on disk so it goes on increasing across restarts and self-updates. Without an epoch, today's behaviour stands.
38 lines
1.5 KiB
Go
38 lines
1.5 KiB
Go
package validate
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// **The validator a controller imports is the host's**: a declaration the host takes passes, and one
|
|
// it refuses is refused with the host's own words, every problem at once.
|
|
func TestTheValidatorIsTheHosts(t *testing.T) {
|
|
good := `{"declaration": 1, "resources": [{"id": "d", "type": "directory", "path": "/var/lib/x", "mode": "0755"}]}`
|
|
if problems := Declaration([]byte(good)); problems != nil {
|
|
t.Fatalf("a declaration the host takes was refused: %v", problems)
|
|
}
|
|
// And one carrying the lease epoch and sequence the controller sends it under (novox/hq to-be 45
|
|
// §6): a controller validating with this package may send them.
|
|
ordered := `{"declaration": 1, "epoch": 57, "sequence": 3, "resources": [{"id": "d", "type": "directory", "path": "/var/lib/x", "mode": "0755"}]}`
|
|
if problems := Declaration([]byte(ordered)); problems != nil {
|
|
t.Fatalf("a declaration carrying its order was refused: %v", problems)
|
|
}
|
|
for _, bad := range []string{
|
|
`{"declaration": 1, "resources": []}`,
|
|
`{"declaration": 99, "resources": [{"id": "d", "type": "directory", "path": "/x"}]}`,
|
|
`{"declaration": 1, "resources": [{"id": "d", "type": "nothing-the-host-knows"}]}`,
|
|
`not json`,
|
|
} {
|
|
problems := Declaration([]byte(bad))
|
|
if len(problems) == 0 {
|
|
t.Errorf("a declaration the host refuses was passed: %s", bad)
|
|
}
|
|
for _, p := range problems {
|
|
if strings.TrimSpace(p) == "" {
|
|
t.Errorf("a problem said nothing, for %s", bad)
|
|
}
|
|
}
|
|
}
|
|
}
|