(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func 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() { |
nothing calls this directly
no test coverage detected