(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func 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 | |
| 53 | func TestModuleHandler_Help(t *testing.T) { |
| 54 | type fields struct { |
nothing calls this directly
no test coverage detected