Files
mesh-delivery/modules/mesh-delivery-view/cmd/mesh-delivery-view/main_test.go
T
jschoubben d151033dae View: the pipelines heard kept for the pages is the setting pipelines-heard
The view kept the last change of at most 1024 pipelines for its pages, a
cap written into the code. A cap is a setting with a default (principle
11): the manifest gives pipelines-heard, 1024 by default, written into a
file of the state directory the process reads at its start. The cap is
kept, not removed: without it the pipelines heard grow without end over
the view's life.

Issue 1983, review round 1 finding 3.
Builds: design 47 H2 H-A-467 (1)
2026-11-22 11:45:32 +01:00

62 lines
1.7 KiB
Go

package main
import (
"context"
"encoding/json"
"io"
"os"
"path/filepath"
"strings"
"testing"
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
)
func TestRunNeedsItsCredential(t *testing.T) {
err := run(context.Background(), func(string) string { return "" }, io.Discard)
if err == nil || !strings.Contains(err.Error(), "MESH_BROKER_FILE") {
t.Fatalf("run = %v, want a refusal naming MESH_BROKER_FILE", err)
}
}
// The setting pipelines-heard is read from the file the node-engine writes, its default where none is written (principle 11).
func TestNumberFileReadsASetting(t *testing.T) {
dir := t.TempDir()
write := func(name, v string) string {
p := filepath.Join(dir, name)
if err := os.WriteFile(p, []byte(v), 0o600); err != nil {
t.Fatal(err)
}
return p
}
for _, r := range []struct {
name, path string
want int
fails bool
}{
{"no file named is the default", "", 1024, false},
{"a file not written is the default", filepath.Join(dir, "none"), 1024, false},
{"an empty file is the default", write("empty", "\n"), 1024, false},
{"a number is read", write("seven", "7\n"), 7, false},
{"zero is refused", write("zero", "0"), 0, true},
{"words are refused", write("words", "many"), 0, true},
} {
t.Run(r.name, func(t *testing.T) {
n, err := numberFile(r.path, 1024)
if (err != nil) != r.fails || n != r.want {
t.Errorf("numberFile = %d, %v; want %d, failing %v", n, err, r.want, r.fails)
}
})
}
}
// rawAsk is the router's ask as the JSON a gate's or an assigner's value carries (mesh-sdk keeps it raw, ADR 0627 section 4).
func rawAsk(t *testing.T, a oc.Ask) json.RawMessage {
t.Helper()
b, err := json.Marshal(a)
if err != nil {
t.Fatal(err)
}
return b
}