| 174 | } |
| 175 | |
| 176 | func 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 | |
| 210 | func TestCallbacksGet(t *testing.T) { |
| 211 | db, _ := gorm.Open(nil, nil) |