(t *testing.T)
| 26 | } |
| 27 | |
| 28 | func TestBuiltinMemory_MoreDispatch(t *testing.T) { |
| 29 | fake := &fakeMemAdapter{} |
| 30 | SetMemoryAdapter(fake) |
| 31 | t.Cleanup(func() { SetMemoryAdapter(nil) }) |
| 32 | |
| 33 | p := NewBuiltinMemoryPlugin() |
| 34 | ctx := context.Background() |
| 35 | |
| 36 | // recall |
| 37 | if _, err := p.Execute(ctx, []string{`{"cmd":"recall","args":{"query":"certs"}}`}); err != nil { |
| 38 | t.Fatalf("recall: %v", err) |
| 39 | } |
| 40 | if fake.lastRecall != "certs" { |
| 41 | t.Errorf("recall query not propagated: %q", fake.lastRecall) |
| 42 | } |
| 43 | |
| 44 | // profile with the bare (no "fields" wrapper) form |
| 45 | if _, err := p.Execute(ctx, []string{`{"cmd":"profile","args":{"role":"SRE"}}`}); err != nil { |
| 46 | t.Fatalf("profile bare: %v", err) |
| 47 | } |
| 48 | if fake.lastProfile["role"] != "SRE" { |
| 49 | t.Errorf("bare profile form not parsed: %v", fake.lastProfile) |
| 50 | } |
| 51 | |
| 52 | // argv (flag) form instead of JSON envelope |
| 53 | if _, err := p.Execute(ctx, []string{"remember", "--content", "argv fact"}); err != nil { |
| 54 | t.Fatalf("argv form: %v", err) |
| 55 | } |
| 56 | if fake.lastRemember[0] != "argv fact" { |
| 57 | t.Errorf("argv form not parsed: %v", fake.lastRemember) |
| 58 | } |
| 59 | |
| 60 | // graph folded into @memory: neighbors routes the query through to the graph |
| 61 | if _, err := p.Execute(ctx, []string{`{"cmd":"neighbors","args":{"query":"auth"}}`}); err != nil { |
| 62 | t.Fatalf("neighbors: %v", err) |
| 63 | } |
| 64 | if fake.lastNeighbors != "auth" { |
| 65 | t.Errorf("neighbors query not propagated: %q", fake.lastNeighbors) |
| 66 | } |
| 67 | // map needs no args |
| 68 | if out, err := p.Execute(ctx, []string{`{"cmd":"map"}`}); err != nil || out != "map" { |
| 69 | t.Fatalf("map: out=%q err=%v", out, err) |
| 70 | } |
| 71 | // neighbors without query -> error |
| 72 | if _, err := p.Execute(ctx, []string{`{"cmd":"neighbors","args":{}}`}); err == nil { |
| 73 | t.Error("expected error for neighbors without query") |
| 74 | } |
| 75 | |
| 76 | // unknown cmd -> error |
| 77 | if _, err := p.Execute(ctx, []string{`{"cmd":"bogus","args":{}}`}); err == nil { |
| 78 | t.Error("expected error for unknown cmd") |
| 79 | } |
| 80 | // forget without match -> error |
| 81 | if _, err := p.Execute(ctx, []string{`{"cmd":"forget","args":{}}`}); err == nil { |
| 82 | t.Error("expected error for forget without match") |
| 83 | } |
| 84 | } |
| 85 |
nothing calls this directly
no test coverage detected