MCPcopy
hub / github.com/go-gorm/gorm / TestPluginCallbacks

Function TestPluginCallbacks

tests/callbacks_test.go:176–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174}
175
176func TestPluginCallbacks(t *testing.T) {
177 db, _ := gorm.Open(nil, nil)
178 createCallback := db.Callback().Create()
179
180 createCallback.Before("*").Register("plugin_1_fn1", c1)
181 createCallback.After("*").Register("plugin_1_fn2", c2)
182
183 if ok, msg := assertCallbacks(createCallback, []string{"c1", "c2"}); !ok {
184 t.Errorf("callbacks tests failed, got %v", msg)
185 }
186
187 // plugin 2
188 createCallback.Before("*").Register("plugin_2_fn1", c3)
189 if ok, msg := assertCallbacks(createCallback, []string{"c3", "c1", "c2"}); !ok {
190 t.Errorf("callbacks tests failed, got %v", msg)
191 }
192
193 createCallback.After("*").Register("plugin_2_fn2", c4)
194 if ok, msg := assertCallbacks(createCallback, []string{"c3", "c1", "c2", "c4"}); !ok {
195 t.Errorf("callbacks tests failed, got %v", msg)
196 }
197
198 // plugin 3
199 createCallback.Before("*").Register("plugin_3_fn1", c5)
200 if ok, msg := assertCallbacks(createCallback, []string{"c5", "c3", "c1", "c2", "c4"}); !ok {
201 t.Errorf("callbacks tests failed, got %v", msg)
202 }
203
204 createCallback.After("*").Register("plugin_3_fn2", c6)
205 if ok, msg := assertCallbacks(createCallback, []string{"c5", "c3", "c1", "c2", "c4", "c6"}); !ok {
206 t.Errorf("callbacks tests failed, got %v", msg)
207 }
208}
209
210func TestCallbacksGet(t *testing.T) {
211 db, _ := gorm.Open(nil, nil)

Callers

nothing calls this directly

Calls 7

OpenFunction · 0.92
assertCallbacksFunction · 0.85
CallbackMethod · 0.80
CreateMethod · 0.65
RegisterMethod · 0.45
BeforeMethod · 0.45
AfterMethod · 0.45

Tested by

no test coverage detected