MCPcopy
hub / github.com/bettercap/bettercap / TestNewModuleHandler

Function TestNewModuleHandler

session/module_handler_test.go:9–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestNewModuleHandler(t *testing.T) {
10 type args struct {
11 name string
12 expr string
13 desc string
14 exec func(args []string) error
15 }
16 tests := []struct {
17 name string
18 args args
19 want ModuleHandler
20 }{
21 {
22 name: "Test NewModuleHandler empty expr",
23 args: args{name: "test name", desc: "test description"},
24 want: ModuleHandler{Name: "test name", Description: "test description"},
25 },
26 {
27 name: "Test NewModuleHandler normal",
28 args: args{name: "test name", desc: "test description", expr: `[a-z]`},
29 want: ModuleHandler{Name: "test name", Description: "test description", Parser: regexp.MustCompile(`[a-z]`)},
30 },
31 // this test shoud handle panic on bad regexp ?
32 // {
33 // name: "Test NewModuleHandler bad regex expr",
34 // args: args{name: "test name", desc: "test description", expr: "/abcd.(]"},
35 // want: ModuleHandler{Name: "test name", Description: "test description"},
36 // },
37 }
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 m := NewModuleHandler(tt.args.name, tt.args.expr, tt.args.desc, tt.args.exec)
41 if m.Parser != nil {
42 if tt.args.expr == "" {
43 t.Errorf("If no regexp were provided, should got nil parser but got %+v", m.Parser)
44 }
45 if m.Parser.String() != tt.want.Parser.String() {
46 t.Errorf("Wrong parser, got %+v want %+v", m.Parser.String(), tt.want.Parser.String())
47 }
48 }
49 })
50 }
51}
52
53func TestModuleHandler_Help(t *testing.T) {
54 type fields struct {

Callers

nothing calls this directly

Calls 3

NewModuleHandlerFunction · 0.85
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected