MCPcopy Create free account
hub / github.com/gotenberg/gotenberg / TestMustRegisterModule

Function TestMustRegisterModule

pkg/gotenberg/modules_test.go:8–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestMustRegisterModule(t *testing.T) {
9 descriptorsMu.RLock()
10 descriptors = map[string]ModuleDescriptor{
11 "a": {ID: "a"},
12 }
13 descriptorsMu.RUnlock()
14
15 for _, tc := range []struct {
16 scenario string
17 ID string
18 New func() Module
19 expectPanic bool
20 }{
21 {
22 scenario: "no ID",
23 ID: "",
24 New: func() Module { return new(ModuleMock) },
25 expectPanic: true,
26 },
27 {
28 scenario: "nil New method",
29 ID: "b",
30 New: nil,
31 expectPanic: true,
32 },
33 {
34 scenario: "nil module",
35 ID: "b",
36 New: func() Module { return nil },
37 expectPanic: true,
38 },
39 {
40 scenario: "existing module",
41 ID: "a",
42 New: func() Module { return new(ModuleMock) },
43 expectPanic: true,
44 },
45 {
46 scenario: "success",
47 ID: "b",
48 New: func() Module { return new(ModuleMock) },
49 expectPanic: false,
50 },
51 } {
52 t.Run(tc.scenario, func(t *testing.T) {
53 mod := &struct{ ModuleMock }{}
54 mod.DescriptorMock = func() ModuleDescriptor { return ModuleDescriptor{ID: tc.ID, New: tc.New} }
55
56 if tc.expectPanic {
57 defer func() {
58 if r := recover(); r == nil {
59 t.Error("expected panic but got none")
60 }
61 }()
62 }
63
64 if !tc.expectPanic {
65 defer func() {

Callers

nothing calls this directly

Calls 3

MustRegisterModuleFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected