MCPcopy
hub / github.com/bettercap/bettercap / TestSessionCommandHandler

Function TestSessionCommandHandler

session/command_handler_test.go:28–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestSessionCommandHandler(t *testing.T) {
29 var units = []struct {
30 expr string
31 panic bool
32 parsed []string
33 }{
34 {"notvali(d", true, nil},
35 {`simple\s+(\d+)`, false, []string{"123"}},
36 }
37
38 for _, u := range units {
39 if u.panic {
40 assertPanic(t, "", func() {
41 _ = NewCommandHandler("", u.expr, "", nil)
42 t.Fatal("panic expected")
43 })
44 } else {
45 c := NewCommandHandler("", u.expr, "", nil)
46 shouldNotParse := "simple123"
47 shouldParse := "simple 123"
48
49 if parsed, _ := c.Parse(shouldNotParse); parsed {
50 t.Fatalf("should not parse '%s'", shouldNotParse)
51 } else if parsed, parts := c.Parse(shouldParse); !parsed {
52 t.Fatalf("should parse '%s'", shouldParse)
53 } else if !sameStrings(parts, u.parsed) {
54 t.Fatalf("expected '%v', got '%v'", u.parsed, parts)
55 }
56 }
57 }
58}

Callers

nothing calls this directly

Calls 5

ParseMethod · 0.95
assertPanicFunction · 0.85
NewCommandHandlerFunction · 0.85
sameStringsFunction · 0.85
FatalMethod · 0.45

Tested by

no test coverage detected