oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package wire_test
2
3import (
4 "strings"
5 "testing"
6
7 "amadan.net/oficina/equipo/internal/wire"
8)
9
10// Whole-branch fix 1, #6: a probe's detail is codes with parameters,
11// never words; what the instance cannot decode is not shown.
12func TestProbeDetailCoded(t *testing.T) {
13 d := wire.ProbeDetails(wire.ProbeDetail("allowed", "home.cat tcp"), "", wire.ProbeDetail("not_run"), wire.ProbeDetail("xcode", "26.2", "17C52"))
14 parts, ok := wire.ParseProbeDetail(d)
15 if !ok || len(parts) != 3 || parts[0].Code != "allowed" || parts[0].Params[0] != "home.cat tcp" || parts[1].Code != "not_run" || len(parts[1].Params) != 0 || parts[2].Params[1] != "17C52" {
16 t.Fatalf("%q: %+v %v", d, parts, ok)
17 }
18 // Separators and the capability string's forbidden characters never
19 // survive in a parameter.
20 p := wire.ProbeDetail("still_running", "a;b,c:d/e=f\ng")
21 if parts, ok := wire.ParseProbeDetail(p); !ok || len(parts) != 1 || strings.ContainsAny(parts[0].Params[0], ";,:/=\n") {
22 t.Fatalf("%q: %+v %v", p, parts, ok)
23 }
24 if err := wire.ValidCapabilities(wire.Capabilities{Probes: []wire.Probe{{ID: "P6", Verdict: wire.ProbeFailed, Detail: p}}}); err != nil {
25 t.Fatalf("a coded detail refused: %v", err)
26 }
27 // Words, an unknown code or the wrong number of parameters: not a
28 // part.
29 for _, bad := range []string{"not run yet", "nope", "allowed", "allowed:a,b", "not_run:x", "allowed: home.cat", "allowed:"} {
30 if parts, ok := wire.ParseProbeDetail(bad); ok || len(parts) != 0 {
31 t.Errorf("%q decoded: %+v", bad, parts)
32 }
33 }
34 // Whole parts only, within the capability string bound.
35 long := wire.ProbeDetails(wire.ProbeDetail("allowed", strings.Repeat("x", 200)), wire.ProbeDetail("not_shown_denied", strings.Repeat("y", 200)), wire.ProbeDetail("not_collected", strings.Repeat("z", 200)))
36 if parts, ok := wire.ParseProbeDetail(long); !ok || len(parts) != 2 || len(long) > wire.MaxCapabilityString {
37 t.Fatalf("%d bytes: %+v %v", len(long), parts, ok)
38 }
39 for code := range wire.ProbeDetailCodes {
40 if code == "" || strings.ContainsAny(code, ";,: ") {
41 t.Errorf("code %q", code)
42 }
43 }
44}
45