(t *testing.T)
| 1021 | } |
| 1022 | |
| 1023 | func TestCollectionModelEventSync(t *testing.T) { |
| 1024 | t.Parallel() |
| 1025 | |
| 1026 | app, _ := tests.NewTestApp() |
| 1027 | defer app.Cleanup() |
| 1028 | |
| 1029 | testCollections := make([]*core.Collection, 4) |
| 1030 | for i := 0; i < 4; i++ { |
| 1031 | testCollections[i] = core.NewBaseCollection("sync_test_" + strconv.Itoa(i)) |
| 1032 | if err := app.Save(testCollections[i]); err != nil { |
| 1033 | t.Fatal(err) |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | createModelEvent := func() *core.ModelEvent { |
| 1038 | event := new(core.ModelEvent) |
| 1039 | event.App = app |
| 1040 | event.Context = context.Background() |
| 1041 | event.Type = "test_a" |
| 1042 | event.Model = testCollections[0] |
| 1043 | return event |
| 1044 | } |
| 1045 | |
| 1046 | createModelErrorEvent := func() *core.ModelErrorEvent { |
| 1047 | event := new(core.ModelErrorEvent) |
| 1048 | event.ModelEvent = *createModelEvent() |
| 1049 | event.Error = errors.New("error_a") |
| 1050 | return event |
| 1051 | } |
| 1052 | |
| 1053 | changeCollectionEventBefore := func(e *core.CollectionEvent) { |
| 1054 | e.Type = "test_b" |
| 1055 | //nolint:staticcheck |
| 1056 | e.Context = context.WithValue(context.Background(), "test", 123) |
| 1057 | e.Collection = testCollections[1] |
| 1058 | } |
| 1059 | |
| 1060 | modelEventFinalizerChange := func(e *core.ModelEvent) { |
| 1061 | e.Type = "test_c" |
| 1062 | //nolint:staticcheck |
| 1063 | e.Context = context.WithValue(context.Background(), "test", 456) |
| 1064 | e.Model = testCollections[2] |
| 1065 | } |
| 1066 | |
| 1067 | changeCollectionEventAfter := func(e *core.CollectionEvent) { |
| 1068 | e.Type = "test_d" |
| 1069 | //nolint:staticcheck |
| 1070 | e.Context = context.WithValue(context.Background(), "test", 789) |
| 1071 | e.Collection = testCollections[3] |
| 1072 | } |
| 1073 | |
| 1074 | expectedBeforeModelEventHandlerChecks := func(t *testing.T, e *core.ModelEvent) { |
| 1075 | if e.Type != "test_a" { |
| 1076 | t.Fatalf("Expected type %q, got %q", "test_a", e.Type) |
| 1077 | } |
| 1078 | |
| 1079 | if v := e.Context.Value("test"); v != nil { |
| 1080 | t.Fatalf("Expected context value %v, got %v", nil, v) |
nothing calls this directly
no test coverage detected
searching dependent graphs…