From cdc6cd2204eff9e1648813b11eec25fb473c0d93 Mon Sep 17 00:00:00 2001 From: david <58231312+davseby@users.noreply.github.com> Date: Sat, 19 Sep 2026 16:15:50 +0300 Subject: [PATCH] add internal simulation flag and diff --- server/auth-realtime/src/operations.test.ts | 3 + server/auth-realtime/src/schema/index.test.ts | 22 + server/auth-realtime/src/schema/metric.ts | 1 + server/core/internal/assistant/AGENTS.md | 5 +- .../core/internal/assistant/block/compact.go | 8 +- .../internal/assistant/block/compact_test.go | 3 +- .../core/internal/assistant/block/expand.go | 9 +- .../internal/assistant/block/expand_test.go | 36 +- .../core/internal/assistant/block/metric.go | 50 + .../internal/assistant/block/metric_test.go | 150 ++ .../persist/0mock_blob_store_test.go | 2 +- .../persist/0mock_history_store_test.go | 2 +- .../persist/0mock_pending_store_test.go | 2 +- .../assistant/persist/_mock/blob_store.go | 2 +- .../assistant/persist/_mock/history_store.go | 2 +- .../assistant/persist/_mock/pending_store.go | 2 +- .../internal/assistant/tools/0mock_db_test.go | 1393 +++++++++-------- .../tools/0mock_search_trigger_test.go | 2 +- .../internal/assistant/tools/0mock_tx_test.go | 91 +- .../core/internal/assistant/tools/_mock/db.go | 1389 ++++++++-------- .../assistant/tools/_mock/searcher.go | 13 +- server/core/internal/assistant/tools/block.go | 70 +- .../internal/assistant/tools/block_test.go | 254 ++- .../datasource/0mock_status_store_test.go | 12 +- .../core/internal/datasource/_mock/mysql.go | 226 +-- .../internal/datasource/_mock/postgresql.go | 226 +-- .../internal/datasource/_mock/prometheus.go | 320 ++-- .../core/internal/datasource/_mock/runner.go | 278 ++-- server/core/internal/datasource/_mock/sql.go | 106 +- .../internal/datasource/_mock/status_store.go | 20 +- server/core/internal/datasource/runner.go | 6 +- .../core/internal/datasource/runner_test.go | 2 +- .../datasource/simulation/simulation.go | 34 +- .../datasource/simulation/simulation_test.go | 20 +- .../core/internal/document/attribute_keys.go | 10 +- .../internal/search/manager/0mock_db_test.go | 21 +- .../search/manager/0mock_index_test.go | 3 +- server/core/internal/server/0mock_db_test.go | 530 ++++--- .../server/0mock_search_trigger_test.go | 2 +- .../internal/assistant/0mock_manager_test.go | 17 +- .../internal/block/0mock_runner_test.go | 6 +- .../server/internal/document/0mock_db_test.go | 126 +- .../document/0mock_search_trigger_test.go | 2 +- .../internal/document/0mock_searcher_test.go | 6 +- .../server/internal/document/0mock_tx_test.go | 126 +- .../server/internal/org/0mock_db_test.go | 8 +- .../internal/org/0mock_search_trigger_test.go | 2 +- .../server/internal/org/0mock_tx_test.go | 8 +- .../server/internal/tag/0mock_db_test.go | 28 +- .../blocks/metrics/MainBlock.nuxt.test.ts | 78 +- .../editor/blocks/metrics/MainBlock.vue | 21 +- .../VisualizationContainer.nuxt.test.ts | 108 +- .../blocks/metrics/VisualizationContainer.vue | 15 +- .../config-modal/ConfigSidebar.nuxt.test.ts | 138 ++ .../metrics/config-modal/ConfigSidebar.vue | 35 +- .../config-modal/SimulationPresetSelect.vue | 6 + .../editor/blocks/metrics/index.test.ts | 80 +- .../components/editor/blocks/metrics/index.ts | 4 + .../editor/blocks/metrics/simulation.ts | 4 + .../editor/blocks/metrics/utils.test.ts | 26 + .../components/editor/blocks/metrics/utils.ts | 11 +- .../diff/compute-merged-document.test.ts | 30 + web/app/components/editor/diff/config.ts | 3 +- .../editor/diff/content-hash.test.ts | 36 + .../components/editor/diff/content-hash.ts | 3 +- web/app/stores/editor.nuxt.test.ts | 1 + 66 files changed, 3746 insertions(+), 2509 deletions(-) diff --git a/server/auth-realtime/src/operations.test.ts b/server/auth-realtime/src/operations.test.ts index da51097a..47ccb85b 100644 --- a/server/auth-realtime/src/operations.test.ts +++ b/server/auth-realtime/src/operations.test.ts @@ -1503,9 +1503,12 @@ describe("pmBlockToY", () => { }, }) + // the simulation flag is the one metric attribute whose schema + // default is not null, so it is written out with the block expect(attrsOf(attached(el))).toEqual({ uid: "metric", queries: [{ query: "up", legend: "uptime" }], + simulationActive: false, }) }) diff --git a/server/auth-realtime/src/schema/index.test.ts b/server/auth-realtime/src/schema/index.test.ts index 02b2be91..c122e850 100644 --- a/server/auth-realtime/src/schema/index.test.ts +++ b/server/auth-realtime/src/schema/index.test.ts @@ -246,6 +246,28 @@ describe("editor schema", () => { ) }) + it("keeps a metric block's simulation flag", ({ expect }) => { + const block = metricBlock("m1") + + const result = roundTrip({ + ...block, + attrs: { + ...block.attrs, + simulationActive: true, + }, + }) + + expect(result.attrs?.simulationActive).toBe(true) + }) + + it("reads a metric block without a simulation flag as not simulating", ({ + expect, + }) => { + const result = roundTrip(metricBlock("m1")) + + expect(result.attrs?.simulationActive).toBe(false) + }) + it("keeps a mermaid block's source text", ({ expect }) => { const result = roundTrip({ type: "mermaidBlock", diff --git a/server/auth-realtime/src/schema/metric.ts b/server/auth-realtime/src/schema/metric.ts index d16a7609..ec4ad6df 100644 --- a/server/auth-realtime/src/schema/metric.ts +++ b/server/auth-realtime/src/schema/metric.ts @@ -45,6 +45,7 @@ export const MetricBlock = Node.create({ axisBoundsMin: {}, axisBoundsMax: {}, simulationPreset: {}, + simulationActive: { default: false }, width: {}, } }, diff --git a/server/core/internal/assistant/AGENTS.md b/server/core/internal/assistant/AGENTS.md index b93da607..5e91f8f1 100644 --- a/server/core/internal/assistant/AGENTS.md +++ b/server/core/internal/assistant/AGENTS.md @@ -42,7 +42,7 @@ for free. handler; `decodeHookSettings` switches on type into the processor's own struct. - **A block write reports from the operation, never a re-read** (the - realtime service persists on a debounce): `expandForWrite` once, ship the + realtime service persists on a debounce): `sanitizeBlock` once, ship the canonical uids, return `blockRows` of the expanded tree. - **Branches are addressed by id, always.** Every content tool requires `branch_id`; listings carry the ids; `FetchDocumentByBranchID` refuses a @@ -65,7 +65,8 @@ for free. `DescribeInput` is its read-only half. - **A write owns its invariants** on the `Input` method that performs it (`MoveDocument` refuses a missing parent or a move under its own subtree), - not in `Execute`. + not in `Execute`. Block writes go through `ApplyEdit`, so their per-type + rules sit in `sanitizeBlock` and `sanitizeBlockAttrs` (`block.go`). - **`Traits()` says what a tool is**; the mixins `plainSummary`/`plainTraits`/`plainTitle` cover the defaults. `Write` gates behind confirmation and protects the result from context diff --git a/server/core/internal/assistant/block/compact.go b/server/core/internal/assistant/block/compact.go index 7c2dec93..fcd151f2 100644 --- a/server/core/internal/assistant/block/compact.go +++ b/server/core/internal/assistant/block/compact.go @@ -367,12 +367,14 @@ func compactFigma(b document.Block, uid string) Block { } } -// compactMetric preserves every non-uid attribute on the source -// metric block — the configuration shape is opaque to the canonical -// layer and the AI sees it through-pass. +// compactMetric keeps every attribute of the source metric block except +// its uid and its simulation flag. The configuration shape is opaque to +// the canonical layer, so it passes through as is. The flag is internal +// state that a reader never sees. func compactMetric(b document.Block, uid string) Block { attrs := b.Attrs.Copy() delete(attrs, document.AttrUID) + delete(attrs, document.AttrSimulationActive) return Block{ Type: BlockMetric, diff --git a/server/core/internal/assistant/block/compact_test.go b/server/core/internal/assistant/block/compact_test.go index dba1e339..92532d93 100644 --- a/server/core/internal/assistant/block/compact_test.go +++ b/server/core/internal/assistant/block/compact_test.go @@ -394,12 +394,13 @@ func Test_Compact(t *testing.T) { Attrs: map[string]any{"query": "up", "unit": "%"}, }, }, - "Metric keeps an active simulation": { + "Metric keeps its preset and hides its simulation flag": { Input: document.Block{ Type: document.BlockNodeMetricBlock, Attrs: map[string]any{ "uid": "m1", "simulationPreset": "http_latency", + "simulationActive": true, }, }, Expected: Block{ diff --git a/server/core/internal/assistant/block/expand.go b/server/core/internal/assistant/block/expand.go index 8a4f5245..dee040f0 100644 --- a/server/core/internal/assistant/block/expand.go +++ b/server/core/internal/assistant/block/expand.go @@ -358,11 +358,18 @@ func expandFigma(b Block) document.Block { // expandMetric builds a metricBlock. All caller-supplied attrs are // passed through unchanged (the metric configuration shape is // opaque to the canonical layer); the uid is taken from Block.UID -// or freshly generated. +// or freshly generated. A simulation flag the caller sent is dropped. +// A block with a preset simulates, and any other does not. func expandMetric(b Block) document.Block { attrs := b.Attrs.Copy() attrs[document.AttrUID] = resolveUID(b.UID) + delete(attrs, document.AttrSimulationActive) + + if _, ok := attrs.Value(document.AttrSimulationPreset); ok { + attrs[document.AttrSimulationActive] = true + } + return document.Block{ Type: document.BlockNodeMetricBlock, Attrs: attrs, diff --git a/server/core/internal/assistant/block/expand_test.go b/server/core/internal/assistant/block/expand_test.go index 9e974a51..941e7919 100644 --- a/server/core/internal/assistant/block/expand_test.go +++ b/server/core/internal/assistant/block/expand_test.go @@ -544,14 +544,46 @@ func Test_Expand(t *testing.T) { Attrs: map[string]any{"query": "up"}, }, }, - "Metric keeps an active simulation": { + "Metric naming a preset simulates": { Input: Block{ Type: BlockMetric, Attrs: map[string]any{"simulationPreset": "http_latency"}, }, + Expected: document.Block{ + Type: document.BlockNodeMetricBlock, + Attrs: map[string]any{ + "simulationPreset": "http_latency", + "simulationActive": true, + }, + }, + }, + "Metric naming a preset simulates whatever flag was sent": { + Input: Block{ + Type: BlockMetric, + Attrs: map[string]any{ + "simulationPreset": "http_latency", + "simulationActive": false, + }, + }, + Expected: document.Block{ + Type: document.BlockNodeMetricBlock, + Attrs: map[string]any{ + "simulationPreset": "http_latency", + "simulationActive": true, + }, + }, + }, + "Metric naming no preset drops the flag it was sent": { + Input: Block{ + Type: BlockMetric, + Attrs: map[string]any{ + "simulationPreset": nil, + "simulationActive": true, + }, + }, Expected: document.Block{ Type: document.BlockNodeMetricBlock, - Attrs: map[string]any{"simulationPreset": "http_latency"}, + Attrs: map[string]any{"simulationPreset": nil}, }, }, // the other half of the legacy round trip: what Compact read diff --git a/server/core/internal/assistant/block/metric.go b/server/core/internal/assistant/block/metric.go index 48e7d69e..97d74635 100644 --- a/server/core/internal/assistant/block/metric.go +++ b/server/core/internal/assistant/block/metric.go @@ -96,6 +96,56 @@ func MetricEnums() map[string][]string { return out } +// DeriveSimulation sets the simulation flag on an attribute update. A +// flag the caller sent is dropped. A changed preset switches the +// simulation on, and a null preset switches it off. Any other update +// leaves the stored flag alone. +func DeriveSimulation(update map[string]any, stored document.Attributes) { + delete(update, document.AttrSimulationActive) + + preset, named := update[document.AttrSimulationPreset] + if !named || preset == stored[document.AttrSimulationPreset] { + return + } + + update[document.AttrSimulationActive] = preset != nil +} + +// KeepSimulation copies the stored simulation flag onto each metric in +// next that stored holds with the same uid and preset. A metric re-sent +// after its data arrived then does not start simulating again. It +// writes to next's attribute maps. +func KeepSimulation(next, stored document.Block) { + if next.Type != document.BlockNodeMetricBlock { + for _, child := range next.Content { + KeepSimulation(child, stored) + } + + return + } + + uid, ok := next.UID() + if !ok { + return + } + + old, found := stored.FindByUID(uid) + if !found || old.Type != document.BlockNodeMetricBlock { + return + } + + preset, ok := next.Attrs.Value(document.AttrSimulationPreset) + if !ok || preset != old.Attrs[document.AttrSimulationPreset] { + return + } + + delete(next.Attrs, document.AttrSimulationActive) + + if active, set := old.Attrs.Value(document.AttrSimulationActive); set { + next.Attrs[document.AttrSimulationActive] = active + } +} + // validateMetric checks a metric block: no content, and every known // attribute it does carry is well-formed. Only present, non-null values // are checked — the editor stores null for "unset" and an older block diff --git a/server/core/internal/assistant/block/metric_test.go b/server/core/internal/assistant/block/metric_test.go index 5a0573ab..d0cfa1f3 100644 --- a/server/core/internal/assistant/block/metric_test.go +++ b/server/core/internal/assistant/block/metric_test.go @@ -28,6 +28,156 @@ func Test_MetricEnums(t *testing.T) { assert.Equal(t, "line_chart", MetricEnums()[document.AttrVisualizationType][0]) } +func Test_DeriveSimulation(t *testing.T) { + t.Parallel() + + cc := map[string]struct { + Update map[string]any + Stored document.Attributes + Expected map[string]any + }{ + "An update naming no preset leaves the flag alone": { + Update: map[string]any{"title": "Requests"}, + Stored: document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}, + Expected: map[string]any{"title": "Requests"}, + }, + "A flag the caller sent is dropped": { + Update: map[string]any{"title": "Requests", "simulationActive": true}, + Stored: document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}, + Expected: map[string]any{"title": "Requests"}, + }, + "The stored preset sent again leaves the flag alone": { + Update: map[string]any{"simulationPreset": "cpu_usage"}, + Stored: document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}, + Expected: map[string]any{"simulationPreset": "cpu_usage"}, + }, + "A first preset switches the simulation on": { + Update: map[string]any{"simulationPreset": "cpu_usage"}, + Stored: document.Attributes{"simulationPreset": nil}, + Expected: map[string]any{"simulationPreset": "cpu_usage", "simulationActive": true}, + }, + "Another preset switches the simulation on": { + Update: map[string]any{"simulationPreset": "error_rate"}, + Stored: document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}, + Expected: map[string]any{"simulationPreset": "error_rate", "simulationActive": true}, + }, + "A null preset switches the simulation off": { + Update: map[string]any{"simulationPreset": nil}, + Stored: document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}, + Expected: map[string]any{"simulationPreset": nil, "simulationActive": false}, + }, + "A null preset on a block that names none changes nothing": { + Update: map[string]any{"simulationPreset": nil}, + Stored: document.Attributes{}, + Expected: map[string]any{"simulationPreset": nil}, + }, + } + + for cn, c := range cc { + t.Run(cn, func(t *testing.T) { + t.Parallel() + + DeriveSimulation(c.Update, c.Stored) + + assert.Equal(t, c.Expected, c.Update) + }) + } +} + +func Test_KeepSimulation(t *testing.T) { + t.Parallel() + + metric := func(uid string, attrs document.Attributes) document.Block { + attrs[document.AttrUID] = uid + + return document.Block{Type: document.BlockNodeMetricBlock, Attrs: attrs} + } + + grid := func(items ...document.Block) document.Block { + return document.Block{Type: document.BlockNodeMetricGrid, Content: items} + } + + cc := map[string]struct { + Next document.Block + Stored document.Block + Expected document.Block + }{ + "The same preset keeps a simulation that was switched off": { + Next: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + Stored: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + Expected: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + }, + "The same preset keeps a simulation that is running": { + Next: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + Stored: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + Expected: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + }, + "The same preset stored without a flag drops the derived one": { + Next: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + Stored: metric("m1", document.Attributes{"simulationPreset": "cpu_usage"}), + Expected: metric("m1", document.Attributes{"simulationPreset": "cpu_usage"}), + }, + "Another preset keeps what was derived": { + Next: metric("m1", document.Attributes{"simulationPreset": "error_rate", "simulationActive": true}), + Stored: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + Expected: metric("m1", document.Attributes{"simulationPreset": "error_rate", "simulationActive": true}), + }, + "A block naming no preset is left alone": { + Next: metric("m1", document.Attributes{"simulationPreset": nil}), + Stored: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + Expected: metric("m1", document.Attributes{"simulationPreset": nil}), + }, + "A block the stored tree does not hold is left alone": { + Next: metric("m2", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + Stored: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + Expected: metric("m2", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + }, + "A block without a uid is left alone": { + Next: document.Block{ + Type: document.BlockNodeMetricBlock, + Attrs: document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}, + }, + Stored: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + Expected: document.Block{ + Type: document.BlockNodeMetricBlock, + Attrs: document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}, + }, + }, + "A uid the stored tree gives to another kind of block is left alone": { + Next: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + Stored: document.Block{ + Type: document.BlockNodeParagraph, + Attrs: document.Attributes{document.AttrUID: "m1"}, + }, + Expected: metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + }, + "A grid carries the flag of each metric it holds": { + Next: grid( + metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": true}), + metric("m2", document.Attributes{"simulationPreset": "error_rate", "simulationActive": true}), + ), + Stored: grid( + metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + metric("m2", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + ), + Expected: grid( + metric("m1", document.Attributes{"simulationPreset": "cpu_usage", "simulationActive": false}), + metric("m2", document.Attributes{"simulationPreset": "error_rate", "simulationActive": true}), + ), + }, + } + + for cn, c := range cc { + t.Run(cn, func(t *testing.T) { + t.Parallel() + + KeepSimulation(c.Next, c.Stored) + + assert.Equal(t, c.Expected, c.Next) + }) + } +} + func Test_validateMetric(t *testing.T) { t.Parallel() diff --git a/server/core/internal/assistant/persist/0mock_blob_store_test.go b/server/core/internal/assistant/persist/0mock_blob_store_test.go index 846a833b..7c4557ec 100644 --- a/server/core/internal/assistant/persist/0mock_blob_store_test.go +++ b/server/core/internal/assistant/persist/0mock_blob_store_test.go @@ -27,7 +27,7 @@ var _ BlobStore = &BlobStoreMock{} // SetFunc: func(ctx context.Context, key string, value []byte) error { // panic("mock out the Set method") // }, -// StartFunc: func(ctx context.Context) { +// StartFunc: func(ctx context.Context) { // panic("mock out the Start method") // }, // } diff --git a/server/core/internal/assistant/persist/0mock_history_store_test.go b/server/core/internal/assistant/persist/0mock_history_store_test.go index 0126f4d4..f06aecf3 100644 --- a/server/core/internal/assistant/persist/0mock_history_store_test.go +++ b/server/core/internal/assistant/persist/0mock_history_store_test.go @@ -29,7 +29,7 @@ var _ HistoryStore = &HistoryStoreMock{} // SetFunc: func(ctx context.Context, key string, value []*schema.Message) error { // panic("mock out the Set method") // }, -// StartFunc: func(ctx context.Context) { +// StartFunc: func(ctx context.Context) { // panic("mock out the Start method") // }, // } diff --git a/server/core/internal/assistant/persist/0mock_pending_store_test.go b/server/core/internal/assistant/persist/0mock_pending_store_test.go index 69634dd7..e3076aa8 100644 --- a/server/core/internal/assistant/persist/0mock_pending_store_test.go +++ b/server/core/internal/assistant/persist/0mock_pending_store_test.go @@ -27,7 +27,7 @@ var _ PendingStore = &PendingStoreMock{} // SetFunc: func(ctx context.Context, key string, value PendingConfirm) error { // panic("mock out the Set method") // }, -// StartFunc: func(ctx context.Context) { +// StartFunc: func(ctx context.Context) { // panic("mock out the Start method") // }, // } diff --git a/server/core/internal/assistant/persist/_mock/blob_store.go b/server/core/internal/assistant/persist/_mock/blob_store.go index 077c378e..2ddf37c2 100644 --- a/server/core/internal/assistant/persist/_mock/blob_store.go +++ b/server/core/internal/assistant/persist/_mock/blob_store.go @@ -29,7 +29,7 @@ var _ persist.BlobStore = &BlobStore{} // SetFunc: func(ctx context.Context, key string, value []byte) error { // panic("mock out the Set method") // }, -// StartFunc: func(ctx context.Context) { +// StartFunc: func(ctx context.Context) { // panic("mock out the Start method") // }, // } diff --git a/server/core/internal/assistant/persist/_mock/history_store.go b/server/core/internal/assistant/persist/_mock/history_store.go index 111cb2ec..0c7bb9fb 100644 --- a/server/core/internal/assistant/persist/_mock/history_store.go +++ b/server/core/internal/assistant/persist/_mock/history_store.go @@ -30,7 +30,7 @@ var _ persist.HistoryStore = &HistoryStore{} // SetFunc: func(ctx context.Context, key string, value []*schema.Message) error { // panic("mock out the Set method") // }, -// StartFunc: func(ctx context.Context) { +// StartFunc: func(ctx context.Context) { // panic("mock out the Start method") // }, // } diff --git a/server/core/internal/assistant/persist/_mock/pending_store.go b/server/core/internal/assistant/persist/_mock/pending_store.go index df3c7835..1eb1689d 100644 --- a/server/core/internal/assistant/persist/_mock/pending_store.go +++ b/server/core/internal/assistant/persist/_mock/pending_store.go @@ -29,7 +29,7 @@ var _ persist.PendingStore = &PendingStore{} // SetFunc: func(ctx context.Context, key string, value persist.PendingConfirm) error { // panic("mock out the Set method") // }, -// StartFunc: func(ctx context.Context) { +// StartFunc: func(ctx context.Context) { // panic("mock out the Start method") // }, // } diff --git a/server/core/internal/assistant/tools/0mock_db_test.go b/server/core/internal/assistant/tools/0mock_db_test.go index 99bcf0b9..c82fbc5b 100644 --- a/server/core/internal/assistant/tools/0mock_db_test.go +++ b/server/core/internal/assistant/tools/0mock_db_test.go @@ -10,7 +10,7 @@ import ( "github.com/guregu/null/v5" "github.com/oxynote/oxynote/server/core/internal/datasource" "github.com/oxynote/oxynote/server/core/internal/document" - hookCore "github.com/oxynote/oxynote/server/core/internal/document/hook" + "github.com/oxynote/oxynote/server/core/internal/document/hook" "github.com/oxynote/oxynote/server/core/internal/tag" "github.com/rs/xid" ) @@ -25,6 +25,9 @@ var _ DB = &DBMock{} // // // make and configure a mocked DB // mockedDB := &DBMock{ +// AssignBranchTagFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { +// panic("mock out the AssignBranchTag method") +// }, // BeginTxFunc: func(ctx context.Context, dest any) error { // panic("mock out the BeginTx method") // }, @@ -34,18 +37,66 @@ var _ DB = &DBMock{} // CheckDocumentExistsFunc: func(ctx context.Context, id xid.ID, organizationID string) error { // panic("mock out the CheckDocumentExists method") // }, +// DeleteDocumentHookFunc: func(ctx context.Context, id xid.ID) error { +// panic("mock out the DeleteDocumentHook method") +// }, +// DeleteTagFunc: func(ctx context.Context, id xid.ID, organizationID string) error { +// panic("mock out the DeleteTag method") +// }, +// FetchBranchTagsFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) { +// panic("mock out the FetchBranchTags method") +// }, +// FetchDataSourceFunc: func(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { +// panic("mock out the FetchDataSource method") +// }, +// FetchDataSourcesFunc: func(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { +// panic("mock out the FetchDataSources method") +// }, // FetchDocumentFunc: func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) { // panic("mock out the FetchDocument method") // }, +// FetchDocumentBranchesFunc: func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) { +// panic("mock out the FetchDocumentBranches method") +// }, +// FetchDocumentByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) { +// panic("mock out the FetchDocumentByBranchID method") +// }, +// FetchDocumentHookFunc: func(ctx context.Context, id xid.ID, organizationID string) (*hook.Hook, error) { +// panic("mock out the FetchDocumentHook method") +// }, +// FetchDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) ([]hook.Hook, error) { +// panic("mock out the FetchDocumentHooksByBranchID method") +// }, // FetchDocumentTreeFunc: func(ctx context.Context, organizationID string) (document.Summaries, error) { // panic("mock out the FetchDocumentTree method") // }, // FetchDocumentTreeByDocumentParentIDFunc: func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) { // panic("mock out the FetchDocumentTreeByDocumentParentID method") // }, +// FetchTagTreeFunc: func(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) { +// panic("mock out the FetchTagTree method") +// }, +// InsertDocumentHookFunc: func(ctx context.Context, hk hook.Hook) error { +// panic("mock out the InsertDocumentHook method") +// }, +// InsertTagFunc: func(ctx context.Context, t tag.Tag) error { +// panic("mock out the InsertTag method") +// }, +// UnassignBranchTagFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { +// panic("mock out the UnassignBranchTag method") +// }, +// UpdateDocumentHookFunc: func(ctx context.Context, hk hook.Hook) error { +// panic("mock out the UpdateDocumentHook method") +// }, // UpdateDocumentParentIDFunc: func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error { // panic("mock out the UpdateDocumentParentID method") // }, +// UpdateTagFunc: func(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error { +// panic("mock out the UpdateTag method") +// }, +// UpdateTagTreeFunc: func(ctx context.Context, tree tag.Summaries, organizationID string) error { +// panic("mock out the UpdateTagTree method") +// }, // } // // // use mockedDB in code that requires DB @@ -53,6 +104,9 @@ var _ DB = &DBMock{} // // } type DBMock struct { + // AssignBranchTagFunc mocks the AssignBranchTag method. + AssignBranchTagFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error + // BeginTxFunc mocks the BeginTx method. BeginTxFunc func(ctx context.Context, dest any) error @@ -62,23 +116,14 @@ type DBMock struct { // CheckDocumentExistsFunc mocks the CheckDocumentExists method. CheckDocumentExistsFunc func(ctx context.Context, id xid.ID, organizationID string) error - // FetchDocumentFunc mocks the FetchDocument method. - FetchDocumentFunc func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) + // DeleteDocumentHookFunc mocks the DeleteDocumentHook method. + DeleteDocumentHookFunc func(ctx context.Context, id xid.ID) error - // FetchDocumentTreeFunc mocks the FetchDocumentTree method. - FetchDocumentTreeFunc func(ctx context.Context, organizationID string) (document.Summaries, error) + // DeleteTagFunc mocks the DeleteTag method. + DeleteTagFunc func(ctx context.Context, id xid.ID, organizationID string) error - // FetchDocumentTreeByDocumentParentIDFunc mocks the FetchDocumentTreeByDocumentParentID method. - FetchDocumentTreeByDocumentParentIDFunc func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) - - // FetchDocumentBranchesFunc mocks the FetchDocumentBranches method. - FetchDocumentBranchesFunc func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) - - // FetchDocumentByBranchIDFunc mocks the FetchDocumentByBranchID method. - FetchDocumentByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) - - // UpdateDocumentParentIDFunc mocks the UpdateDocumentParentID method. - UpdateDocumentParentIDFunc func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error + // FetchBranchTagsFunc mocks the FetchBranchTags method. + FetchBranchTagsFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) // FetchDataSourceFunc mocks the FetchDataSource method. FetchDataSourceFunc func(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) @@ -86,35 +131,66 @@ type DBMock struct { // FetchDataSourcesFunc mocks the FetchDataSources method. FetchDataSourcesFunc func(ctx context.Context, organizationID string) ([]datasource.DataSource, error) + // FetchDocumentFunc mocks the FetchDocument method. + FetchDocumentFunc func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) + + // FetchDocumentBranchesFunc mocks the FetchDocumentBranches method. + FetchDocumentBranchesFunc func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) + + // FetchDocumentByBranchIDFunc mocks the FetchDocumentByBranchID method. + FetchDocumentByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) + + // FetchDocumentHookFunc mocks the FetchDocumentHook method. + FetchDocumentHookFunc func(ctx context.Context, id xid.ID, organizationID string) (*hook.Hook, error) + + // FetchDocumentHooksByBranchIDFunc mocks the FetchDocumentHooksByBranchID method. + FetchDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) ([]hook.Hook, error) + + // FetchDocumentTreeFunc mocks the FetchDocumentTree method. + FetchDocumentTreeFunc func(ctx context.Context, organizationID string) (document.Summaries, error) + + // FetchDocumentTreeByDocumentParentIDFunc mocks the FetchDocumentTreeByDocumentParentID method. + FetchDocumentTreeByDocumentParentIDFunc func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) + // FetchTagTreeFunc mocks the FetchTagTree method. FetchTagTreeFunc func(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) - // FetchBranchTagsFunc mocks the FetchBranchTags method. - FetchBranchTagsFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) + + // InsertDocumentHookFunc mocks the InsertDocumentHook method. + InsertDocumentHookFunc func(ctx context.Context, hk hook.Hook) error + // InsertTagFunc mocks the InsertTag method. InsertTagFunc func(ctx context.Context, t tag.Tag) error - // UpdateTagFunc mocks the UpdateTag method. - UpdateTagFunc func(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error - // DeleteTagFunc mocks the DeleteTag method. - DeleteTagFunc func(ctx context.Context, id xid.ID, organizationID string) error - // AssignBranchTagFunc mocks the AssignBranchTag method. - AssignBranchTagFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error + // UnassignBranchTagFunc mocks the UnassignBranchTag method. UnassignBranchTagFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error + + // UpdateDocumentHookFunc mocks the UpdateDocumentHook method. + UpdateDocumentHookFunc func(ctx context.Context, hk hook.Hook) error + + // UpdateDocumentParentIDFunc mocks the UpdateDocumentParentID method. + UpdateDocumentParentIDFunc func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error + + // UpdateTagFunc mocks the UpdateTag method. + UpdateTagFunc func(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error + // UpdateTagTreeFunc mocks the UpdateTagTree method. UpdateTagTreeFunc func(ctx context.Context, tree tag.Summaries, organizationID string) error - // FetchDocumentHooksByBranchIDFunc mocks the FetchDocumentHooksByBranchID method. - FetchDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) ([]hookCore.Hook, error) - // FetchDocumentHookFunc mocks the FetchDocumentHook method. - FetchDocumentHookFunc func(ctx context.Context, id xid.ID, organizationID string) (*hookCore.Hook, error) - // InsertDocumentHookFunc mocks the InsertDocumentHook method. - InsertDocumentHookFunc func(ctx context.Context, hk hookCore.Hook) error - // UpdateDocumentHookFunc mocks the UpdateDocumentHook method. - UpdateDocumentHookFunc func(ctx context.Context, hk hookCore.Hook) error - // DeleteDocumentHookFunc mocks the DeleteDocumentHook method. - DeleteDocumentHookFunc func(ctx context.Context, id xid.ID) error // calls tracks calls to the methods. calls struct { + // AssignBranchTag holds details about calls to the AssignBranchTag method. + AssignBranchTag []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + // DocumentID is the documentID argument value. + DocumentID xid.ID + // BranchID is the branchID argument value. + BranchID xid.ID + // TagID is the tagID argument value. + TagID xid.ID + } // BeginTx holds details about calls to the BeginTx method. BeginTx []struct { // Ctx is the ctx argument value. @@ -142,6 +218,49 @@ type DBMock struct { // OrganizationID is the organizationID argument value. OrganizationID string } + // DeleteDocumentHook holds details about calls to the DeleteDocumentHook method. + DeleteDocumentHook []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + } + // DeleteTag holds details about calls to the DeleteTag method. + DeleteTag []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // FetchBranchTags holds details about calls to the FetchBranchTags method. + FetchBranchTags []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + // DocumentID is the documentID argument value. + DocumentID xid.ID + // BranchID is the branchID argument value. + BranchID xid.ID + } + // FetchDataSource holds details about calls to the FetchDataSource method. + FetchDataSource []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // FetchDataSources holds details about calls to the FetchDataSources method. + FetchDataSources []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + } // FetchDocument holds details about calls to the FetchDocument method. FetchDocument []struct { // Ctx is the ctx argument value. @@ -171,6 +290,24 @@ type DBMock struct { // OrganizationID is the organizationID argument value. OrganizationID string } + // FetchDocumentHook holds details about calls to the FetchDocumentHook method. + FetchDocumentHook []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // FetchDocumentHooksByBranchID holds details about calls to the FetchDocumentHooksByBranchID method. + FetchDocumentHooksByBranchID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // BranchID is the branchID argument value. + BranchID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } // FetchDocumentTree holds details about calls to the FetchDocumentTree method. FetchDocumentTree []struct { // Ctx is the ctx argument value. @@ -187,33 +324,6 @@ type DBMock struct { // OrganizationID is the organizationID argument value. OrganizationID string } - // UpdateDocumentParentID holds details about calls to the UpdateDocumentParentID method. - UpdateDocumentParentID []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - // ParentID is the parentID argument value. - ParentID null.Value[xid.ID] - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // FetchDataSource holds details about calls to the FetchDataSource method. - FetchDataSource []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Id is the id argument value. - Id xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // FetchDataSources holds details about calls to the FetchDataSources method. - FetchDataSources []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - } // FetchTagTree holds details about calls to the FetchTagTree method. FetchTagTree []struct { // Ctx is the ctx argument value. @@ -223,16 +333,12 @@ type DBMock struct { // UserID is the userID argument value. UserID string } - // FetchBranchTags holds details about calls to the FetchBranchTags method. - FetchBranchTags []struct { + // InsertDocumentHook holds details about calls to the InsertDocumentHook method. + InsertDocumentHook []struct { // Ctx is the ctx argument value. Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - // DocumentID is the documentID argument value. - DocumentID xid.ID - // BranchID is the branchID argument value. - BranchID xid.ID + // Hk is the hk argument value. + Hk hook.Hook } // InsertTag holds details about calls to the InsertTag method. InsertTag []struct { @@ -241,39 +347,6 @@ type DBMock struct { // T is the t argument value. T tag.Tag } - // UpdateTag holds details about calls to the UpdateTag method. - UpdateTag []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - // ID is the id argument value. - ID xid.ID - // Inp is the inp argument value. - Inp tag.UpdateInput - } - // DeleteTag holds details about calls to the DeleteTag method. - DeleteTag []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // AssignBranchTag holds details about calls to the AssignBranchTag method. - AssignBranchTag []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - // DocumentID is the documentID argument value. - DocumentID xid.ID - // BranchID is the branchID argument value. - BranchID xid.ID - // TagID is the tagID argument value. - TagID xid.ID - } // UnassignBranchTag holds details about calls to the UnassignBranchTag method. UnassignBranchTag []struct { // Ctx is the ctx argument value. @@ -287,6 +360,35 @@ type DBMock struct { // TagID is the tagID argument value. TagID xid.ID } + // UpdateDocumentHook holds details about calls to the UpdateDocumentHook method. + UpdateDocumentHook []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Hk is the hk argument value. + Hk hook.Hook + } + // UpdateDocumentParentID holds details about calls to the UpdateDocumentParentID method. + UpdateDocumentParentID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // ParentID is the parentID argument value. + ParentID null.Value[xid.ID] + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // UpdateTag holds details about calls to the UpdateTag method. + UpdateTag []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + // ID is the id argument value. + ID xid.ID + // Inp is the inp argument value. + Inp tag.UpdateInput + } // UpdateTagTree holds details about calls to the UpdateTagTree method. UpdateTagTree []struct { // Ctx is the ctx argument value. @@ -296,70 +398,82 @@ type DBMock struct { // OrganizationID is the organizationID argument value. OrganizationID string } - // FetchDocumentHooksByBranchID holds details about calls to the FetchDocumentHooksByBranchID method. - FetchDocumentHooksByBranchID []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // BranchID is the branchID argument value. - BranchID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // FetchDocumentHook holds details about calls to the FetchDocumentHook method. - FetchDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // InsertDocumentHook holds details about calls to the InsertDocumentHook method. - InsertDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Hk is the hk argument value. - Hk hookCore.Hook - } - // UpdateDocumentHook holds details about calls to the UpdateDocumentHook method. - UpdateDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Hk is the hk argument value. - Hk hookCore.Hook - } - // DeleteDocumentHook holds details about calls to the DeleteDocumentHook method. - DeleteDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - } } + lockAssignBranchTag sync.RWMutex lockBeginTx sync.RWMutex lockCheckDocumentCycle sync.RWMutex lockCheckDocumentExists sync.RWMutex + lockDeleteDocumentHook sync.RWMutex + lockDeleteTag sync.RWMutex + lockFetchBranchTags sync.RWMutex + lockFetchDataSource sync.RWMutex + lockFetchDataSources sync.RWMutex lockFetchDocument sync.RWMutex lockFetchDocumentBranches sync.RWMutex lockFetchDocumentByBranchID sync.RWMutex + lockFetchDocumentHook sync.RWMutex + lockFetchDocumentHooksByBranchID sync.RWMutex lockFetchDocumentTree sync.RWMutex lockFetchDocumentTreeByDocumentParentID sync.RWMutex - lockUpdateDocumentParentID sync.RWMutex - lockFetchDataSource sync.RWMutex - lockFetchDataSources sync.RWMutex lockFetchTagTree sync.RWMutex - lockFetchBranchTags sync.RWMutex - lockInsertTag sync.RWMutex - lockUpdateTag sync.RWMutex - lockDeleteTag sync.RWMutex - lockAssignBranchTag sync.RWMutex - lockUnassignBranchTag sync.RWMutex - lockUpdateTagTree sync.RWMutex - lockFetchDocumentHooksByBranchID sync.RWMutex - lockFetchDocumentHook sync.RWMutex lockInsertDocumentHook sync.RWMutex + lockInsertTag sync.RWMutex + lockUnassignBranchTag sync.RWMutex lockUpdateDocumentHook sync.RWMutex - lockDeleteDocumentHook sync.RWMutex + lockUpdateDocumentParentID sync.RWMutex + lockUpdateTag sync.RWMutex + lockUpdateTagTree sync.RWMutex +} + +// AssignBranchTag calls AssignBranchTagFunc. +func (mock *DBMock) AssignBranchTag(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { + callInfo := struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + TagID xid.ID + }{ + Ctx: ctx, + OrganizationID: organizationID, + DocumentID: documentID, + BranchID: branchID, + TagID: tagID, + } + mock.lockAssignBranchTag.Lock() + mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) + mock.lockAssignBranchTag.Unlock() + if mock.AssignBranchTagFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) +} + +// AssignBranchTagCalls gets all the calls that were made to AssignBranchTag. +// Check the length with: +// +// len(mockedDB.AssignBranchTagCalls()) +func (mock *DBMock) AssignBranchTagCalls() []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + TagID xid.ID +} { + var calls []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + TagID xid.ID + } + mock.lockAssignBranchTag.RLock() + calls = mock.calls.AssignBranchTag + mock.lockAssignBranchTag.RUnlock() + return calls } // BeginTx calls BeginTxFunc. @@ -492,6 +606,220 @@ func (mock *DBMock) CheckDocumentExistsCalls() []struct { return calls } +// DeleteDocumentHook calls DeleteDocumentHookFunc. +func (mock *DBMock) DeleteDocumentHook(ctx context.Context, id xid.ID) error { + callInfo := struct { + Ctx context.Context + ID xid.ID + }{ + Ctx: ctx, + ID: id, + } + mock.lockDeleteDocumentHook.Lock() + mock.calls.DeleteDocumentHook = append(mock.calls.DeleteDocumentHook, callInfo) + mock.lockDeleteDocumentHook.Unlock() + if mock.DeleteDocumentHookFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.DeleteDocumentHookFunc(ctx, id) +} + +// DeleteDocumentHookCalls gets all the calls that were made to DeleteDocumentHook. +// Check the length with: +// +// len(mockedDB.DeleteDocumentHookCalls()) +func (mock *DBMock) DeleteDocumentHookCalls() []struct { + Ctx context.Context + ID xid.ID +} { + var calls []struct { + Ctx context.Context + ID xid.ID + } + mock.lockDeleteDocumentHook.RLock() + calls = mock.calls.DeleteDocumentHook + mock.lockDeleteDocumentHook.RUnlock() + return calls +} + +// DeleteTag calls DeleteTagFunc. +func (mock *DBMock) DeleteTag(ctx context.Context, id xid.ID, organizationID string) error { + callInfo := struct { + Ctx context.Context + ID xid.ID + OrganizationID string + }{ + Ctx: ctx, + ID: id, + OrganizationID: organizationID, + } + mock.lockDeleteTag.Lock() + mock.calls.DeleteTag = append(mock.calls.DeleteTag, callInfo) + mock.lockDeleteTag.Unlock() + if mock.DeleteTagFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.DeleteTagFunc(ctx, id, organizationID) +} + +// DeleteTagCalls gets all the calls that were made to DeleteTag. +// Check the length with: +// +// len(mockedDB.DeleteTagCalls()) +func (mock *DBMock) DeleteTagCalls() []struct { + Ctx context.Context + ID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + OrganizationID string + } + mock.lockDeleteTag.RLock() + calls = mock.calls.DeleteTag + mock.lockDeleteTag.RUnlock() + return calls +} + +// FetchBranchTags calls FetchBranchTagsFunc. +func (mock *DBMock) FetchBranchTags(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) { + callInfo := struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + }{ + Ctx: ctx, + OrganizationID: organizationID, + DocumentID: documentID, + BranchID: branchID, + } + mock.lockFetchBranchTags.Lock() + mock.calls.FetchBranchTags = append(mock.calls.FetchBranchTags, callInfo) + mock.lockFetchBranchTags.Unlock() + if mock.FetchBranchTagsFunc == nil { + var ( + tagsOut []tag.Tag + errOut error + ) + return tagsOut, errOut + } + return mock.FetchBranchTagsFunc(ctx, organizationID, documentID, branchID) +} + +// FetchBranchTagsCalls gets all the calls that were made to FetchBranchTags. +// Check the length with: +// +// len(mockedDB.FetchBranchTagsCalls()) +func (mock *DBMock) FetchBranchTagsCalls() []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID +} { + var calls []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + } + mock.lockFetchBranchTags.RLock() + calls = mock.calls.FetchBranchTags + mock.lockFetchBranchTags.RUnlock() + return calls +} + +// FetchDataSource calls FetchDataSourceFunc. +func (mock *DBMock) FetchDataSource(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { + callInfo := struct { + Ctx context.Context + ID xid.ID + OrganizationID string + }{ + Ctx: ctx, + ID: id, + OrganizationID: organizationID, + } + mock.lockFetchDataSource.Lock() + mock.calls.FetchDataSource = append(mock.calls.FetchDataSource, callInfo) + mock.lockFetchDataSource.Unlock() + if mock.FetchDataSourceFunc == nil { + var ( + dataSourceOut *datasource.DataSource + errOut error + ) + return dataSourceOut, errOut + } + return mock.FetchDataSourceFunc(ctx, id, organizationID) +} + +// FetchDataSourceCalls gets all the calls that were made to FetchDataSource. +// Check the length with: +// +// len(mockedDB.FetchDataSourceCalls()) +func (mock *DBMock) FetchDataSourceCalls() []struct { + Ctx context.Context + ID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + OrganizationID string + } + mock.lockFetchDataSource.RLock() + calls = mock.calls.FetchDataSource + mock.lockFetchDataSource.RUnlock() + return calls +} + +// FetchDataSources calls FetchDataSourcesFunc. +func (mock *DBMock) FetchDataSources(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { + callInfo := struct { + Ctx context.Context + OrganizationID string + }{ + Ctx: ctx, + OrganizationID: organizationID, + } + mock.lockFetchDataSources.Lock() + mock.calls.FetchDataSources = append(mock.calls.FetchDataSources, callInfo) + mock.lockFetchDataSources.Unlock() + if mock.FetchDataSourcesFunc == nil { + var ( + dataSourcesOut []datasource.DataSource + errOut error + ) + return dataSourcesOut, errOut + } + return mock.FetchDataSourcesFunc(ctx, organizationID) +} + +// FetchDataSourcesCalls gets all the calls that were made to FetchDataSources. +// Check the length with: +// +// len(mockedDB.FetchDataSourcesCalls()) +func (mock *DBMock) FetchDataSourcesCalls() []struct { + Ctx context.Context + OrganizationID string +} { + var calls []struct { + Ctx context.Context + OrganizationID string + } + mock.lockFetchDataSources.RLock() + calls = mock.calls.FetchDataSources + mock.lockFetchDataSources.RUnlock() + return calls +} + // FetchDocument calls FetchDocumentFunc. func (mock *DBMock) FetchDocument(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) { callInfo := struct { @@ -567,7 +895,7 @@ func (mock *DBMock) FetchDocumentBranches(ctx context.Context, docID xid.ID, org // FetchDocumentBranchesCalls gets all the calls that were made to FetchDocumentBranches. // Check the length with: // -// len(mockedDBMock.FetchDocumentBranchesCalls()) +// len(mockedDB.FetchDocumentBranchesCalls()) func (mock *DBMock) FetchDocumentBranchesCalls() []struct { Ctx context.Context DocID xid.ID @@ -611,7 +939,7 @@ func (mock *DBMock) FetchDocumentByBranchID(ctx context.Context, branchID xid.ID // FetchDocumentByBranchIDCalls gets all the calls that were made to FetchDocumentByBranchID. // Check the length with: // -// len(mockedDBMock.FetchDocumentByBranchIDCalls()) +// len(mockedDB.FetchDocumentByBranchIDCalls()) func (mock *DBMock) FetchDocumentByBranchIDCalls() []struct { Ctx context.Context BranchID xid.ID @@ -628,6 +956,94 @@ func (mock *DBMock) FetchDocumentByBranchIDCalls() []struct { return calls } +// FetchDocumentHook calls FetchDocumentHookFunc. +func (mock *DBMock) FetchDocumentHook(ctx context.Context, id xid.ID, organizationID string) (*hook.Hook, error) { + callInfo := struct { + Ctx context.Context + ID xid.ID + OrganizationID string + }{ + Ctx: ctx, + ID: id, + OrganizationID: organizationID, + } + mock.lockFetchDocumentHook.Lock() + mock.calls.FetchDocumentHook = append(mock.calls.FetchDocumentHook, callInfo) + mock.lockFetchDocumentHook.Unlock() + if mock.FetchDocumentHookFunc == nil { + var ( + hookOut *hook.Hook + errOut error + ) + return hookOut, errOut + } + return mock.FetchDocumentHookFunc(ctx, id, organizationID) +} + +// FetchDocumentHookCalls gets all the calls that were made to FetchDocumentHook. +// Check the length with: +// +// len(mockedDB.FetchDocumentHookCalls()) +func (mock *DBMock) FetchDocumentHookCalls() []struct { + Ctx context.Context + ID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + OrganizationID string + } + mock.lockFetchDocumentHook.RLock() + calls = mock.calls.FetchDocumentHook + mock.lockFetchDocumentHook.RUnlock() + return calls +} + +// FetchDocumentHooksByBranchID calls FetchDocumentHooksByBranchIDFunc. +func (mock *DBMock) FetchDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) ([]hook.Hook, error) { + callInfo := struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + }{ + Ctx: ctx, + BranchID: branchID, + OrganizationID: organizationID, + } + mock.lockFetchDocumentHooksByBranchID.Lock() + mock.calls.FetchDocumentHooksByBranchID = append(mock.calls.FetchDocumentHooksByBranchID, callInfo) + mock.lockFetchDocumentHooksByBranchID.Unlock() + if mock.FetchDocumentHooksByBranchIDFunc == nil { + var ( + hooksOut []hook.Hook + errOut error + ) + return hooksOut, errOut + } + return mock.FetchDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) +} + +// FetchDocumentHooksByBranchIDCalls gets all the calls that were made to FetchDocumentHooksByBranchID. +// Check the length with: +// +// len(mockedDB.FetchDocumentHooksByBranchIDCalls()) +func (mock *DBMock) FetchDocumentHooksByBranchIDCalls() []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + } + mock.lockFetchDocumentHooksByBranchID.RLock() + calls = mock.calls.FetchDocumentHooksByBranchID + mock.lockFetchDocumentHooksByBranchID.RUnlock() + return calls +} + // FetchDocumentTree calls FetchDocumentTreeFunc. func (mock *DBMock) FetchDocumentTree(ctx context.Context, organizationID string) (document.Summaries, error) { callInfo := struct { @@ -712,137 +1128,6 @@ func (mock *DBMock) FetchDocumentTreeByDocumentParentIDCalls() []struct { return calls } -// UpdateDocumentParentID calls UpdateDocumentParentIDFunc. -func (mock *DBMock) UpdateDocumentParentID(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error { - callInfo := struct { - Ctx context.Context - ID xid.ID - ParentID null.Value[xid.ID] - OrganizationID string - }{ - Ctx: ctx, - ID: id, - ParentID: parentID, - OrganizationID: organizationID, - } - mock.lockUpdateDocumentParentID.Lock() - mock.calls.UpdateDocumentParentID = append(mock.calls.UpdateDocumentParentID, callInfo) - mock.lockUpdateDocumentParentID.Unlock() - if mock.UpdateDocumentParentIDFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.UpdateDocumentParentIDFunc(ctx, id, parentID, organizationID) -} - -// UpdateDocumentParentIDCalls gets all the calls that were made to UpdateDocumentParentID. -// Check the length with: -// -// len(mockedDB.UpdateDocumentParentIDCalls()) -func (mock *DBMock) UpdateDocumentParentIDCalls() []struct { - Ctx context.Context - ID xid.ID - ParentID null.Value[xid.ID] - OrganizationID string -} { - var calls []struct { - Ctx context.Context - ID xid.ID - ParentID null.Value[xid.ID] - OrganizationID string - } - mock.lockUpdateDocumentParentID.RLock() - calls = mock.calls.UpdateDocumentParentID - mock.lockUpdateDocumentParentID.RUnlock() - return calls -} - -// FetchDataSource calls FetchDataSourceFunc. -func (mock *DBMock) FetchDataSource(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { - callInfo := struct { - Ctx context.Context - Id xid.ID - OrganizationID string - }{ - Ctx: ctx, - Id: id, - OrganizationID: organizationID, - } - mock.lockFetchDataSource.Lock() - mock.calls.FetchDataSource = append(mock.calls.FetchDataSource, callInfo) - mock.lockFetchDataSource.Unlock() - if mock.FetchDataSourceFunc == nil { - var ( - dataSourceOut *datasource.DataSource - errOut error - ) - return dataSourceOut, errOut - } - return mock.FetchDataSourceFunc(ctx, id, organizationID) -} - -// FetchDataSourceCalls gets all the calls that were made to FetchDataSource. -// Check the length with: -// -// len(mockedDB.FetchDataSourceCalls()) -func (mock *DBMock) FetchDataSourceCalls() []struct { - Ctx context.Context - Id xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - Id xid.ID - OrganizationID string - } - mock.lockFetchDataSource.RLock() - calls = mock.calls.FetchDataSource - mock.lockFetchDataSource.RUnlock() - return calls -} - -// FetchDataSources calls FetchDataSourcesFunc. -func (mock *DBMock) FetchDataSources(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { - callInfo := struct { - Ctx context.Context - OrganizationID string - }{ - Ctx: ctx, - OrganizationID: organizationID, - } - mock.lockFetchDataSources.Lock() - mock.calls.FetchDataSources = append(mock.calls.FetchDataSources, callInfo) - mock.lockFetchDataSources.Unlock() - if mock.FetchDataSourcesFunc == nil { - var ( - dataSourcesOut []datasource.DataSource - errOut error - ) - return dataSourcesOut, errOut - } - return mock.FetchDataSourcesFunc(ctx, organizationID) -} - -// FetchDataSourcesCalls gets all the calls that were made to FetchDataSources. -// Check the length with: -// -// len(mockedDB.FetchDataSourcesCalls()) -func (mock *DBMock) FetchDataSourcesCalls() []struct { - Ctx context.Context - OrganizationID string -} { - var calls []struct { - Ctx context.Context - OrganizationID string - } - mock.lockFetchDataSources.RLock() - calls = mock.calls.FetchDataSources - mock.lockFetchDataSources.RUnlock() - return calls -} - // FetchTagTree calls FetchTagTreeFunc. func (mock *DBMock) FetchTagTree(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) { callInfo := struct { @@ -887,51 +1172,42 @@ func (mock *DBMock) FetchTagTreeCalls() []struct { return calls } -// FetchBranchTags calls FetchBranchTagsFunc. -func (mock *DBMock) FetchBranchTags(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) { +// InsertDocumentHook calls InsertDocumentHookFunc. +func (mock *DBMock) InsertDocumentHook(ctx context.Context, hk hook.Hook) error { callInfo := struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID + Ctx context.Context + Hk hook.Hook }{ - Ctx: ctx, - OrganizationID: organizationID, - DocumentID: documentID, - BranchID: branchID, + Ctx: ctx, + Hk: hk, } - mock.lockFetchBranchTags.Lock() - mock.calls.FetchBranchTags = append(mock.calls.FetchBranchTags, callInfo) - mock.lockFetchBranchTags.Unlock() - if mock.FetchBranchTagsFunc == nil { + mock.lockInsertDocumentHook.Lock() + mock.calls.InsertDocumentHook = append(mock.calls.InsertDocumentHook, callInfo) + mock.lockInsertDocumentHook.Unlock() + if mock.InsertDocumentHookFunc == nil { var ( - tagsOut []tag.Tag - errOut error + errOut error ) - return tagsOut, errOut + return errOut } - return mock.FetchBranchTagsFunc(ctx, organizationID, documentID, branchID) + return mock.InsertDocumentHookFunc(ctx, hk) } -// FetchBranchTagsCalls gets all the calls that were made to FetchBranchTags. +// InsertDocumentHookCalls gets all the calls that were made to InsertDocumentHook. // Check the length with: // -// len(mockedDB.FetchBranchTagsCalls()) -func (mock *DBMock) FetchBranchTagsCalls() []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID +// len(mockedDB.InsertDocumentHookCalls()) +func (mock *DBMock) InsertDocumentHookCalls() []struct { + Ctx context.Context + Hk hook.Hook } { var calls []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID + Ctx context.Context + Hk hook.Hook } - mock.lockFetchBranchTags.RLock() - calls = mock.calls.FetchBranchTags - mock.lockFetchBranchTags.RUnlock() + mock.lockInsertDocumentHook.RLock() + calls = mock.calls.InsertDocumentHook + mock.lockInsertDocumentHook.RUnlock() return calls } @@ -974,147 +1250,6 @@ func (mock *DBMock) InsertTagCalls() []struct { return calls } -// UpdateTag calls UpdateTagFunc. -func (mock *DBMock) UpdateTag(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error { - callInfo := struct { - Ctx context.Context - OrganizationID string - ID xid.ID - Inp tag.UpdateInput - }{ - Ctx: ctx, - OrganizationID: organizationID, - ID: id, - Inp: inp, - } - mock.lockUpdateTag.Lock() - mock.calls.UpdateTag = append(mock.calls.UpdateTag, callInfo) - mock.lockUpdateTag.Unlock() - if mock.UpdateTagFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.UpdateTagFunc(ctx, organizationID, id, inp) -} - -// UpdateTagCalls gets all the calls that were made to UpdateTag. -// Check the length with: -// -// len(mockedDB.UpdateTagCalls()) -func (mock *DBMock) UpdateTagCalls() []struct { - Ctx context.Context - OrganizationID string - ID xid.ID - Inp tag.UpdateInput -} { - var calls []struct { - Ctx context.Context - OrganizationID string - ID xid.ID - Inp tag.UpdateInput - } - mock.lockUpdateTag.RLock() - calls = mock.calls.UpdateTag - mock.lockUpdateTag.RUnlock() - return calls -} - -// DeleteTag calls DeleteTagFunc. -func (mock *DBMock) DeleteTag(ctx context.Context, id xid.ID, organizationID string) error { - callInfo := struct { - Ctx context.Context - ID xid.ID - OrganizationID string - }{ - Ctx: ctx, - ID: id, - OrganizationID: organizationID, - } - mock.lockDeleteTag.Lock() - mock.calls.DeleteTag = append(mock.calls.DeleteTag, callInfo) - mock.lockDeleteTag.Unlock() - if mock.DeleteTagFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.DeleteTagFunc(ctx, id, organizationID) -} - -// DeleteTagCalls gets all the calls that were made to DeleteTag. -// Check the length with: -// -// len(mockedDB.DeleteTagCalls()) -func (mock *DBMock) DeleteTagCalls() []struct { - Ctx context.Context - ID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - ID xid.ID - OrganizationID string - } - mock.lockDeleteTag.RLock() - calls = mock.calls.DeleteTag - mock.lockDeleteTag.RUnlock() - return calls -} - -// AssignBranchTag calls AssignBranchTagFunc. -func (mock *DBMock) AssignBranchTag(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { - callInfo := struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID - TagID xid.ID - }{ - Ctx: ctx, - OrganizationID: organizationID, - DocumentID: documentID, - BranchID: branchID, - TagID: tagID, - } - mock.lockAssignBranchTag.Lock() - mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) - mock.lockAssignBranchTag.Unlock() - if mock.AssignBranchTagFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) -} - -// AssignBranchTagCalls gets all the calls that were made to AssignBranchTag. -// Check the length with: -// -// len(mockedDB.AssignBranchTagCalls()) -func (mock *DBMock) AssignBranchTagCalls() []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID - TagID xid.ID -} { - var calls []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID - TagID xid.ID - } - mock.lockAssignBranchTag.RLock() - calls = mock.calls.AssignBranchTag - mock.lockAssignBranchTag.RUnlock() - return calls -} - // UnassignBranchTag calls UnassignBranchTagFunc. func (mock *DBMock) UnassignBranchTag(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { callInfo := struct { @@ -1166,6 +1301,139 @@ func (mock *DBMock) UnassignBranchTagCalls() []struct { return calls } +// UpdateDocumentHook calls UpdateDocumentHookFunc. +func (mock *DBMock) UpdateDocumentHook(ctx context.Context, hk hook.Hook) error { + callInfo := struct { + Ctx context.Context + Hk hook.Hook + }{ + Ctx: ctx, + Hk: hk, + } + mock.lockUpdateDocumentHook.Lock() + mock.calls.UpdateDocumentHook = append(mock.calls.UpdateDocumentHook, callInfo) + mock.lockUpdateDocumentHook.Unlock() + if mock.UpdateDocumentHookFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.UpdateDocumentHookFunc(ctx, hk) +} + +// UpdateDocumentHookCalls gets all the calls that were made to UpdateDocumentHook. +// Check the length with: +// +// len(mockedDB.UpdateDocumentHookCalls()) +func (mock *DBMock) UpdateDocumentHookCalls() []struct { + Ctx context.Context + Hk hook.Hook +} { + var calls []struct { + Ctx context.Context + Hk hook.Hook + } + mock.lockUpdateDocumentHook.RLock() + calls = mock.calls.UpdateDocumentHook + mock.lockUpdateDocumentHook.RUnlock() + return calls +} + +// UpdateDocumentParentID calls UpdateDocumentParentIDFunc. +func (mock *DBMock) UpdateDocumentParentID(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error { + callInfo := struct { + Ctx context.Context + ID xid.ID + ParentID null.Value[xid.ID] + OrganizationID string + }{ + Ctx: ctx, + ID: id, + ParentID: parentID, + OrganizationID: organizationID, + } + mock.lockUpdateDocumentParentID.Lock() + mock.calls.UpdateDocumentParentID = append(mock.calls.UpdateDocumentParentID, callInfo) + mock.lockUpdateDocumentParentID.Unlock() + if mock.UpdateDocumentParentIDFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.UpdateDocumentParentIDFunc(ctx, id, parentID, organizationID) +} + +// UpdateDocumentParentIDCalls gets all the calls that were made to UpdateDocumentParentID. +// Check the length with: +// +// len(mockedDB.UpdateDocumentParentIDCalls()) +func (mock *DBMock) UpdateDocumentParentIDCalls() []struct { + Ctx context.Context + ID xid.ID + ParentID null.Value[xid.ID] + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + ParentID null.Value[xid.ID] + OrganizationID string + } + mock.lockUpdateDocumentParentID.RLock() + calls = mock.calls.UpdateDocumentParentID + mock.lockUpdateDocumentParentID.RUnlock() + return calls +} + +// UpdateTag calls UpdateTagFunc. +func (mock *DBMock) UpdateTag(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error { + callInfo := struct { + Ctx context.Context + OrganizationID string + ID xid.ID + Inp tag.UpdateInput + }{ + Ctx: ctx, + OrganizationID: organizationID, + ID: id, + Inp: inp, + } + mock.lockUpdateTag.Lock() + mock.calls.UpdateTag = append(mock.calls.UpdateTag, callInfo) + mock.lockUpdateTag.Unlock() + if mock.UpdateTagFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.UpdateTagFunc(ctx, organizationID, id, inp) +} + +// UpdateTagCalls gets all the calls that were made to UpdateTag. +// Check the length with: +// +// len(mockedDB.UpdateTagCalls()) +func (mock *DBMock) UpdateTagCalls() []struct { + Ctx context.Context + OrganizationID string + ID xid.ID + Inp tag.UpdateInput +} { + var calls []struct { + Ctx context.Context + OrganizationID string + ID xid.ID + Inp tag.UpdateInput + } + mock.lockUpdateTag.RLock() + calls = mock.calls.UpdateTag + mock.lockUpdateTag.RUnlock() + return calls +} + // UpdateTagTree calls UpdateTagTreeFunc. func (mock *DBMock) UpdateTagTree(ctx context.Context, tree tag.Summaries, organizationID string) error { callInfo := struct { @@ -1208,208 +1476,3 @@ func (mock *DBMock) UpdateTagTreeCalls() []struct { mock.lockUpdateTagTree.RUnlock() return calls } - -// FetchDocumentHooksByBranchID calls FetchDocumentHooksByBranchIDFunc. -func (mock *DBMock) FetchDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) ([]hookCore.Hook, error) { - callInfo := struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - }{ - Ctx: ctx, - BranchID: branchID, - OrganizationID: organizationID, - } - mock.lockFetchDocumentHooksByBranchID.Lock() - mock.calls.FetchDocumentHooksByBranchID = append(mock.calls.FetchDocumentHooksByBranchID, callInfo) - mock.lockFetchDocumentHooksByBranchID.Unlock() - if mock.FetchDocumentHooksByBranchIDFunc == nil { - var ( - hooksOut []hookCore.Hook - errOut error - ) - return hooksOut, errOut - } - return mock.FetchDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) -} - -// FetchDocumentHooksByBranchIDCalls gets all the calls that were made to FetchDocumentHooksByBranchID. -// Check the length with: -// -// len(mockedDB.FetchDocumentHooksByBranchIDCalls()) -func (mock *DBMock) FetchDocumentHooksByBranchIDCalls() []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - } - mock.lockFetchDocumentHooksByBranchID.RLock() - calls = mock.calls.FetchDocumentHooksByBranchID - mock.lockFetchDocumentHooksByBranchID.RUnlock() - return calls -} - -// FetchDocumentHook calls FetchDocumentHookFunc. -func (mock *DBMock) FetchDocumentHook(ctx context.Context, id xid.ID, organizationID string) (*hookCore.Hook, error) { - callInfo := struct { - Ctx context.Context - ID xid.ID - OrganizationID string - }{ - Ctx: ctx, - ID: id, - OrganizationID: organizationID, - } - mock.lockFetchDocumentHook.Lock() - mock.calls.FetchDocumentHook = append(mock.calls.FetchDocumentHook, callInfo) - mock.lockFetchDocumentHook.Unlock() - if mock.FetchDocumentHookFunc == nil { - var ( - hookOut *hookCore.Hook - errOut error - ) - return hookOut, errOut - } - return mock.FetchDocumentHookFunc(ctx, id, organizationID) -} - -// FetchDocumentHookCalls gets all the calls that were made to FetchDocumentHook. -// Check the length with: -// -// len(mockedDB.FetchDocumentHookCalls()) -func (mock *DBMock) FetchDocumentHookCalls() []struct { - Ctx context.Context - ID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - ID xid.ID - OrganizationID string - } - mock.lockFetchDocumentHook.RLock() - calls = mock.calls.FetchDocumentHook - mock.lockFetchDocumentHook.RUnlock() - return calls -} - -// InsertDocumentHook calls InsertDocumentHookFunc. -func (mock *DBMock) InsertDocumentHook(ctx context.Context, hk hookCore.Hook) error { - callInfo := struct { - Ctx context.Context - Hk hookCore.Hook - }{ - Ctx: ctx, - Hk: hk, - } - mock.lockInsertDocumentHook.Lock() - mock.calls.InsertDocumentHook = append(mock.calls.InsertDocumentHook, callInfo) - mock.lockInsertDocumentHook.Unlock() - if mock.InsertDocumentHookFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.InsertDocumentHookFunc(ctx, hk) -} - -// InsertDocumentHookCalls gets all the calls that were made to InsertDocumentHook. -// Check the length with: -// -// len(mockedDB.InsertDocumentHookCalls()) -func (mock *DBMock) InsertDocumentHookCalls() []struct { - Ctx context.Context - Hk hookCore.Hook -} { - var calls []struct { - Ctx context.Context - Hk hookCore.Hook - } - mock.lockInsertDocumentHook.RLock() - calls = mock.calls.InsertDocumentHook - mock.lockInsertDocumentHook.RUnlock() - return calls -} - -// UpdateDocumentHook calls UpdateDocumentHookFunc. -func (mock *DBMock) UpdateDocumentHook(ctx context.Context, hk hookCore.Hook) error { - callInfo := struct { - Ctx context.Context - Hk hookCore.Hook - }{ - Ctx: ctx, - Hk: hk, - } - mock.lockUpdateDocumentHook.Lock() - mock.calls.UpdateDocumentHook = append(mock.calls.UpdateDocumentHook, callInfo) - mock.lockUpdateDocumentHook.Unlock() - if mock.UpdateDocumentHookFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.UpdateDocumentHookFunc(ctx, hk) -} - -// UpdateDocumentHookCalls gets all the calls that were made to UpdateDocumentHook. -// Check the length with: -// -// len(mockedDB.UpdateDocumentHookCalls()) -func (mock *DBMock) UpdateDocumentHookCalls() []struct { - Ctx context.Context - Hk hookCore.Hook -} { - var calls []struct { - Ctx context.Context - Hk hookCore.Hook - } - mock.lockUpdateDocumentHook.RLock() - calls = mock.calls.UpdateDocumentHook - mock.lockUpdateDocumentHook.RUnlock() - return calls -} - -// DeleteDocumentHook calls DeleteDocumentHookFunc. -func (mock *DBMock) DeleteDocumentHook(ctx context.Context, id xid.ID) error { - callInfo := struct { - Ctx context.Context - ID xid.ID - }{ - Ctx: ctx, - ID: id, - } - mock.lockDeleteDocumentHook.Lock() - mock.calls.DeleteDocumentHook = append(mock.calls.DeleteDocumentHook, callInfo) - mock.lockDeleteDocumentHook.Unlock() - if mock.DeleteDocumentHookFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.DeleteDocumentHookFunc(ctx, id) -} - -// DeleteDocumentHookCalls gets all the calls that were made to DeleteDocumentHook. -// Check the length with: -// -// len(mockedDB.DeleteDocumentHookCalls()) -func (mock *DBMock) DeleteDocumentHookCalls() []struct { - Ctx context.Context - ID xid.ID -} { - var calls []struct { - Ctx context.Context - ID xid.ID - } - mock.lockDeleteDocumentHook.RLock() - calls = mock.calls.DeleteDocumentHook - mock.lockDeleteDocumentHook.RUnlock() - return calls -} diff --git a/server/core/internal/assistant/tools/0mock_search_trigger_test.go b/server/core/internal/assistant/tools/0mock_search_trigger_test.go index 07a7fd1d..c7432b86 100644 --- a/server/core/internal/assistant/tools/0mock_search_trigger_test.go +++ b/server/core/internal/assistant/tools/0mock_search_trigger_test.go @@ -17,7 +17,7 @@ var _ SearchTrigger = &SearchTriggerMock{} // // // make and configure a mocked SearchTrigger // mockedSearchTrigger := &SearchTriggerMock{ -// TriggerFunc: func() { +// TriggerFunc: func() { // panic("mock out the Trigger method") // }, // } diff --git a/server/core/internal/assistant/tools/0mock_tx_test.go b/server/core/internal/assistant/tools/0mock_tx_test.go index cd187018..6f319c45 100644 --- a/server/core/internal/assistant/tools/0mock_tx_test.go +++ b/server/core/internal/assistant/tools/0mock_tx_test.go @@ -25,6 +25,9 @@ var _ Tx = &TxMock{} // CommitFunc: func() error { // panic("mock out the Commit method") // }, +// DeleteDocumentFunc: func(ctx context.Context, id xid.ID, organizationID string) ([]xid.ID, error) { +// panic("mock out the DeleteDocument method") +// }, // InsertDocumentFunc: func(ctx context.Context, doc document.Document) error { // panic("mock out the InsertDocument method") // }, @@ -143,6 +146,50 @@ func (mock *TxMock) CommitCalls() []struct { return calls } +// DeleteDocument calls DeleteDocumentFunc. +func (mock *TxMock) DeleteDocument(ctx context.Context, id xid.ID, organizationID string) ([]xid.ID, error) { + callInfo := struct { + Ctx context.Context + ID xid.ID + OrganizationID string + }{ + Ctx: ctx, + ID: id, + OrganizationID: organizationID, + } + mock.lockDeleteDocument.Lock() + mock.calls.DeleteDocument = append(mock.calls.DeleteDocument, callInfo) + mock.lockDeleteDocument.Unlock() + if mock.DeleteDocumentFunc == nil { + var ( + iDsOut []xid.ID + errOut error + ) + return iDsOut, errOut + } + return mock.DeleteDocumentFunc(ctx, id, organizationID) +} + +// DeleteDocumentCalls gets all the calls that were made to DeleteDocument. +// Check the length with: +// +// len(mockedTx.DeleteDocumentCalls()) +func (mock *TxMock) DeleteDocumentCalls() []struct { + Ctx context.Context + ID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + OrganizationID string + } + mock.lockDeleteDocument.RLock() + calls = mock.calls.DeleteDocument + mock.lockDeleteDocument.RUnlock() + return calls +} + // InsertDocument calls InsertDocumentFunc. func (mock *TxMock) InsertDocument(ctx context.Context, doc document.Document) error { callInfo := struct { @@ -297,47 +344,3 @@ func (mock *TxMock) UpsertDocumentMaintainersCalls() []struct { mock.lockUpsertDocumentMaintainers.RUnlock() return calls } - -// DeleteDocument calls DeleteDocumentFunc. -func (mock *TxMock) DeleteDocument(ctx context.Context, id xid.ID, organizationID string) ([]xid.ID, error) { - callInfo := struct { - Ctx context.Context - ID xid.ID - OrganizationID string - }{ - Ctx: ctx, - ID: id, - OrganizationID: organizationID, - } - mock.lockDeleteDocument.Lock() - mock.calls.DeleteDocument = append(mock.calls.DeleteDocument, callInfo) - mock.lockDeleteDocument.Unlock() - if mock.DeleteDocumentFunc == nil { - var ( - iDsOut []xid.ID - errOut error - ) - return iDsOut, errOut - } - return mock.DeleteDocumentFunc(ctx, id, organizationID) -} - -// DeleteDocumentCalls gets all the calls that were made to DeleteDocument. -// Check the length with: -// -// len(mockedTx.DeleteDocumentCalls()) -func (mock *TxMock) DeleteDocumentCalls() []struct { - Ctx context.Context - ID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - ID xid.ID - OrganizationID string - } - mock.lockDeleteDocument.RLock() - calls = mock.calls.DeleteDocument - mock.lockDeleteDocument.RUnlock() - return calls -} diff --git a/server/core/internal/assistant/tools/_mock/db.go b/server/core/internal/assistant/tools/_mock/db.go index 6910bbbb..1e4bf8c3 100644 --- a/server/core/internal/assistant/tools/_mock/db.go +++ b/server/core/internal/assistant/tools/_mock/db.go @@ -11,7 +11,7 @@ import ( "github.com/oxynote/oxynote/server/core/internal/assistant/tools" "github.com/oxynote/oxynote/server/core/internal/datasource" "github.com/oxynote/oxynote/server/core/internal/document" - hookCore "github.com/oxynote/oxynote/server/core/internal/document/hook" + "github.com/oxynote/oxynote/server/core/internal/document/hook" "github.com/oxynote/oxynote/server/core/internal/tag" "github.com/rs/xid" ) @@ -26,6 +26,9 @@ var _ tools.DB = &DB{} // // // make and configure a mocked tools.DB // mockedDB := &DB{ +// AssignBranchTagFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { +// panic("mock out the AssignBranchTag method") +// }, // BeginTxFunc: func(ctx context.Context, dest any) error { // panic("mock out the BeginTx method") // }, @@ -35,18 +38,66 @@ var _ tools.DB = &DB{} // CheckDocumentExistsFunc: func(ctx context.Context, id xid.ID, organizationID string) error { // panic("mock out the CheckDocumentExists method") // }, +// DeleteDocumentHookFunc: func(ctx context.Context, id xid.ID) error { +// panic("mock out the DeleteDocumentHook method") +// }, +// DeleteTagFunc: func(ctx context.Context, id xid.ID, organizationID string) error { +// panic("mock out the DeleteTag method") +// }, +// FetchBranchTagsFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) { +// panic("mock out the FetchBranchTags method") +// }, +// FetchDataSourceFunc: func(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { +// panic("mock out the FetchDataSource method") +// }, +// FetchDataSourcesFunc: func(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { +// panic("mock out the FetchDataSources method") +// }, // FetchDocumentFunc: func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) { // panic("mock out the FetchDocument method") // }, +// FetchDocumentBranchesFunc: func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) { +// panic("mock out the FetchDocumentBranches method") +// }, +// FetchDocumentByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) { +// panic("mock out the FetchDocumentByBranchID method") +// }, +// FetchDocumentHookFunc: func(ctx context.Context, id xid.ID, organizationID string) (*hook.Hook, error) { +// panic("mock out the FetchDocumentHook method") +// }, +// FetchDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) ([]hook.Hook, error) { +// panic("mock out the FetchDocumentHooksByBranchID method") +// }, // FetchDocumentTreeFunc: func(ctx context.Context, organizationID string) (document.Summaries, error) { // panic("mock out the FetchDocumentTree method") // }, // FetchDocumentTreeByDocumentParentIDFunc: func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) { // panic("mock out the FetchDocumentTreeByDocumentParentID method") // }, +// FetchTagTreeFunc: func(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) { +// panic("mock out the FetchTagTree method") +// }, +// InsertDocumentHookFunc: func(ctx context.Context, hk hook.Hook) error { +// panic("mock out the InsertDocumentHook method") +// }, +// InsertTagFunc: func(ctx context.Context, t tag.Tag) error { +// panic("mock out the InsertTag method") +// }, +// UnassignBranchTagFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { +// panic("mock out the UnassignBranchTag method") +// }, +// UpdateDocumentHookFunc: func(ctx context.Context, hk hook.Hook) error { +// panic("mock out the UpdateDocumentHook method") +// }, // UpdateDocumentParentIDFunc: func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error { // panic("mock out the UpdateDocumentParentID method") // }, +// UpdateTagFunc: func(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error { +// panic("mock out the UpdateTag method") +// }, +// UpdateTagTreeFunc: func(ctx context.Context, tree tag.Summaries, organizationID string) error { +// panic("mock out the UpdateTagTree method") +// }, // } // // // use mockedDB in code that requires tools.DB @@ -54,6 +105,9 @@ var _ tools.DB = &DB{} // // } type DB struct { + // AssignBranchTagFunc mocks the AssignBranchTag method. + AssignBranchTagFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error + // BeginTxFunc mocks the BeginTx method. BeginTxFunc func(ctx context.Context, dest any) error @@ -63,23 +117,14 @@ type DB struct { // CheckDocumentExistsFunc mocks the CheckDocumentExists method. CheckDocumentExistsFunc func(ctx context.Context, id xid.ID, organizationID string) error - // FetchDocumentFunc mocks the FetchDocument method. - FetchDocumentFunc func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) + // DeleteDocumentHookFunc mocks the DeleteDocumentHook method. + DeleteDocumentHookFunc func(ctx context.Context, id xid.ID) error - // FetchDocumentTreeFunc mocks the FetchDocumentTree method. - FetchDocumentTreeFunc func(ctx context.Context, organizationID string) (document.Summaries, error) + // DeleteTagFunc mocks the DeleteTag method. + DeleteTagFunc func(ctx context.Context, id xid.ID, organizationID string) error - // FetchDocumentTreeByDocumentParentIDFunc mocks the FetchDocumentTreeByDocumentParentID method. - FetchDocumentTreeByDocumentParentIDFunc func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) - - // FetchDocumentBranchesFunc mocks the FetchDocumentBranches method. - FetchDocumentBranchesFunc func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) - - // FetchDocumentByBranchIDFunc mocks the FetchDocumentByBranchID method. - FetchDocumentByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) - - // UpdateDocumentParentIDFunc mocks the UpdateDocumentParentID method. - UpdateDocumentParentIDFunc func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error + // FetchBranchTagsFunc mocks the FetchBranchTags method. + FetchBranchTagsFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) // FetchDataSourceFunc mocks the FetchDataSource method. FetchDataSourceFunc func(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) @@ -87,35 +132,66 @@ type DB struct { // FetchDataSourcesFunc mocks the FetchDataSources method. FetchDataSourcesFunc func(ctx context.Context, organizationID string) ([]datasource.DataSource, error) + // FetchDocumentFunc mocks the FetchDocument method. + FetchDocumentFunc func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) + + // FetchDocumentBranchesFunc mocks the FetchDocumentBranches method. + FetchDocumentBranchesFunc func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) + + // FetchDocumentByBranchIDFunc mocks the FetchDocumentByBranchID method. + FetchDocumentByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) + + // FetchDocumentHookFunc mocks the FetchDocumentHook method. + FetchDocumentHookFunc func(ctx context.Context, id xid.ID, organizationID string) (*hook.Hook, error) + + // FetchDocumentHooksByBranchIDFunc mocks the FetchDocumentHooksByBranchID method. + FetchDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) ([]hook.Hook, error) + + // FetchDocumentTreeFunc mocks the FetchDocumentTree method. + FetchDocumentTreeFunc func(ctx context.Context, organizationID string) (document.Summaries, error) + + // FetchDocumentTreeByDocumentParentIDFunc mocks the FetchDocumentTreeByDocumentParentID method. + FetchDocumentTreeByDocumentParentIDFunc func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) + // FetchTagTreeFunc mocks the FetchTagTree method. FetchTagTreeFunc func(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) - // FetchBranchTagsFunc mocks the FetchBranchTags method. - FetchBranchTagsFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) + + // InsertDocumentHookFunc mocks the InsertDocumentHook method. + InsertDocumentHookFunc func(ctx context.Context, hk hook.Hook) error + // InsertTagFunc mocks the InsertTag method. InsertTagFunc func(ctx context.Context, t tag.Tag) error - // UpdateTagFunc mocks the UpdateTag method. - UpdateTagFunc func(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error - // DeleteTagFunc mocks the DeleteTag method. - DeleteTagFunc func(ctx context.Context, id xid.ID, organizationID string) error - // AssignBranchTagFunc mocks the AssignBranchTag method. - AssignBranchTagFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error + // UnassignBranchTagFunc mocks the UnassignBranchTag method. UnassignBranchTagFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error + + // UpdateDocumentHookFunc mocks the UpdateDocumentHook method. + UpdateDocumentHookFunc func(ctx context.Context, hk hook.Hook) error + + // UpdateDocumentParentIDFunc mocks the UpdateDocumentParentID method. + UpdateDocumentParentIDFunc func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error + + // UpdateTagFunc mocks the UpdateTag method. + UpdateTagFunc func(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error + // UpdateTagTreeFunc mocks the UpdateTagTree method. UpdateTagTreeFunc func(ctx context.Context, tree tag.Summaries, organizationID string) error - // FetchDocumentHooksByBranchIDFunc mocks the FetchDocumentHooksByBranchID method. - FetchDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) ([]hookCore.Hook, error) - // FetchDocumentHookFunc mocks the FetchDocumentHook method. - FetchDocumentHookFunc func(ctx context.Context, id xid.ID, organizationID string) (*hookCore.Hook, error) - // InsertDocumentHookFunc mocks the InsertDocumentHook method. - InsertDocumentHookFunc func(ctx context.Context, hk hookCore.Hook) error - // UpdateDocumentHookFunc mocks the UpdateDocumentHook method. - UpdateDocumentHookFunc func(ctx context.Context, hk hookCore.Hook) error - // DeleteDocumentHookFunc mocks the DeleteDocumentHook method. - DeleteDocumentHookFunc func(ctx context.Context, id xid.ID) error // calls tracks calls to the methods. calls struct { + // AssignBranchTag holds details about calls to the AssignBranchTag method. + AssignBranchTag []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + // DocumentID is the documentID argument value. + DocumentID xid.ID + // BranchID is the branchID argument value. + BranchID xid.ID + // TagID is the tagID argument value. + TagID xid.ID + } // BeginTx holds details about calls to the BeginTx method. BeginTx []struct { // Ctx is the ctx argument value. @@ -143,6 +219,49 @@ type DB struct { // OrganizationID is the organizationID argument value. OrganizationID string } + // DeleteDocumentHook holds details about calls to the DeleteDocumentHook method. + DeleteDocumentHook []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + } + // DeleteTag holds details about calls to the DeleteTag method. + DeleteTag []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // FetchBranchTags holds details about calls to the FetchBranchTags method. + FetchBranchTags []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + // DocumentID is the documentID argument value. + DocumentID xid.ID + // BranchID is the branchID argument value. + BranchID xid.ID + } + // FetchDataSource holds details about calls to the FetchDataSource method. + FetchDataSource []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // FetchDataSources holds details about calls to the FetchDataSources method. + FetchDataSources []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + } // FetchDocument holds details about calls to the FetchDocument method. FetchDocument []struct { // Ctx is the ctx argument value. @@ -172,6 +291,24 @@ type DB struct { // OrganizationID is the organizationID argument value. OrganizationID string } + // FetchDocumentHook holds details about calls to the FetchDocumentHook method. + FetchDocumentHook []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // FetchDocumentHooksByBranchID holds details about calls to the FetchDocumentHooksByBranchID method. + FetchDocumentHooksByBranchID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // BranchID is the branchID argument value. + BranchID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } // FetchDocumentTree holds details about calls to the FetchDocumentTree method. FetchDocumentTree []struct { // Ctx is the ctx argument value. @@ -188,33 +325,6 @@ type DB struct { // OrganizationID is the organizationID argument value. OrganizationID string } - // UpdateDocumentParentID holds details about calls to the UpdateDocumentParentID method. - UpdateDocumentParentID []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - // ParentID is the parentID argument value. - ParentID null.Value[xid.ID] - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // FetchDataSource holds details about calls to the FetchDataSource method. - FetchDataSource []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Id is the id argument value. - Id xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // FetchDataSources holds details about calls to the FetchDataSources method. - FetchDataSources []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - } // FetchTagTree holds details about calls to the FetchTagTree method. FetchTagTree []struct { // Ctx is the ctx argument value. @@ -224,16 +334,12 @@ type DB struct { // UserID is the userID argument value. UserID string } - // FetchBranchTags holds details about calls to the FetchBranchTags method. - FetchBranchTags []struct { + // InsertDocumentHook holds details about calls to the InsertDocumentHook method. + InsertDocumentHook []struct { // Ctx is the ctx argument value. Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - // DocumentID is the documentID argument value. - DocumentID xid.ID - // BranchID is the branchID argument value. - BranchID xid.ID + // Hk is the hk argument value. + Hk hook.Hook } // InsertTag holds details about calls to the InsertTag method. InsertTag []struct { @@ -242,39 +348,6 @@ type DB struct { // T is the t argument value. T tag.Tag } - // UpdateTag holds details about calls to the UpdateTag method. - UpdateTag []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - // ID is the id argument value. - ID xid.ID - // Inp is the inp argument value. - Inp tag.UpdateInput - } - // DeleteTag holds details about calls to the DeleteTag method. - DeleteTag []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // AssignBranchTag holds details about calls to the AssignBranchTag method. - AssignBranchTag []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // OrganizationID is the organizationID argument value. - OrganizationID string - // DocumentID is the documentID argument value. - DocumentID xid.ID - // BranchID is the branchID argument value. - BranchID xid.ID - // TagID is the tagID argument value. - TagID xid.ID - } // UnassignBranchTag holds details about calls to the UnassignBranchTag method. UnassignBranchTag []struct { // Ctx is the ctx argument value. @@ -288,6 +361,35 @@ type DB struct { // TagID is the tagID argument value. TagID xid.ID } + // UpdateDocumentHook holds details about calls to the UpdateDocumentHook method. + UpdateDocumentHook []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Hk is the hk argument value. + Hk hook.Hook + } + // UpdateDocumentParentID holds details about calls to the UpdateDocumentParentID method. + UpdateDocumentParentID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID xid.ID + // ParentID is the parentID argument value. + ParentID null.Value[xid.ID] + // OrganizationID is the organizationID argument value. + OrganizationID string + } + // UpdateTag holds details about calls to the UpdateTag method. + UpdateTag []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // OrganizationID is the organizationID argument value. + OrganizationID string + // ID is the id argument value. + ID xid.ID + // Inp is the inp argument value. + Inp tag.UpdateInput + } // UpdateTagTree holds details about calls to the UpdateTagTree method. UpdateTagTree []struct { // Ctx is the ctx argument value. @@ -297,70 +399,82 @@ type DB struct { // OrganizationID is the organizationID argument value. OrganizationID string } - // FetchDocumentHooksByBranchID holds details about calls to the FetchDocumentHooksByBranchID method. - FetchDocumentHooksByBranchID []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // BranchID is the branchID argument value. - BranchID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // FetchDocumentHook holds details about calls to the FetchDocumentHook method. - FetchDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } - // InsertDocumentHook holds details about calls to the InsertDocumentHook method. - InsertDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Hk is the hk argument value. - Hk hookCore.Hook - } - // UpdateDocumentHook holds details about calls to the UpdateDocumentHook method. - UpdateDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Hk is the hk argument value. - Hk hookCore.Hook - } - // DeleteDocumentHook holds details about calls to the DeleteDocumentHook method. - DeleteDocumentHook []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID xid.ID - } } + lockAssignBranchTag sync.RWMutex lockBeginTx sync.RWMutex lockCheckDocumentCycle sync.RWMutex lockCheckDocumentExists sync.RWMutex + lockDeleteDocumentHook sync.RWMutex + lockDeleteTag sync.RWMutex + lockFetchBranchTags sync.RWMutex + lockFetchDataSource sync.RWMutex + lockFetchDataSources sync.RWMutex lockFetchDocument sync.RWMutex lockFetchDocumentBranches sync.RWMutex lockFetchDocumentByBranchID sync.RWMutex + lockFetchDocumentHook sync.RWMutex + lockFetchDocumentHooksByBranchID sync.RWMutex lockFetchDocumentTree sync.RWMutex lockFetchDocumentTreeByDocumentParentID sync.RWMutex - lockUpdateDocumentParentID sync.RWMutex - lockFetchDataSource sync.RWMutex - lockFetchDataSources sync.RWMutex lockFetchTagTree sync.RWMutex - lockFetchBranchTags sync.RWMutex - lockInsertTag sync.RWMutex - lockUpdateTag sync.RWMutex - lockDeleteTag sync.RWMutex - lockAssignBranchTag sync.RWMutex - lockUnassignBranchTag sync.RWMutex - lockUpdateTagTree sync.RWMutex - lockFetchDocumentHooksByBranchID sync.RWMutex - lockFetchDocumentHook sync.RWMutex lockInsertDocumentHook sync.RWMutex + lockInsertTag sync.RWMutex + lockUnassignBranchTag sync.RWMutex lockUpdateDocumentHook sync.RWMutex - lockDeleteDocumentHook sync.RWMutex + lockUpdateDocumentParentID sync.RWMutex + lockUpdateTag sync.RWMutex + lockUpdateTagTree sync.RWMutex +} + +// AssignBranchTag calls AssignBranchTagFunc. +func (mock *DB) AssignBranchTag(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { + callInfo := struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + TagID xid.ID + }{ + Ctx: ctx, + OrganizationID: organizationID, + DocumentID: documentID, + BranchID: branchID, + TagID: tagID, + } + mock.lockAssignBranchTag.Lock() + mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) + mock.lockAssignBranchTag.Unlock() + if mock.AssignBranchTagFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) +} + +// AssignBranchTagCalls gets all the calls that were made to AssignBranchTag. +// Check the length with: +// +// len(mockedDB.AssignBranchTagCalls()) +func (mock *DB) AssignBranchTagCalls() []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + TagID xid.ID +} { + var calls []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + TagID xid.ID + } + mock.lockAssignBranchTag.RLock() + calls = mock.calls.AssignBranchTag + mock.lockAssignBranchTag.RUnlock() + return calls } // BeginTx calls BeginTxFunc. @@ -493,6 +607,220 @@ func (mock *DB) CheckDocumentExistsCalls() []struct { return calls } +// DeleteDocumentHook calls DeleteDocumentHookFunc. +func (mock *DB) DeleteDocumentHook(ctx context.Context, id xid.ID) error { + callInfo := struct { + Ctx context.Context + ID xid.ID + }{ + Ctx: ctx, + ID: id, + } + mock.lockDeleteDocumentHook.Lock() + mock.calls.DeleteDocumentHook = append(mock.calls.DeleteDocumentHook, callInfo) + mock.lockDeleteDocumentHook.Unlock() + if mock.DeleteDocumentHookFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.DeleteDocumentHookFunc(ctx, id) +} + +// DeleteDocumentHookCalls gets all the calls that were made to DeleteDocumentHook. +// Check the length with: +// +// len(mockedDB.DeleteDocumentHookCalls()) +func (mock *DB) DeleteDocumentHookCalls() []struct { + Ctx context.Context + ID xid.ID +} { + var calls []struct { + Ctx context.Context + ID xid.ID + } + mock.lockDeleteDocumentHook.RLock() + calls = mock.calls.DeleteDocumentHook + mock.lockDeleteDocumentHook.RUnlock() + return calls +} + +// DeleteTag calls DeleteTagFunc. +func (mock *DB) DeleteTag(ctx context.Context, id xid.ID, organizationID string) error { + callInfo := struct { + Ctx context.Context + ID xid.ID + OrganizationID string + }{ + Ctx: ctx, + ID: id, + OrganizationID: organizationID, + } + mock.lockDeleteTag.Lock() + mock.calls.DeleteTag = append(mock.calls.DeleteTag, callInfo) + mock.lockDeleteTag.Unlock() + if mock.DeleteTagFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.DeleteTagFunc(ctx, id, organizationID) +} + +// DeleteTagCalls gets all the calls that were made to DeleteTag. +// Check the length with: +// +// len(mockedDB.DeleteTagCalls()) +func (mock *DB) DeleteTagCalls() []struct { + Ctx context.Context + ID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + OrganizationID string + } + mock.lockDeleteTag.RLock() + calls = mock.calls.DeleteTag + mock.lockDeleteTag.RUnlock() + return calls +} + +// FetchBranchTags calls FetchBranchTagsFunc. +func (mock *DB) FetchBranchTags(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) { + callInfo := struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + }{ + Ctx: ctx, + OrganizationID: organizationID, + DocumentID: documentID, + BranchID: branchID, + } + mock.lockFetchBranchTags.Lock() + mock.calls.FetchBranchTags = append(mock.calls.FetchBranchTags, callInfo) + mock.lockFetchBranchTags.Unlock() + if mock.FetchBranchTagsFunc == nil { + var ( + tagsOut []tag.Tag + errOut error + ) + return tagsOut, errOut + } + return mock.FetchBranchTagsFunc(ctx, organizationID, documentID, branchID) +} + +// FetchBranchTagsCalls gets all the calls that were made to FetchBranchTags. +// Check the length with: +// +// len(mockedDB.FetchBranchTagsCalls()) +func (mock *DB) FetchBranchTagsCalls() []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID +} { + var calls []struct { + Ctx context.Context + OrganizationID string + DocumentID xid.ID + BranchID xid.ID + } + mock.lockFetchBranchTags.RLock() + calls = mock.calls.FetchBranchTags + mock.lockFetchBranchTags.RUnlock() + return calls +} + +// FetchDataSource calls FetchDataSourceFunc. +func (mock *DB) FetchDataSource(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { + callInfo := struct { + Ctx context.Context + ID xid.ID + OrganizationID string + }{ + Ctx: ctx, + ID: id, + OrganizationID: organizationID, + } + mock.lockFetchDataSource.Lock() + mock.calls.FetchDataSource = append(mock.calls.FetchDataSource, callInfo) + mock.lockFetchDataSource.Unlock() + if mock.FetchDataSourceFunc == nil { + var ( + dataSourceOut *datasource.DataSource + errOut error + ) + return dataSourceOut, errOut + } + return mock.FetchDataSourceFunc(ctx, id, organizationID) +} + +// FetchDataSourceCalls gets all the calls that were made to FetchDataSource. +// Check the length with: +// +// len(mockedDB.FetchDataSourceCalls()) +func (mock *DB) FetchDataSourceCalls() []struct { + Ctx context.Context + ID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + OrganizationID string + } + mock.lockFetchDataSource.RLock() + calls = mock.calls.FetchDataSource + mock.lockFetchDataSource.RUnlock() + return calls +} + +// FetchDataSources calls FetchDataSourcesFunc. +func (mock *DB) FetchDataSources(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { + callInfo := struct { + Ctx context.Context + OrganizationID string + }{ + Ctx: ctx, + OrganizationID: organizationID, + } + mock.lockFetchDataSources.Lock() + mock.calls.FetchDataSources = append(mock.calls.FetchDataSources, callInfo) + mock.lockFetchDataSources.Unlock() + if mock.FetchDataSourcesFunc == nil { + var ( + dataSourcesOut []datasource.DataSource + errOut error + ) + return dataSourcesOut, errOut + } + return mock.FetchDataSourcesFunc(ctx, organizationID) +} + +// FetchDataSourcesCalls gets all the calls that were made to FetchDataSources. +// Check the length with: +// +// len(mockedDB.FetchDataSourcesCalls()) +func (mock *DB) FetchDataSourcesCalls() []struct { + Ctx context.Context + OrganizationID string +} { + var calls []struct { + Ctx context.Context + OrganizationID string + } + mock.lockFetchDataSources.RLock() + calls = mock.calls.FetchDataSources + mock.lockFetchDataSources.RUnlock() + return calls +} + // FetchDocument calls FetchDocumentFunc. func (mock *DB) FetchDocument(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) { callInfo := struct { @@ -629,6 +957,94 @@ func (mock *DB) FetchDocumentByBranchIDCalls() []struct { return calls } +// FetchDocumentHook calls FetchDocumentHookFunc. +func (mock *DB) FetchDocumentHook(ctx context.Context, id xid.ID, organizationID string) (*hook.Hook, error) { + callInfo := struct { + Ctx context.Context + ID xid.ID + OrganizationID string + }{ + Ctx: ctx, + ID: id, + OrganizationID: organizationID, + } + mock.lockFetchDocumentHook.Lock() + mock.calls.FetchDocumentHook = append(mock.calls.FetchDocumentHook, callInfo) + mock.lockFetchDocumentHook.Unlock() + if mock.FetchDocumentHookFunc == nil { + var ( + hookOut *hook.Hook + errOut error + ) + return hookOut, errOut + } + return mock.FetchDocumentHookFunc(ctx, id, organizationID) +} + +// FetchDocumentHookCalls gets all the calls that were made to FetchDocumentHook. +// Check the length with: +// +// len(mockedDB.FetchDocumentHookCalls()) +func (mock *DB) FetchDocumentHookCalls() []struct { + Ctx context.Context + ID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + OrganizationID string + } + mock.lockFetchDocumentHook.RLock() + calls = mock.calls.FetchDocumentHook + mock.lockFetchDocumentHook.RUnlock() + return calls +} + +// FetchDocumentHooksByBranchID calls FetchDocumentHooksByBranchIDFunc. +func (mock *DB) FetchDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) ([]hook.Hook, error) { + callInfo := struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + }{ + Ctx: ctx, + BranchID: branchID, + OrganizationID: organizationID, + } + mock.lockFetchDocumentHooksByBranchID.Lock() + mock.calls.FetchDocumentHooksByBranchID = append(mock.calls.FetchDocumentHooksByBranchID, callInfo) + mock.lockFetchDocumentHooksByBranchID.Unlock() + if mock.FetchDocumentHooksByBranchIDFunc == nil { + var ( + hooksOut []hook.Hook + errOut error + ) + return hooksOut, errOut + } + return mock.FetchDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) +} + +// FetchDocumentHooksByBranchIDCalls gets all the calls that were made to FetchDocumentHooksByBranchID. +// Check the length with: +// +// len(mockedDB.FetchDocumentHooksByBranchIDCalls()) +func (mock *DB) FetchDocumentHooksByBranchIDCalls() []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + } + mock.lockFetchDocumentHooksByBranchID.RLock() + calls = mock.calls.FetchDocumentHooksByBranchID + mock.lockFetchDocumentHooksByBranchID.RUnlock() + return calls +} + // FetchDocumentTree calls FetchDocumentTreeFunc. func (mock *DB) FetchDocumentTree(ctx context.Context, organizationID string) (document.Summaries, error) { callInfo := struct { @@ -713,137 +1129,6 @@ func (mock *DB) FetchDocumentTreeByDocumentParentIDCalls() []struct { return calls } -// UpdateDocumentParentID calls UpdateDocumentParentIDFunc. -func (mock *DB) UpdateDocumentParentID(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error { - callInfo := struct { - Ctx context.Context - ID xid.ID - ParentID null.Value[xid.ID] - OrganizationID string - }{ - Ctx: ctx, - ID: id, - ParentID: parentID, - OrganizationID: organizationID, - } - mock.lockUpdateDocumentParentID.Lock() - mock.calls.UpdateDocumentParentID = append(mock.calls.UpdateDocumentParentID, callInfo) - mock.lockUpdateDocumentParentID.Unlock() - if mock.UpdateDocumentParentIDFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.UpdateDocumentParentIDFunc(ctx, id, parentID, organizationID) -} - -// UpdateDocumentParentIDCalls gets all the calls that were made to UpdateDocumentParentID. -// Check the length with: -// -// len(mockedDB.UpdateDocumentParentIDCalls()) -func (mock *DB) UpdateDocumentParentIDCalls() []struct { - Ctx context.Context - ID xid.ID - ParentID null.Value[xid.ID] - OrganizationID string -} { - var calls []struct { - Ctx context.Context - ID xid.ID - ParentID null.Value[xid.ID] - OrganizationID string - } - mock.lockUpdateDocumentParentID.RLock() - calls = mock.calls.UpdateDocumentParentID - mock.lockUpdateDocumentParentID.RUnlock() - return calls -} - -// FetchDataSource calls FetchDataSourceFunc. -func (mock *DB) FetchDataSource(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { - callInfo := struct { - Ctx context.Context - Id xid.ID - OrganizationID string - }{ - Ctx: ctx, - Id: id, - OrganizationID: organizationID, - } - mock.lockFetchDataSource.Lock() - mock.calls.FetchDataSource = append(mock.calls.FetchDataSource, callInfo) - mock.lockFetchDataSource.Unlock() - if mock.FetchDataSourceFunc == nil { - var ( - dataSourceOut *datasource.DataSource - errOut error - ) - return dataSourceOut, errOut - } - return mock.FetchDataSourceFunc(ctx, id, organizationID) -} - -// FetchDataSourceCalls gets all the calls that were made to FetchDataSource. -// Check the length with: -// -// len(mockedDB.FetchDataSourceCalls()) -func (mock *DB) FetchDataSourceCalls() []struct { - Ctx context.Context - Id xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - Id xid.ID - OrganizationID string - } - mock.lockFetchDataSource.RLock() - calls = mock.calls.FetchDataSource - mock.lockFetchDataSource.RUnlock() - return calls -} - -// FetchDataSources calls FetchDataSourcesFunc. -func (mock *DB) FetchDataSources(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { - callInfo := struct { - Ctx context.Context - OrganizationID string - }{ - Ctx: ctx, - OrganizationID: organizationID, - } - mock.lockFetchDataSources.Lock() - mock.calls.FetchDataSources = append(mock.calls.FetchDataSources, callInfo) - mock.lockFetchDataSources.Unlock() - if mock.FetchDataSourcesFunc == nil { - var ( - dataSourcesOut []datasource.DataSource - errOut error - ) - return dataSourcesOut, errOut - } - return mock.FetchDataSourcesFunc(ctx, organizationID) -} - -// FetchDataSourcesCalls gets all the calls that were made to FetchDataSources. -// Check the length with: -// -// len(mockedDB.FetchDataSourcesCalls()) -func (mock *DB) FetchDataSourcesCalls() []struct { - Ctx context.Context - OrganizationID string -} { - var calls []struct { - Ctx context.Context - OrganizationID string - } - mock.lockFetchDataSources.RLock() - calls = mock.calls.FetchDataSources - mock.lockFetchDataSources.RUnlock() - return calls -} - // FetchTagTree calls FetchTagTreeFunc. func (mock *DB) FetchTagTree(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) { callInfo := struct { @@ -888,51 +1173,42 @@ func (mock *DB) FetchTagTreeCalls() []struct { return calls } -// FetchBranchTags calls FetchBranchTagsFunc. -func (mock *DB) FetchBranchTags(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]tag.Tag, error) { +// InsertDocumentHook calls InsertDocumentHookFunc. +func (mock *DB) InsertDocumentHook(ctx context.Context, hk hook.Hook) error { callInfo := struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID + Ctx context.Context + Hk hook.Hook }{ - Ctx: ctx, - OrganizationID: organizationID, - DocumentID: documentID, - BranchID: branchID, + Ctx: ctx, + Hk: hk, } - mock.lockFetchBranchTags.Lock() - mock.calls.FetchBranchTags = append(mock.calls.FetchBranchTags, callInfo) - mock.lockFetchBranchTags.Unlock() - if mock.FetchBranchTagsFunc == nil { + mock.lockInsertDocumentHook.Lock() + mock.calls.InsertDocumentHook = append(mock.calls.InsertDocumentHook, callInfo) + mock.lockInsertDocumentHook.Unlock() + if mock.InsertDocumentHookFunc == nil { var ( - tagsOut []tag.Tag - errOut error + errOut error ) - return tagsOut, errOut + return errOut } - return mock.FetchBranchTagsFunc(ctx, organizationID, documentID, branchID) + return mock.InsertDocumentHookFunc(ctx, hk) } -// FetchBranchTagsCalls gets all the calls that were made to FetchBranchTags. +// InsertDocumentHookCalls gets all the calls that were made to InsertDocumentHook. // Check the length with: // -// len(mockedDB.FetchBranchTagsCalls()) -func (mock *DB) FetchBranchTagsCalls() []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID +// len(mockedDB.InsertDocumentHookCalls()) +func (mock *DB) InsertDocumentHookCalls() []struct { + Ctx context.Context + Hk hook.Hook } { var calls []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID + Ctx context.Context + Hk hook.Hook } - mock.lockFetchBranchTags.RLock() - calls = mock.calls.FetchBranchTags - mock.lockFetchBranchTags.RUnlock() + mock.lockInsertDocumentHook.RLock() + calls = mock.calls.InsertDocumentHook + mock.lockInsertDocumentHook.RUnlock() return calls } @@ -975,147 +1251,6 @@ func (mock *DB) InsertTagCalls() []struct { return calls } -// UpdateTag calls UpdateTagFunc. -func (mock *DB) UpdateTag(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error { - callInfo := struct { - Ctx context.Context - OrganizationID string - ID xid.ID - Inp tag.UpdateInput - }{ - Ctx: ctx, - OrganizationID: organizationID, - ID: id, - Inp: inp, - } - mock.lockUpdateTag.Lock() - mock.calls.UpdateTag = append(mock.calls.UpdateTag, callInfo) - mock.lockUpdateTag.Unlock() - if mock.UpdateTagFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.UpdateTagFunc(ctx, organizationID, id, inp) -} - -// UpdateTagCalls gets all the calls that were made to UpdateTag. -// Check the length with: -// -// len(mockedDB.UpdateTagCalls()) -func (mock *DB) UpdateTagCalls() []struct { - Ctx context.Context - OrganizationID string - ID xid.ID - Inp tag.UpdateInput -} { - var calls []struct { - Ctx context.Context - OrganizationID string - ID xid.ID - Inp tag.UpdateInput - } - mock.lockUpdateTag.RLock() - calls = mock.calls.UpdateTag - mock.lockUpdateTag.RUnlock() - return calls -} - -// DeleteTag calls DeleteTagFunc. -func (mock *DB) DeleteTag(ctx context.Context, id xid.ID, organizationID string) error { - callInfo := struct { - Ctx context.Context - ID xid.ID - OrganizationID string - }{ - Ctx: ctx, - ID: id, - OrganizationID: organizationID, - } - mock.lockDeleteTag.Lock() - mock.calls.DeleteTag = append(mock.calls.DeleteTag, callInfo) - mock.lockDeleteTag.Unlock() - if mock.DeleteTagFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.DeleteTagFunc(ctx, id, organizationID) -} - -// DeleteTagCalls gets all the calls that were made to DeleteTag. -// Check the length with: -// -// len(mockedDB.DeleteTagCalls()) -func (mock *DB) DeleteTagCalls() []struct { - Ctx context.Context - ID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - ID xid.ID - OrganizationID string - } - mock.lockDeleteTag.RLock() - calls = mock.calls.DeleteTag - mock.lockDeleteTag.RUnlock() - return calls -} - -// AssignBranchTag calls AssignBranchTagFunc. -func (mock *DB) AssignBranchTag(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { - callInfo := struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID - TagID xid.ID - }{ - Ctx: ctx, - OrganizationID: organizationID, - DocumentID: documentID, - BranchID: branchID, - TagID: tagID, - } - mock.lockAssignBranchTag.Lock() - mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) - mock.lockAssignBranchTag.Unlock() - if mock.AssignBranchTagFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) -} - -// AssignBranchTagCalls gets all the calls that were made to AssignBranchTag. -// Check the length with: -// -// len(mockedDB.AssignBranchTagCalls()) -func (mock *DB) AssignBranchTagCalls() []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID - TagID xid.ID -} { - var calls []struct { - Ctx context.Context - OrganizationID string - DocumentID xid.ID - BranchID xid.ID - TagID xid.ID - } - mock.lockAssignBranchTag.RLock() - calls = mock.calls.AssignBranchTag - mock.lockAssignBranchTag.RUnlock() - return calls -} - // UnassignBranchTag calls UnassignBranchTagFunc. func (mock *DB) UnassignBranchTag(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { callInfo := struct { @@ -1167,6 +1302,139 @@ func (mock *DB) UnassignBranchTagCalls() []struct { return calls } +// UpdateDocumentHook calls UpdateDocumentHookFunc. +func (mock *DB) UpdateDocumentHook(ctx context.Context, hk hook.Hook) error { + callInfo := struct { + Ctx context.Context + Hk hook.Hook + }{ + Ctx: ctx, + Hk: hk, + } + mock.lockUpdateDocumentHook.Lock() + mock.calls.UpdateDocumentHook = append(mock.calls.UpdateDocumentHook, callInfo) + mock.lockUpdateDocumentHook.Unlock() + if mock.UpdateDocumentHookFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.UpdateDocumentHookFunc(ctx, hk) +} + +// UpdateDocumentHookCalls gets all the calls that were made to UpdateDocumentHook. +// Check the length with: +// +// len(mockedDB.UpdateDocumentHookCalls()) +func (mock *DB) UpdateDocumentHookCalls() []struct { + Ctx context.Context + Hk hook.Hook +} { + var calls []struct { + Ctx context.Context + Hk hook.Hook + } + mock.lockUpdateDocumentHook.RLock() + calls = mock.calls.UpdateDocumentHook + mock.lockUpdateDocumentHook.RUnlock() + return calls +} + +// UpdateDocumentParentID calls UpdateDocumentParentIDFunc. +func (mock *DB) UpdateDocumentParentID(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error { + callInfo := struct { + Ctx context.Context + ID xid.ID + ParentID null.Value[xid.ID] + OrganizationID string + }{ + Ctx: ctx, + ID: id, + ParentID: parentID, + OrganizationID: organizationID, + } + mock.lockUpdateDocumentParentID.Lock() + mock.calls.UpdateDocumentParentID = append(mock.calls.UpdateDocumentParentID, callInfo) + mock.lockUpdateDocumentParentID.Unlock() + if mock.UpdateDocumentParentIDFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.UpdateDocumentParentIDFunc(ctx, id, parentID, organizationID) +} + +// UpdateDocumentParentIDCalls gets all the calls that were made to UpdateDocumentParentID. +// Check the length with: +// +// len(mockedDB.UpdateDocumentParentIDCalls()) +func (mock *DB) UpdateDocumentParentIDCalls() []struct { + Ctx context.Context + ID xid.ID + ParentID null.Value[xid.ID] + OrganizationID string +} { + var calls []struct { + Ctx context.Context + ID xid.ID + ParentID null.Value[xid.ID] + OrganizationID string + } + mock.lockUpdateDocumentParentID.RLock() + calls = mock.calls.UpdateDocumentParentID + mock.lockUpdateDocumentParentID.RUnlock() + return calls +} + +// UpdateTag calls UpdateTagFunc. +func (mock *DB) UpdateTag(ctx context.Context, organizationID string, id xid.ID, inp tag.UpdateInput) error { + callInfo := struct { + Ctx context.Context + OrganizationID string + ID xid.ID + Inp tag.UpdateInput + }{ + Ctx: ctx, + OrganizationID: organizationID, + ID: id, + Inp: inp, + } + mock.lockUpdateTag.Lock() + mock.calls.UpdateTag = append(mock.calls.UpdateTag, callInfo) + mock.lockUpdateTag.Unlock() + if mock.UpdateTagFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.UpdateTagFunc(ctx, organizationID, id, inp) +} + +// UpdateTagCalls gets all the calls that were made to UpdateTag. +// Check the length with: +// +// len(mockedDB.UpdateTagCalls()) +func (mock *DB) UpdateTagCalls() []struct { + Ctx context.Context + OrganizationID string + ID xid.ID + Inp tag.UpdateInput +} { + var calls []struct { + Ctx context.Context + OrganizationID string + ID xid.ID + Inp tag.UpdateInput + } + mock.lockUpdateTag.RLock() + calls = mock.calls.UpdateTag + mock.lockUpdateTag.RUnlock() + return calls +} + // UpdateTagTree calls UpdateTagTreeFunc. func (mock *DB) UpdateTagTree(ctx context.Context, tree tag.Summaries, organizationID string) error { callInfo := struct { @@ -1209,208 +1477,3 @@ func (mock *DB) UpdateTagTreeCalls() []struct { mock.lockUpdateTagTree.RUnlock() return calls } - -// FetchDocumentHooksByBranchID calls FetchDocumentHooksByBranchIDFunc. -func (mock *DB) FetchDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) ([]hookCore.Hook, error) { - callInfo := struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - }{ - Ctx: ctx, - BranchID: branchID, - OrganizationID: organizationID, - } - mock.lockFetchDocumentHooksByBranchID.Lock() - mock.calls.FetchDocumentHooksByBranchID = append(mock.calls.FetchDocumentHooksByBranchID, callInfo) - mock.lockFetchDocumentHooksByBranchID.Unlock() - if mock.FetchDocumentHooksByBranchIDFunc == nil { - var ( - hooksOut []hookCore.Hook - errOut error - ) - return hooksOut, errOut - } - return mock.FetchDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) -} - -// FetchDocumentHooksByBranchIDCalls gets all the calls that were made to FetchDocumentHooksByBranchID. -// Check the length with: -// -// len(mockedDB.FetchDocumentHooksByBranchIDCalls()) -func (mock *DB) FetchDocumentHooksByBranchIDCalls() []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - } - mock.lockFetchDocumentHooksByBranchID.RLock() - calls = mock.calls.FetchDocumentHooksByBranchID - mock.lockFetchDocumentHooksByBranchID.RUnlock() - return calls -} - -// FetchDocumentHook calls FetchDocumentHookFunc. -func (mock *DB) FetchDocumentHook(ctx context.Context, id xid.ID, organizationID string) (*hookCore.Hook, error) { - callInfo := struct { - Ctx context.Context - ID xid.ID - OrganizationID string - }{ - Ctx: ctx, - ID: id, - OrganizationID: organizationID, - } - mock.lockFetchDocumentHook.Lock() - mock.calls.FetchDocumentHook = append(mock.calls.FetchDocumentHook, callInfo) - mock.lockFetchDocumentHook.Unlock() - if mock.FetchDocumentHookFunc == nil { - var ( - hookOut *hookCore.Hook - errOut error - ) - return hookOut, errOut - } - return mock.FetchDocumentHookFunc(ctx, id, organizationID) -} - -// FetchDocumentHookCalls gets all the calls that were made to FetchDocumentHook. -// Check the length with: -// -// len(mockedDB.FetchDocumentHookCalls()) -func (mock *DB) FetchDocumentHookCalls() []struct { - Ctx context.Context - ID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - ID xid.ID - OrganizationID string - } - mock.lockFetchDocumentHook.RLock() - calls = mock.calls.FetchDocumentHook - mock.lockFetchDocumentHook.RUnlock() - return calls -} - -// InsertDocumentHook calls InsertDocumentHookFunc. -func (mock *DB) InsertDocumentHook(ctx context.Context, hk hookCore.Hook) error { - callInfo := struct { - Ctx context.Context - Hk hookCore.Hook - }{ - Ctx: ctx, - Hk: hk, - } - mock.lockInsertDocumentHook.Lock() - mock.calls.InsertDocumentHook = append(mock.calls.InsertDocumentHook, callInfo) - mock.lockInsertDocumentHook.Unlock() - if mock.InsertDocumentHookFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.InsertDocumentHookFunc(ctx, hk) -} - -// InsertDocumentHookCalls gets all the calls that were made to InsertDocumentHook. -// Check the length with: -// -// len(mockedDB.InsertDocumentHookCalls()) -func (mock *DB) InsertDocumentHookCalls() []struct { - Ctx context.Context - Hk hookCore.Hook -} { - var calls []struct { - Ctx context.Context - Hk hookCore.Hook - } - mock.lockInsertDocumentHook.RLock() - calls = mock.calls.InsertDocumentHook - mock.lockInsertDocumentHook.RUnlock() - return calls -} - -// UpdateDocumentHook calls UpdateDocumentHookFunc. -func (mock *DB) UpdateDocumentHook(ctx context.Context, hk hookCore.Hook) error { - callInfo := struct { - Ctx context.Context - Hk hookCore.Hook - }{ - Ctx: ctx, - Hk: hk, - } - mock.lockUpdateDocumentHook.Lock() - mock.calls.UpdateDocumentHook = append(mock.calls.UpdateDocumentHook, callInfo) - mock.lockUpdateDocumentHook.Unlock() - if mock.UpdateDocumentHookFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.UpdateDocumentHookFunc(ctx, hk) -} - -// UpdateDocumentHookCalls gets all the calls that were made to UpdateDocumentHook. -// Check the length with: -// -// len(mockedDB.UpdateDocumentHookCalls()) -func (mock *DB) UpdateDocumentHookCalls() []struct { - Ctx context.Context - Hk hookCore.Hook -} { - var calls []struct { - Ctx context.Context - Hk hookCore.Hook - } - mock.lockUpdateDocumentHook.RLock() - calls = mock.calls.UpdateDocumentHook - mock.lockUpdateDocumentHook.RUnlock() - return calls -} - -// DeleteDocumentHook calls DeleteDocumentHookFunc. -func (mock *DB) DeleteDocumentHook(ctx context.Context, id xid.ID) error { - callInfo := struct { - Ctx context.Context - ID xid.ID - }{ - Ctx: ctx, - ID: id, - } - mock.lockDeleteDocumentHook.Lock() - mock.calls.DeleteDocumentHook = append(mock.calls.DeleteDocumentHook, callInfo) - mock.lockDeleteDocumentHook.Unlock() - if mock.DeleteDocumentHookFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.DeleteDocumentHookFunc(ctx, id) -} - -// DeleteDocumentHookCalls gets all the calls that were made to DeleteDocumentHook. -// Check the length with: -// -// len(mockedDB.DeleteDocumentHookCalls()) -func (mock *DB) DeleteDocumentHookCalls() []struct { - Ctx context.Context - ID xid.ID -} { - var calls []struct { - Ctx context.Context - ID xid.ID - } - mock.lockDeleteDocumentHook.RLock() - calls = mock.calls.DeleteDocumentHook - mock.lockDeleteDocumentHook.RUnlock() - return calls -} diff --git a/server/core/internal/assistant/tools/_mock/searcher.go b/server/core/internal/assistant/tools/_mock/searcher.go index f3cf72fb..495421c1 100644 --- a/server/core/internal/assistant/tools/_mock/searcher.go +++ b/server/core/internal/assistant/tools/_mock/searcher.go @@ -5,9 +5,10 @@ package mock import ( "context" + "sync" + "github.com/oxynote/oxynote/server/core/internal/assistant/tools" "github.com/oxynote/oxynote/server/core/internal/search" - "sync" ) // Ensure, that Searcher does implement tools.Searcher. @@ -18,14 +19,14 @@ var _ tools.Searcher = &Searcher{} // // func TestSomethingThatUsesSearcher(t *testing.T) { // -// // make and configure a mocked Searcher +// // make and configure a mocked tools.Searcher // mockedSearcher := &Searcher{ // SearchDocumentBlocksFunc: func(ctx context.Context, organizationID string, query string, limit int) ([]search.Block, error) { // panic("mock out the SearchDocumentBlocks method") // }, // } // -// // use mockedSearcher in code that requires Searcher +// // use mockedSearcher in code that requires tools.Searcher // // and then make assertions. // // } @@ -68,10 +69,10 @@ func (mock *Searcher) SearchDocumentBlocks(ctx context.Context, organizationID s mock.lockSearchDocumentBlocks.Unlock() if mock.SearchDocumentBlocksFunc == nil { var ( - out0 []search.Block - errOut error + blocksOut []search.Block + errOut error ) - return out0, errOut + return blocksOut, errOut } return mock.SearchDocumentBlocksFunc(ctx, organizationID, query, limit) } diff --git a/server/core/internal/assistant/tools/block.go b/server/core/internal/assistant/tools/block.go index 517bd1a4..4153c8e7 100644 --- a/server/core/internal/assistant/tools/block.go +++ b/server/core/internal/assistant/tools/block.go @@ -313,15 +313,11 @@ func (insertBlock) Execute(inp Input) (string, error) { return "", fmt.Errorf("insert_block: %w", err) } - if err := inp.CheckDataSources(in.Block.CollectAttributeValues(document.AttrDataSourceID)); err != nil { - return "", fmt.Errorf("insert_block: %w", err) - } - // uids are resolved at expansion, so expanding here rather than at // wire time is what lets the tool report what it wrote without // reading the document back, which the debounced persist would not // reliably show yet. - expanded, err := block.Expand(in.Block) + expanded, err := sanitizeBlock(inp, in.Block, document.Block{}) if err != nil { return "", fmt.Errorf("insert_block: %w", err) } @@ -462,11 +458,20 @@ func (replaceBlock) Execute(inp Input) (string, error) { return "", fmt.Errorf("replace_block: %w", err) } - if err := inp.CheckDataSources(in.Block.CollectAttributeValues(document.AttrDataSourceID)); err != nil { + content, err := inp.FetchDocumentContent(in.DocumentID, in.BranchID) + if err != nil { return "", fmt.Errorf("replace_block: %w", err) } - expanded, err := block.Expand(in.Block) + // an unknown uid leaves stored empty, so no flag is kept. ApplyEdit + // reports the unknown uid. + var stored document.Block + + if b, ok := content.Content.FindByUID(in.BlockUID); ok { + stored = b + } + + expanded, err := sanitizeBlock(inp, in.Block, stored) if err != nil { return "", fmt.Errorf("replace_block: %w", err) } @@ -715,15 +720,6 @@ func (updateBlockAttrs) Execute(inp Input) (string, error) { return "", err } - // the payload names attributes, not a block type, so a metric's - // data source arrives here on its own rather than inside a block - // the walk could find it in. - if id, ok := in.Attrs[document.AttrDataSourceID].(string); ok && id != "" { - if err := inp.CheckDataSources([]string{id}); err != nil { - return "", fmt.Errorf("update_block_attrs: %w", err) - } - } - if err := inp.ValidateAttrUpdate(in.DocumentID, in.BranchID, in.BlockUID, in.Attrs); err != nil { return "", fmt.Errorf("update_block_attrs: %w", err) } @@ -733,6 +729,10 @@ func (updateBlockAttrs) Execute(inp Input) (string, error) { return "", fmt.Errorf("update_block_attrs: %w", err) } + if err := sanitizeBlockAttrs(inp, in.Attrs, b); err != nil { + return "", fmt.Errorf("update_block_attrs: %w", err) + } + if err := inp.ApplyEdit(in.DocumentID, in.BranchID, []edit.Operation{edit.UpdateAttrs(in.BlockUID, in.Attrs)}); err != nil { return "", err } @@ -998,3 +998,41 @@ func (moveBlock) Execute(inp Input) (string, error) { return result(blockWriteResult{Blocks: blockRows(b)}) } + +// sanitizeBlock checks a block before a write and expands it. stored is +// the block being replaced, or empty for an insert. A metric that stored +// already holds keeps its simulation flag. +func sanitizeBlock(inp Input, b block.Block, stored document.Block) (document.Block, error) { + if err := inp.CheckDataSources(b.CollectAttributeValues(document.AttrDataSourceID)); err != nil { + return document.Block{}, err + } + + expanded, err := block.Expand(b) + if err != nil { + return document.Block{}, err + } + + block.KeepSimulation(expanded, stored) + + return expanded, nil +} + +// sanitizeBlockAttrs checks an attribute update by the type of the +// stored block. For a metric it checks the data source and sets the +// simulation flag. It writes to attrs. +func sanitizeBlockAttrs(inp Input, attrs map[string]any, stored document.Block) error { + if stored.Type != document.BlockNodeMetricBlock { + return nil + } + + // an empty data source means unset, so there is nothing to check. + if id, ok := attrs[document.AttrDataSourceID].(string); ok && id != "" { + if err := inp.CheckDataSources([]string{id}); err != nil { + return err + } + } + + block.DeriveSimulation(attrs, stored.Attrs) + + return nil +} diff --git a/server/core/internal/assistant/tools/block_test.go b/server/core/internal/assistant/tools/block_test.go index 68536d5c..09222dd7 100644 --- a/server/core/internal/assistant/tools/block_test.go +++ b/server/core/internal/assistant/tools/block_test.go @@ -2,6 +2,7 @@ package tools import ( "context" + "encoding/json" "testing" "github.com/oxynote/oxynote/server/core/internal/assistant/block" @@ -26,10 +27,13 @@ const _stubContentUID = "a" // for the cases that need a block with attributes of its own. const _stubHeadingUID = "h" +// _stubMetricUID is the uid of the metric stubSimulationDB answers with. +const _stubMetricUID = "m" + // stubContentDB answers content reads with a single paragraph the // placement checks can find. func stubContentDB(err error) *DBMock { - root := document.RootBlock{ + return stubRootDB(document.RootBlock{ Content: []document.Block{ { Type: document.BlockNodeParagraph, @@ -42,8 +46,35 @@ func stubContentDB(err error) *DBMock { Attrs: document.Attributes{document.AttrUID: _stubHeadingUID, document.AttrLevel: 1}, }, }, - } + }, err) +} +// stubSimulationDB answers content reads with one metric whose data has +// arrived: it still names its preset and its simulation is switched off. +func stubSimulationDB() *DBMock { + return stubRootDB(document.RootBlock{ + Content: []document.Block{ + { + Type: document.BlockNodeMetricGrid, + Attrs: document.Attributes{document.AttrUID: "g"}, + Content: []document.Block{ + { + Type: document.BlockNodeMetricBlock, + Attrs: document.Attributes{ + document.AttrUID: _stubMetricUID, + document.AttrSimulationPreset: "cpu_usage", + document.AttrSimulationActive: false, + }, + }, + }, + }, + }, + }, nil) +} + +// stubRootDB answers content reads with the given tree. err makes the +// branch fetch fail. +func stubRootDB(root document.RootBlock, err error) *DBMock { db := stubDocumentDB() fetch := db.FetchDocumentFunc fetchByBranch := db.FetchDocumentByBranchIDFunc @@ -98,7 +129,11 @@ func metricBlockArgs(dataSourceID string) string { // stubMetricDB answers content reads and resolves exactly one data // source, so only the id under test decides a metric write's outcome. func stubMetricDB() *DBMock { - db := stubContentDB(nil) + return stubDataSource(stubContentDB(nil)) +} + +// stubDataSource makes db resolve exactly one data source. +func stubDataSource(db *DBMock) *DBMock { db.FetchDataSourceFunc = func(_ context.Context, id xid.ID, orgID string) (*datasource.DataSource, error) { if id != _testDataSourceID || orgID != "org" { return nil, errutil.ErrNotFound @@ -120,7 +155,12 @@ type editCase struct { Runner *datasourceMock.Runner Args string Contains []string - Err error + + // Op is the single operation the write should send, as the realtime + // service receives it. Empty skips the check. + Op string + + Err error } // runEdit executes a block tool and asserts the shared outcome. @@ -153,6 +193,21 @@ func runEdit(t *testing.T, tl Tool, name Name, c editCase) { for _, want := range c.Contains { assert.Contains(t, res, want) } + + if c.Op == "" { + return + } + + require.Len(t, applier.ApplyCalls(), 1) + require.Len(t, applier.ApplyCalls()[0].Ops, 1) + + op, err := applier.ApplyCalls()[0].Ops[0]() + require.NoError(t, err) + + raw, err := json.Marshal(op) + require.NoError(t, err) + + assert.JSONEq(t, c.Op, string(raw)) } func Test_readBlockArgs_Validate(t *testing.T) { @@ -540,6 +595,22 @@ func Test_replaceBlock_Execute(t *testing.T) { `","block":` + metricBlockArgs(_unknownDataSourceID) + `}`, Err: assert.AnError, }, + // read_block shows a metric with its preset even after its data + // arrived. Re-sending it must not start the simulation again. + "A metric re-sent with its preset keeps its simulation switched off": { + DB: stubSimulationDB(), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + `","block":` + + `{"type":"metric","uid":"` + _stubMetricUID + `","attrs":{"title":"CPU","simulationPreset":"cpu_usage"}}}`, + Op: `{"kind":"replace","block_uid":"m","block":{"type":"metricBlock","attrs":` + + `{"uid":"m","title":"CPU","simulationPreset":"cpu_usage","simulationActive":false}}}`, + }, + "A metric re-sent with another preset simulates": { + DB: stubSimulationDB(), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + `","block":` + + `{"type":"metric","uid":"` + _stubMetricUID + `","attrs":{"simulationPreset":"error_rate"}}}`, + Op: `{"kind":"replace","block_uid":"m","block":{"type":"metricBlock","attrs":` + + `{"uid":"m","simulationPreset":"error_rate","simulationActive":true}}}`, + }, } for cn, c := range cc { @@ -757,21 +828,46 @@ func Test_updateBlockAttrs_Execute(t *testing.T) { // the payload names attributes, not a block type, so a metric's // data source arrives on its own rather than inside a block. "A data source the organisation owns": { - DB: stubMetricDB(), - Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"a","attrs":{"dataSourceId":"` + + DB: stubDataSource(stubSimulationDB()), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + `","attrs":{"dataSourceId":"` + _testDataSourceID.String() + `"}}`, }, "A data source it does not": { - DB: stubMetricDB(), - Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"a","attrs":{"dataSourceId":"` + + DB: stubDataSource(stubSimulationDB()), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + `","attrs":{"dataSourceId":"` + _unknownDataSourceID + `"}}`, Err: assert.AnError, }, // an empty data source is the editor's "unset", not a reference // to check, and no other attribute names one at all. "An empty data source is not looked up": { - DB: stubMetricDB(), - Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"a","attrs":{"dataSourceId":""}}`, + DB: stubDataSource(stubSimulationDB()), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + `","attrs":{"dataSourceId":""}}`, + }, + "A simulation flag the caller sent is dropped": { + DB: stubSimulationDB(), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + + `","attrs":{"title":"CPU","simulationActive":true}}`, + Op: `{"kind":"update_attrs","block_uid":"m","attrs":{"title":"CPU"}}`, + }, + "Another preset switches the simulation on": { + DB: stubSimulationDB(), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + + `","attrs":{"simulationPreset":"error_rate"}}`, + Op: `{"kind":"update_attrs","block_uid":"m","attrs":{"simulationPreset":"error_rate","simulationActive":true}}`, + }, + "A null preset switches the simulation off": { + DB: stubSimulationDB(), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"` + _stubMetricUID + + `","attrs":{"simulationPreset":null}}`, + Op: `{"kind":"update_attrs","block_uid":"m","attrs":{"simulationPreset":null,"simulationActive":false}}`, + }, + // only metric blocks have the flag, so any other block is sent + // unchanged. + "A block that is not a metric is sent as given": { + DB: stubContentDB(nil), + Args: `{` + targetArgs(_stubMainBranchID) + `,"block_uid":"h","attrs":{"level":2}}`, + Op: `{"kind":"update_attrs","block_uid":"h","attrs":{"level":2}}`, }, } @@ -1000,6 +1096,144 @@ func Test_moveBlock_Execute(t *testing.T) { } } +func Test_sanitizeBlock(t *testing.T) { + t.Parallel() + + metric := func(attrs document.Attributes) block.Block { + return block.Block{Type: block.BlockMetric, UID: _stubMetricUID, Attrs: attrs} + } + + cc := map[string]struct { + Block block.Block + Stored document.Block + Result document.Attributes + Err error + }{ + "Error returned by inp.CheckDataSources": { + Block: metric(document.Attributes{document.AttrDataSourceID: _unknownDataSourceID}), + Err: assert.AnError, + }, + "Error returned by block.Expand": { + Block: block.Block{Type: "nope"}, + Err: assert.AnError, + }, + "A new metric naming a preset simulates": { + Block: metric(document.Attributes{document.AttrSimulationPreset: "cpu_usage"}), + Result: document.Attributes{ + document.AttrUID: _stubMetricUID, + document.AttrSimulationPreset: "cpu_usage", + document.AttrSimulationActive: true, + }, + }, + "A stored metric keeps its simulation flag": { + Block: metric(document.Attributes{document.AttrSimulationPreset: "cpu_usage"}), + Stored: document.Block{ + Type: document.BlockNodeMetricBlock, + Attrs: document.Attributes{ + document.AttrUID: _stubMetricUID, + document.AttrSimulationPreset: "cpu_usage", + document.AttrSimulationActive: false, + }, + }, + Result: document.Attributes{ + document.AttrUID: _stubMetricUID, + document.AttrSimulationPreset: "cpu_usage", + document.AttrSimulationActive: false, + }, + }, + } + + for cn, c := range cc { + t.Run(cn, func(t *testing.T) { + t.Parallel() + + inp := testInput(testDeps(stubMetricDB(), nil, nil), NameReplaceBlock, `{}`) + + res, err := sanitizeBlock(inp, c.Block, c.Stored) + testutil.AssertEqualError(t, c.Err, err) + + if err != nil { + return + } + + assert.Equal(t, document.BlockNodeMetricBlock, res.Type) + assert.Equal(t, c.Result, res.Attrs) + }) + } +} + +func Test_sanitizeBlockAttrs(t *testing.T) { + t.Parallel() + + stored := document.Block{ + Type: document.BlockNodeMetricBlock, + Attrs: document.Attributes{ + document.AttrUID: _stubMetricUID, + document.AttrSimulationPreset: "cpu_usage", + document.AttrSimulationActive: false, + }, + } + + cc := map[string]struct { + Attrs map[string]any + Stored document.Block + Result map[string]any + Err error + }{ + "Error returned by inp.CheckDataSources": { + Attrs: map[string]any{document.AttrDataSourceID: _unknownDataSourceID}, + Stored: stored, + Err: assert.AnError, + }, + "A block that is not a metric is left as given": { + Attrs: map[string]any{ + document.AttrDataSourceID: _unknownDataSourceID, + document.AttrSimulationActive: true, + }, + Stored: document.Block{Type: document.BlockNodeParagraph}, + Result: map[string]any{ + document.AttrDataSourceID: _unknownDataSourceID, + document.AttrSimulationActive: true, + }, + }, + "An empty data source is not looked up": { + Attrs: map[string]any{document.AttrDataSourceID: ""}, + Stored: stored, + Result: map[string]any{document.AttrDataSourceID: ""}, + }, + "A metric has its simulation flag derived": { + Attrs: map[string]any{ + document.AttrDataSourceID: _testDataSourceID.String(), + document.AttrSimulationPreset: "error_rate", + document.AttrSimulationActive: false, + }, + Stored: stored, + Result: map[string]any{ + document.AttrDataSourceID: _testDataSourceID.String(), + document.AttrSimulationPreset: "error_rate", + document.AttrSimulationActive: true, + }, + }, + } + + for cn, c := range cc { + t.Run(cn, func(t *testing.T) { + t.Parallel() + + inp := testInput(testDeps(stubMetricDB(), nil, nil), NameUpdateBlockAttrs, `{}`) + + err := sanitizeBlockAttrs(inp, c.Attrs, c.Stored) + testutil.AssertEqualError(t, c.Err, err) + + if err != nil { + return + } + + assert.Equal(t, c.Result, c.Attrs) + }) + } +} + func Test_docTarget_validate(t *testing.T) { t.Parallel() diff --git a/server/core/internal/datasource/0mock_status_store_test.go b/server/core/internal/datasource/0mock_status_store_test.go index 1d94bf49..ff1d7bf5 100644 --- a/server/core/internal/datasource/0mock_status_store_test.go +++ b/server/core/internal/datasource/0mock_status_store_test.go @@ -40,8 +40,8 @@ type StatusStoreMock struct { UpdateDataSourceStatus []struct { // Ctx is the ctx argument value. Ctx context.Context - // Id is the id argument value. - Id xid.ID + // ID is the id argument value. + ID xid.ID // OrganizationID is the organizationID argument value. OrganizationID string // Status is the status argument value. @@ -55,12 +55,12 @@ type StatusStoreMock struct { func (mock *StatusStoreMock) UpdateDataSourceStatus(ctx context.Context, id xid.ID, organizationID string, status processor.ConnectionStatus) error { callInfo := struct { Ctx context.Context - Id xid.ID + ID xid.ID OrganizationID string Status processor.ConnectionStatus }{ Ctx: ctx, - Id: id, + ID: id, OrganizationID: organizationID, Status: status, } @@ -82,13 +82,13 @@ func (mock *StatusStoreMock) UpdateDataSourceStatus(ctx context.Context, id xid. // len(mockedStatusStore.UpdateDataSourceStatusCalls()) func (mock *StatusStoreMock) UpdateDataSourceStatusCalls() []struct { Ctx context.Context - Id xid.ID + ID xid.ID OrganizationID string Status processor.ConnectionStatus } { var calls []struct { Ctx context.Context - Id xid.ID + ID xid.ID OrganizationID string Status processor.ConnectionStatus } diff --git a/server/core/internal/datasource/_mock/mysql.go b/server/core/internal/datasource/_mock/mysql.go index 9067cb57..6b46ef3a 100644 --- a/server/core/internal/datasource/_mock/mysql.go +++ b/server/core/internal/datasource/_mock/mysql.go @@ -17,62 +17,48 @@ var _ datasource.MySQL = &MySQL{} // MySQL is a mock implementation of datasource.MySQL. // -// func TestSomethingThatUsesdatasource.MySQL(t *testing.T) { +// func TestSomethingThatUsesMySQL(t *testing.T) { // // // make and configure a mocked datasource.MySQL -// mockeddatasource.MySQL := &MySQL{ -// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { -// panic("mock out the TestConnection method") -// }, +// mockedMySQL := &MySQL{ // MetadataFunc: func(ctx context.Context) (*processor.SQLMetadataResult, error) { // panic("mock out the Metadata method") // }, -// QueryLabelsFunc: func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { -// panic("mock out the QueryLabels method") -// }, // QueryFunc: func(ctx context.Context, q string, tr processor.TimeRange) (*processor.MySQLQueryResult, error) { // panic("mock out the Query method") // }, +// QueryLabelsFunc: func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { +// panic("mock out the QueryLabels method") +// }, +// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { +// panic("mock out the TestConnection method") +// }, // } // -// // use mockeddatasource.MySQL in code that requires datasource.MySQL +// // use mockedMySQL in code that requires datasource.MySQL // // and then make assertions. // // } type MySQL struct { - // TestConnectionFunc mocks the TestConnection method. - TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) - // MetadataFunc mocks the Metadata method. MetadataFunc func(ctx context.Context) (*processor.SQLMetadataResult, error) - // QueryLabelsFunc mocks the QueryLabels method. - QueryLabelsFunc func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) - // QueryFunc mocks the Query method. QueryFunc func(ctx context.Context, q string, tr processor.TimeRange) (*processor.MySQLQueryResult, error) + // QueryLabelsFunc mocks the QueryLabels method. + QueryLabelsFunc func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) + + // TestConnectionFunc mocks the TestConnection method. + TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) + // calls tracks calls to the methods. calls struct { - // TestConnection holds details about calls to the TestConnection method. - TestConnection []struct { - // Ctx is the ctx argument value. - Ctx context.Context - } // Metadata holds details about calls to the Metadata method. Metadata []struct { // Ctx is the ctx argument value. Ctx context.Context } - // QueryLabels holds details about calls to the QueryLabels method. - QueryLabels []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Q is the q argument value. - Q string - // Tr is the tr argument value. - Tr processor.TimeRange - } // Query holds details about calls to the Query method. Query []struct { // Ctx is the ctx argument value. @@ -82,47 +68,25 @@ type MySQL struct { // Tr is the tr argument value. Tr processor.TimeRange } + // QueryLabels holds details about calls to the QueryLabels method. + QueryLabels []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Q is the q argument value. + Q string + // Tr is the tr argument value. + Tr processor.TimeRange + } + // TestConnection holds details about calls to the TestConnection method. + TestConnection []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } } - lockTestConnection sync.RWMutex lockMetadata sync.RWMutex - lockQueryLabels sync.RWMutex lockQuery sync.RWMutex -} - -// TestConnection calls TestConnectionFunc. -func (mock *MySQL) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { - callInfo := struct { - Ctx context.Context - }{ - Ctx: ctx, - } - mock.lockTestConnection.Lock() - mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) - mock.lockTestConnection.Unlock() - if mock.TestConnectionFunc == nil { - var ( - connectionStatusOut processor.ConnectionStatus - errOut error - ) - return connectionStatusOut, errOut - } - return mock.TestConnectionFunc(ctx) -} - -// TestConnectionCalls gets all the calls that were made to TestConnection. -// Check the length with: -// -// len(mockeddatasource.MySQL.TestConnectionCalls()) -func (mock *MySQL) TestConnectionCalls() []struct { - Ctx context.Context -} { - var calls []struct { - Ctx context.Context - } - mock.lockTestConnection.RLock() - calls = mock.calls.TestConnection - mock.lockTestConnection.RUnlock() - return calls + lockQueryLabels sync.RWMutex + lockTestConnection sync.RWMutex } // Metadata calls MetadataFunc. @@ -148,7 +112,7 @@ func (mock *MySQL) Metadata(ctx context.Context) (*processor.SQLMetadataResult, // MetadataCalls gets all the calls that were made to Metadata. // Check the length with: // -// len(mockeddatasource.MySQL.MetadataCalls()) +// len(mockedMySQL.MetadataCalls()) func (mock *MySQL) MetadataCalls() []struct { Ctx context.Context } { @@ -161,50 +125,6 @@ func (mock *MySQL) MetadataCalls() []struct { return calls } -// QueryLabels calls QueryLabelsFunc. -func (mock *MySQL) QueryLabels(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { - callInfo := struct { - Ctx context.Context - Q string - Tr processor.TimeRange - }{ - Ctx: ctx, - Q: q, - Tr: tr, - } - mock.lockQueryLabels.Lock() - mock.calls.QueryLabels = append(mock.calls.QueryLabels, callInfo) - mock.lockQueryLabels.Unlock() - if mock.QueryLabelsFunc == nil { - var ( - stringToStringOut map[string]string - errOut error - ) - return stringToStringOut, errOut - } - return mock.QueryLabelsFunc(ctx, q, tr) -} - -// QueryLabelsCalls gets all the calls that were made to QueryLabels. -// Check the length with: -// -// len(mockeddatasource.MySQL.QueryLabelsCalls()) -func (mock *MySQL) QueryLabelsCalls() []struct { - Ctx context.Context - Q string - Tr processor.TimeRange -} { - var calls []struct { - Ctx context.Context - Q string - Tr processor.TimeRange - } - mock.lockQueryLabels.RLock() - calls = mock.calls.QueryLabels - mock.lockQueryLabels.RUnlock() - return calls -} - // Query calls QueryFunc. func (mock *MySQL) Query(ctx context.Context, q string, tr processor.TimeRange) (*processor.MySQLQueryResult, error) { callInfo := struct { @@ -232,7 +152,7 @@ func (mock *MySQL) Query(ctx context.Context, q string, tr processor.TimeRange) // QueryCalls gets all the calls that were made to Query. // Check the length with: // -// len(mockeddatasource.MySQL.QueryCalls()) +// len(mockedMySQL.QueryCalls()) func (mock *MySQL) QueryCalls() []struct { Ctx context.Context Q string @@ -248,3 +168,83 @@ func (mock *MySQL) QueryCalls() []struct { mock.lockQuery.RUnlock() return calls } + +// QueryLabels calls QueryLabelsFunc. +func (mock *MySQL) QueryLabels(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { + callInfo := struct { + Ctx context.Context + Q string + Tr processor.TimeRange + }{ + Ctx: ctx, + Q: q, + Tr: tr, + } + mock.lockQueryLabels.Lock() + mock.calls.QueryLabels = append(mock.calls.QueryLabels, callInfo) + mock.lockQueryLabels.Unlock() + if mock.QueryLabelsFunc == nil { + var ( + stringToStringOut map[string]string + errOut error + ) + return stringToStringOut, errOut + } + return mock.QueryLabelsFunc(ctx, q, tr) +} + +// QueryLabelsCalls gets all the calls that were made to QueryLabels. +// Check the length with: +// +// len(mockedMySQL.QueryLabelsCalls()) +func (mock *MySQL) QueryLabelsCalls() []struct { + Ctx context.Context + Q string + Tr processor.TimeRange +} { + var calls []struct { + Ctx context.Context + Q string + Tr processor.TimeRange + } + mock.lockQueryLabels.RLock() + calls = mock.calls.QueryLabels + mock.lockQueryLabels.RUnlock() + return calls +} + +// TestConnection calls TestConnectionFunc. +func (mock *MySQL) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockTestConnection.Lock() + mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) + mock.lockTestConnection.Unlock() + if mock.TestConnectionFunc == nil { + var ( + connectionStatusOut processor.ConnectionStatus + errOut error + ) + return connectionStatusOut, errOut + } + return mock.TestConnectionFunc(ctx) +} + +// TestConnectionCalls gets all the calls that were made to TestConnection. +// Check the length with: +// +// len(mockedMySQL.TestConnectionCalls()) +func (mock *MySQL) TestConnectionCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockTestConnection.RLock() + calls = mock.calls.TestConnection + mock.lockTestConnection.RUnlock() + return calls +} diff --git a/server/core/internal/datasource/_mock/postgresql.go b/server/core/internal/datasource/_mock/postgresql.go index 3d141951..d9d43ae9 100644 --- a/server/core/internal/datasource/_mock/postgresql.go +++ b/server/core/internal/datasource/_mock/postgresql.go @@ -17,62 +17,48 @@ var _ datasource.PostgreSQL = &PostgreSQL{} // PostgreSQL is a mock implementation of datasource.PostgreSQL. // -// func TestSomethingThatUsesdatasource.PostgreSQL(t *testing.T) { +// func TestSomethingThatUsesPostgreSQL(t *testing.T) { // // // make and configure a mocked datasource.PostgreSQL -// mockeddatasource.PostgreSQL := &PostgreSQL{ -// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { -// panic("mock out the TestConnection method") -// }, +// mockedPostgreSQL := &PostgreSQL{ // MetadataFunc: func(ctx context.Context) (*processor.SQLMetadataResult, error) { // panic("mock out the Metadata method") // }, -// QueryLabelsFunc: func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { -// panic("mock out the QueryLabels method") -// }, // QueryFunc: func(ctx context.Context, q string, tr processor.TimeRange) (*processor.PostgreSQLQueryResult, error) { // panic("mock out the Query method") // }, +// QueryLabelsFunc: func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { +// panic("mock out the QueryLabels method") +// }, +// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { +// panic("mock out the TestConnection method") +// }, // } // -// // use mockeddatasource.PostgreSQL in code that requires datasource.PostgreSQL +// // use mockedPostgreSQL in code that requires datasource.PostgreSQL // // and then make assertions. // // } type PostgreSQL struct { - // TestConnectionFunc mocks the TestConnection method. - TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) - // MetadataFunc mocks the Metadata method. MetadataFunc func(ctx context.Context) (*processor.SQLMetadataResult, error) - // QueryLabelsFunc mocks the QueryLabels method. - QueryLabelsFunc func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) - // QueryFunc mocks the Query method. QueryFunc func(ctx context.Context, q string, tr processor.TimeRange) (*processor.PostgreSQLQueryResult, error) + // QueryLabelsFunc mocks the QueryLabels method. + QueryLabelsFunc func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) + + // TestConnectionFunc mocks the TestConnection method. + TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) + // calls tracks calls to the methods. calls struct { - // TestConnection holds details about calls to the TestConnection method. - TestConnection []struct { - // Ctx is the ctx argument value. - Ctx context.Context - } // Metadata holds details about calls to the Metadata method. Metadata []struct { // Ctx is the ctx argument value. Ctx context.Context } - // QueryLabels holds details about calls to the QueryLabels method. - QueryLabels []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Q is the q argument value. - Q string - // Tr is the tr argument value. - Tr processor.TimeRange - } // Query holds details about calls to the Query method. Query []struct { // Ctx is the ctx argument value. @@ -82,47 +68,25 @@ type PostgreSQL struct { // Tr is the tr argument value. Tr processor.TimeRange } + // QueryLabels holds details about calls to the QueryLabels method. + QueryLabels []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Q is the q argument value. + Q string + // Tr is the tr argument value. + Tr processor.TimeRange + } + // TestConnection holds details about calls to the TestConnection method. + TestConnection []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } } - lockTestConnection sync.RWMutex lockMetadata sync.RWMutex - lockQueryLabels sync.RWMutex lockQuery sync.RWMutex -} - -// TestConnection calls TestConnectionFunc. -func (mock *PostgreSQL) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { - callInfo := struct { - Ctx context.Context - }{ - Ctx: ctx, - } - mock.lockTestConnection.Lock() - mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) - mock.lockTestConnection.Unlock() - if mock.TestConnectionFunc == nil { - var ( - connectionStatusOut processor.ConnectionStatus - errOut error - ) - return connectionStatusOut, errOut - } - return mock.TestConnectionFunc(ctx) -} - -// TestConnectionCalls gets all the calls that were made to TestConnection. -// Check the length with: -// -// len(mockeddatasource.PostgreSQL.TestConnectionCalls()) -func (mock *PostgreSQL) TestConnectionCalls() []struct { - Ctx context.Context -} { - var calls []struct { - Ctx context.Context - } - mock.lockTestConnection.RLock() - calls = mock.calls.TestConnection - mock.lockTestConnection.RUnlock() - return calls + lockQueryLabels sync.RWMutex + lockTestConnection sync.RWMutex } // Metadata calls MetadataFunc. @@ -148,7 +112,7 @@ func (mock *PostgreSQL) Metadata(ctx context.Context) (*processor.SQLMetadataRes // MetadataCalls gets all the calls that were made to Metadata. // Check the length with: // -// len(mockeddatasource.PostgreSQL.MetadataCalls()) +// len(mockedPostgreSQL.MetadataCalls()) func (mock *PostgreSQL) MetadataCalls() []struct { Ctx context.Context } { @@ -161,50 +125,6 @@ func (mock *PostgreSQL) MetadataCalls() []struct { return calls } -// QueryLabels calls QueryLabelsFunc. -func (mock *PostgreSQL) QueryLabels(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { - callInfo := struct { - Ctx context.Context - Q string - Tr processor.TimeRange - }{ - Ctx: ctx, - Q: q, - Tr: tr, - } - mock.lockQueryLabels.Lock() - mock.calls.QueryLabels = append(mock.calls.QueryLabels, callInfo) - mock.lockQueryLabels.Unlock() - if mock.QueryLabelsFunc == nil { - var ( - stringToStringOut map[string]string - errOut error - ) - return stringToStringOut, errOut - } - return mock.QueryLabelsFunc(ctx, q, tr) -} - -// QueryLabelsCalls gets all the calls that were made to QueryLabels. -// Check the length with: -// -// len(mockeddatasource.PostgreSQL.QueryLabelsCalls()) -func (mock *PostgreSQL) QueryLabelsCalls() []struct { - Ctx context.Context - Q string - Tr processor.TimeRange -} { - var calls []struct { - Ctx context.Context - Q string - Tr processor.TimeRange - } - mock.lockQueryLabels.RLock() - calls = mock.calls.QueryLabels - mock.lockQueryLabels.RUnlock() - return calls -} - // Query calls QueryFunc. func (mock *PostgreSQL) Query(ctx context.Context, q string, tr processor.TimeRange) (*processor.PostgreSQLQueryResult, error) { callInfo := struct { @@ -232,7 +152,7 @@ func (mock *PostgreSQL) Query(ctx context.Context, q string, tr processor.TimeRa // QueryCalls gets all the calls that were made to Query. // Check the length with: // -// len(mockeddatasource.PostgreSQL.QueryCalls()) +// len(mockedPostgreSQL.QueryCalls()) func (mock *PostgreSQL) QueryCalls() []struct { Ctx context.Context Q string @@ -248,3 +168,83 @@ func (mock *PostgreSQL) QueryCalls() []struct { mock.lockQuery.RUnlock() return calls } + +// QueryLabels calls QueryLabelsFunc. +func (mock *PostgreSQL) QueryLabels(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { + callInfo := struct { + Ctx context.Context + Q string + Tr processor.TimeRange + }{ + Ctx: ctx, + Q: q, + Tr: tr, + } + mock.lockQueryLabels.Lock() + mock.calls.QueryLabels = append(mock.calls.QueryLabels, callInfo) + mock.lockQueryLabels.Unlock() + if mock.QueryLabelsFunc == nil { + var ( + stringToStringOut map[string]string + errOut error + ) + return stringToStringOut, errOut + } + return mock.QueryLabelsFunc(ctx, q, tr) +} + +// QueryLabelsCalls gets all the calls that were made to QueryLabels. +// Check the length with: +// +// len(mockedPostgreSQL.QueryLabelsCalls()) +func (mock *PostgreSQL) QueryLabelsCalls() []struct { + Ctx context.Context + Q string + Tr processor.TimeRange +} { + var calls []struct { + Ctx context.Context + Q string + Tr processor.TimeRange + } + mock.lockQueryLabels.RLock() + calls = mock.calls.QueryLabels + mock.lockQueryLabels.RUnlock() + return calls +} + +// TestConnection calls TestConnectionFunc. +func (mock *PostgreSQL) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockTestConnection.Lock() + mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) + mock.lockTestConnection.Unlock() + if mock.TestConnectionFunc == nil { + var ( + connectionStatusOut processor.ConnectionStatus + errOut error + ) + return connectionStatusOut, errOut + } + return mock.TestConnectionFunc(ctx) +} + +// TestConnectionCalls gets all the calls that were made to TestConnection. +// Check the length with: +// +// len(mockedPostgreSQL.TestConnectionCalls()) +func (mock *PostgreSQL) TestConnectionCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockTestConnection.RLock() + calls = mock.calls.TestConnection + mock.lockTestConnection.RUnlock() + return calls +} diff --git a/server/core/internal/datasource/_mock/prometheus.go b/server/core/internal/datasource/_mock/prometheus.go index 8e736e65..a2cbbf26 100644 --- a/server/core/internal/datasource/_mock/prometheus.go +++ b/server/core/internal/datasource/_mock/prometheus.go @@ -17,12 +17,15 @@ var _ datasource.Prometheus = &Prometheus{} // Prometheus is a mock implementation of datasource.Prometheus. // -// func TestSomethingThatUsesdatasource.Prometheus(t *testing.T) { +// func TestSomethingThatUsesPrometheus(t *testing.T) { // // // make and configure a mocked datasource.Prometheus -// mockeddatasource.Prometheus := &Prometheus{ -// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { -// panic("mock out the TestConnection method") +// mockedPrometheus := &Prometheus{ +// LabelNamesFunc: func(ctx context.Context, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelNamesResult, error) { +// panic("mock out the LabelNames method") +// }, +// LabelValuesFunc: func(ctx context.Context, label string, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelValuesResult, error) { +// panic("mock out the LabelValues method") // }, // MetadataFunc: func(ctx context.Context) (*processor.PrometheusMetadataResult, error) { // panic("mock out the Metadata method") @@ -30,24 +33,24 @@ var _ datasource.Prometheus = &Prometheus{} // QueryRangeFunc: func(ctx context.Context, q string, tr processor.TimeRange) (*processor.PrometheusQueryResult, error) { // panic("mock out the QueryRange method") // }, -// LabelNamesFunc: func(ctx context.Context, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelNamesResult, error) { -// panic("mock out the LabelNames method") -// }, -// LabelValuesFunc: func(ctx context.Context, label string, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelValuesResult, error) { -// panic("mock out the LabelValues method") -// }, // SeriesFunc: func(ctx context.Context, matchers []string, tr processor.TimeRange) (*processor.PrometheusSeriesResult, error) { // panic("mock out the Series method") // }, +// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { +// panic("mock out the TestConnection method") +// }, // } // -// // use mockeddatasource.Prometheus in code that requires datasource.Prometheus +// // use mockedPrometheus in code that requires datasource.Prometheus // // and then make assertions. // // } type Prometheus struct { - // TestConnectionFunc mocks the TestConnection method. - TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) + // LabelNamesFunc mocks the LabelNames method. + LabelNamesFunc func(ctx context.Context, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelNamesResult, error) + + // LabelValuesFunc mocks the LabelValues method. + LabelValuesFunc func(ctx context.Context, label string, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelValuesResult, error) // MetadataFunc mocks the Metadata method. MetadataFunc func(ctx context.Context) (*processor.PrometheusMetadataResult, error) @@ -55,36 +58,14 @@ type Prometheus struct { // QueryRangeFunc mocks the QueryRange method. QueryRangeFunc func(ctx context.Context, q string, tr processor.TimeRange) (*processor.PrometheusQueryResult, error) - // LabelNamesFunc mocks the LabelNames method. - LabelNamesFunc func(ctx context.Context, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelNamesResult, error) - - // LabelValuesFunc mocks the LabelValues method. - LabelValuesFunc func(ctx context.Context, label string, matchers []string, tr processor.TimeRange) (*processor.PrometheusLabelValuesResult, error) - // SeriesFunc mocks the Series method. SeriesFunc func(ctx context.Context, matchers []string, tr processor.TimeRange) (*processor.PrometheusSeriesResult, error) + // TestConnectionFunc mocks the TestConnection method. + TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) + // calls tracks calls to the methods. calls struct { - // TestConnection holds details about calls to the TestConnection method. - TestConnection []struct { - // Ctx is the ctx argument value. - Ctx context.Context - } - // Metadata holds details about calls to the Metadata method. - Metadata []struct { - // Ctx is the ctx argument value. - Ctx context.Context - } - // QueryRange holds details about calls to the QueryRange method. - QueryRange []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Q is the q argument value. - Q string - // Tr is the tr argument value. - Tr processor.TimeRange - } // LabelNames holds details about calls to the LabelNames method. LabelNames []struct { // Ctx is the ctx argument value. @@ -105,6 +86,20 @@ type Prometheus struct { // Tr is the tr argument value. Tr processor.TimeRange } + // Metadata holds details about calls to the Metadata method. + Metadata []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } + // QueryRange holds details about calls to the QueryRange method. + QueryRange []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Q is the q argument value. + Q string + // Tr is the tr argument value. + Tr processor.TimeRange + } // Series holds details about calls to the Series method. Series []struct { // Ctx is the ctx argument value. @@ -114,129 +109,18 @@ type Prometheus struct { // Tr is the tr argument value. Tr processor.TimeRange } + // TestConnection holds details about calls to the TestConnection method. + TestConnection []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } } - lockTestConnection sync.RWMutex - lockMetadata sync.RWMutex - lockQueryRange sync.RWMutex lockLabelNames sync.RWMutex lockLabelValues sync.RWMutex + lockMetadata sync.RWMutex + lockQueryRange sync.RWMutex lockSeries sync.RWMutex -} - -// TestConnection calls TestConnectionFunc. -func (mock *Prometheus) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { - callInfo := struct { - Ctx context.Context - }{ - Ctx: ctx, - } - mock.lockTestConnection.Lock() - mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) - mock.lockTestConnection.Unlock() - if mock.TestConnectionFunc == nil { - var ( - connectionStatusOut processor.ConnectionStatus - errOut error - ) - return connectionStatusOut, errOut - } - return mock.TestConnectionFunc(ctx) -} - -// TestConnectionCalls gets all the calls that were made to TestConnection. -// Check the length with: -// -// len(mockeddatasource.Prometheus.TestConnectionCalls()) -func (mock *Prometheus) TestConnectionCalls() []struct { - Ctx context.Context -} { - var calls []struct { - Ctx context.Context - } - mock.lockTestConnection.RLock() - calls = mock.calls.TestConnection - mock.lockTestConnection.RUnlock() - return calls -} - -// Metadata calls MetadataFunc. -func (mock *Prometheus) Metadata(ctx context.Context) (*processor.PrometheusMetadataResult, error) { - callInfo := struct { - Ctx context.Context - }{ - Ctx: ctx, - } - mock.lockMetadata.Lock() - mock.calls.Metadata = append(mock.calls.Metadata, callInfo) - mock.lockMetadata.Unlock() - if mock.MetadataFunc == nil { - var ( - prometheusMetadataResultOut *processor.PrometheusMetadataResult - errOut error - ) - return prometheusMetadataResultOut, errOut - } - return mock.MetadataFunc(ctx) -} - -// MetadataCalls gets all the calls that were made to Metadata. -// Check the length with: -// -// len(mockeddatasource.Prometheus.MetadataCalls()) -func (mock *Prometheus) MetadataCalls() []struct { - Ctx context.Context -} { - var calls []struct { - Ctx context.Context - } - mock.lockMetadata.RLock() - calls = mock.calls.Metadata - mock.lockMetadata.RUnlock() - return calls -} - -// QueryRange calls QueryRangeFunc. -func (mock *Prometheus) QueryRange(ctx context.Context, q string, tr processor.TimeRange) (*processor.PrometheusQueryResult, error) { - callInfo := struct { - Ctx context.Context - Q string - Tr processor.TimeRange - }{ - Ctx: ctx, - Q: q, - Tr: tr, - } - mock.lockQueryRange.Lock() - mock.calls.QueryRange = append(mock.calls.QueryRange, callInfo) - mock.lockQueryRange.Unlock() - if mock.QueryRangeFunc == nil { - var ( - prometheusQueryResultOut *processor.PrometheusQueryResult - errOut error - ) - return prometheusQueryResultOut, errOut - } - return mock.QueryRangeFunc(ctx, q, tr) -} - -// QueryRangeCalls gets all the calls that were made to QueryRange. -// Check the length with: -// -// len(mockeddatasource.Prometheus.QueryRangeCalls()) -func (mock *Prometheus) QueryRangeCalls() []struct { - Ctx context.Context - Q string - Tr processor.TimeRange -} { - var calls []struct { - Ctx context.Context - Q string - Tr processor.TimeRange - } - mock.lockQueryRange.RLock() - calls = mock.calls.QueryRange - mock.lockQueryRange.RUnlock() - return calls + lockTestConnection sync.RWMutex } // LabelNames calls LabelNamesFunc. @@ -266,7 +150,7 @@ func (mock *Prometheus) LabelNames(ctx context.Context, matchers []string, tr pr // LabelNamesCalls gets all the calls that were made to LabelNames. // Check the length with: // -// len(mockeddatasource.Prometheus.LabelNamesCalls()) +// len(mockedPrometheus.LabelNamesCalls()) func (mock *Prometheus) LabelNamesCalls() []struct { Ctx context.Context Matchers []string @@ -312,7 +196,7 @@ func (mock *Prometheus) LabelValues(ctx context.Context, label string, matchers // LabelValuesCalls gets all the calls that were made to LabelValues. // Check the length with: // -// len(mockeddatasource.Prometheus.LabelValuesCalls()) +// len(mockedPrometheus.LabelValuesCalls()) func (mock *Prometheus) LabelValuesCalls() []struct { Ctx context.Context Label string @@ -331,6 +215,86 @@ func (mock *Prometheus) LabelValuesCalls() []struct { return calls } +// Metadata calls MetadataFunc. +func (mock *Prometheus) Metadata(ctx context.Context) (*processor.PrometheusMetadataResult, error) { + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockMetadata.Lock() + mock.calls.Metadata = append(mock.calls.Metadata, callInfo) + mock.lockMetadata.Unlock() + if mock.MetadataFunc == nil { + var ( + prometheusMetadataResultOut *processor.PrometheusMetadataResult + errOut error + ) + return prometheusMetadataResultOut, errOut + } + return mock.MetadataFunc(ctx) +} + +// MetadataCalls gets all the calls that were made to Metadata. +// Check the length with: +// +// len(mockedPrometheus.MetadataCalls()) +func (mock *Prometheus) MetadataCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockMetadata.RLock() + calls = mock.calls.Metadata + mock.lockMetadata.RUnlock() + return calls +} + +// QueryRange calls QueryRangeFunc. +func (mock *Prometheus) QueryRange(ctx context.Context, q string, tr processor.TimeRange) (*processor.PrometheusQueryResult, error) { + callInfo := struct { + Ctx context.Context + Q string + Tr processor.TimeRange + }{ + Ctx: ctx, + Q: q, + Tr: tr, + } + mock.lockQueryRange.Lock() + mock.calls.QueryRange = append(mock.calls.QueryRange, callInfo) + mock.lockQueryRange.Unlock() + if mock.QueryRangeFunc == nil { + var ( + prometheusQueryResultOut *processor.PrometheusQueryResult + errOut error + ) + return prometheusQueryResultOut, errOut + } + return mock.QueryRangeFunc(ctx, q, tr) +} + +// QueryRangeCalls gets all the calls that were made to QueryRange. +// Check the length with: +// +// len(mockedPrometheus.QueryRangeCalls()) +func (mock *Prometheus) QueryRangeCalls() []struct { + Ctx context.Context + Q string + Tr processor.TimeRange +} { + var calls []struct { + Ctx context.Context + Q string + Tr processor.TimeRange + } + mock.lockQueryRange.RLock() + calls = mock.calls.QueryRange + mock.lockQueryRange.RUnlock() + return calls +} + // Series calls SeriesFunc. func (mock *Prometheus) Series(ctx context.Context, matchers []string, tr processor.TimeRange) (*processor.PrometheusSeriesResult, error) { callInfo := struct { @@ -358,7 +322,7 @@ func (mock *Prometheus) Series(ctx context.Context, matchers []string, tr proces // SeriesCalls gets all the calls that were made to Series. // Check the length with: // -// len(mockeddatasource.Prometheus.SeriesCalls()) +// len(mockedPrometheus.SeriesCalls()) func (mock *Prometheus) SeriesCalls() []struct { Ctx context.Context Matchers []string @@ -374,3 +338,39 @@ func (mock *Prometheus) SeriesCalls() []struct { mock.lockSeries.RUnlock() return calls } + +// TestConnection calls TestConnectionFunc. +func (mock *Prometheus) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockTestConnection.Lock() + mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) + mock.lockTestConnection.Unlock() + if mock.TestConnectionFunc == nil { + var ( + connectionStatusOut processor.ConnectionStatus + errOut error + ) + return connectionStatusOut, errOut + } + return mock.TestConnectionFunc(ctx) +} + +// TestConnectionCalls gets all the calls that were made to TestConnection. +// Check the length with: +// +// len(mockedPrometheus.TestConnectionCalls()) +func (mock *Prometheus) TestConnectionCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockTestConnection.RLock() + calls = mock.calls.TestConnection + mock.lockTestConnection.RUnlock() + return calls +} diff --git a/server/core/internal/datasource/_mock/runner.go b/server/core/internal/datasource/_mock/runner.go index d77bfee1..8d5b7377 100644 --- a/server/core/internal/datasource/_mock/runner.go +++ b/server/core/internal/datasource/_mock/runner.go @@ -17,65 +17,57 @@ var _ datasource.Runner = &Runner{} // Runner is a mock implementation of datasource.Runner. // -// func TestSomethingThatUsesdatasource.Runner(t *testing.T) { +// func TestSomethingThatUsesRunner(t *testing.T) { // // // make and configure a mocked datasource.Runner -// mockeddatasource.Runner := &Runner{ -// TypeFunc: func() datasource.Type { -// panic("mock out the Type method") -// }, -// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { -// panic("mock out the TestConnection method") -// }, -// PrometheusFunc: func(ctx context.Context) (datasource.Prometheus, error) { -// panic("mock out the Prometheus method") +// mockedRunner := &Runner{ +// MySQLFunc: func(ctx context.Context) (datasource.MySQL, error) { +// panic("mock out the MySQL method") // }, // PostgreSQLFunc: func(ctx context.Context) (datasource.PostgreSQL, error) { // panic("mock out the PostgreSQL method") // }, -// MySQLFunc: func(ctx context.Context) (datasource.MySQL, error) { -// panic("mock out the MySQL method") +// PrometheusFunc: func(ctx context.Context) (datasource.Prometheus, error) { +// panic("mock out the Prometheus method") // }, // SQLFunc: func(ctx context.Context) (datasource.SQL, error) { // panic("mock out the SQL method") // }, +// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { +// panic("mock out the TestConnection method") +// }, +// TypeFunc: func() datasource.Type { +// panic("mock out the Type method") +// }, // } // -// // use mockeddatasource.Runner in code that requires datasource.Runner +// // use mockedRunner in code that requires datasource.Runner // // and then make assertions. // // } type Runner struct { - // TypeFunc mocks the Type method. - TypeFunc func() datasource.Type - - // TestConnectionFunc mocks the TestConnection method. - TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) - - // PrometheusFunc mocks the Prometheus method. - PrometheusFunc func(ctx context.Context) (datasource.Prometheus, error) + // MySQLFunc mocks the MySQL method. + MySQLFunc func(ctx context.Context) (datasource.MySQL, error) // PostgreSQLFunc mocks the PostgreSQL method. PostgreSQLFunc func(ctx context.Context) (datasource.PostgreSQL, error) - // MySQLFunc mocks the MySQL method. - MySQLFunc func(ctx context.Context) (datasource.MySQL, error) + // PrometheusFunc mocks the Prometheus method. + PrometheusFunc func(ctx context.Context) (datasource.Prometheus, error) // SQLFunc mocks the SQL method. SQLFunc func(ctx context.Context) (datasource.SQL, error) + // TestConnectionFunc mocks the TestConnection method. + TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) + + // TypeFunc mocks the Type method. + TypeFunc func() datasource.Type + // calls tracks calls to the methods. calls struct { - // Type holds details about calls to the Type method. - Type []struct { - } - // TestConnection holds details about calls to the TestConnection method. - TestConnection []struct { - // Ctx is the ctx argument value. - Ctx context.Context - } - // Prometheus holds details about calls to the Prometheus method. - Prometheus []struct { + // MySQL holds details about calls to the MySQL method. + MySQL []struct { // Ctx is the ctx argument value. Ctx context.Context } @@ -84,8 +76,8 @@ type Runner struct { // Ctx is the ctx argument value. Ctx context.Context } - // MySQL holds details about calls to the MySQL method. - MySQL []struct { + // Prometheus holds details about calls to the Prometheus method. + Prometheus []struct { // Ctx is the ctx argument value. Ctx context.Context } @@ -94,114 +86,56 @@ type Runner struct { // Ctx is the ctx argument value. Ctx context.Context } + // TestConnection holds details about calls to the TestConnection method. + TestConnection []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } + // Type holds details about calls to the Type method. + Type []struct { + } } - lockType sync.RWMutex - lockTestConnection sync.RWMutex - lockPrometheus sync.RWMutex - lockPostgreSQL sync.RWMutex lockMySQL sync.RWMutex + lockPostgreSQL sync.RWMutex + lockPrometheus sync.RWMutex lockSQL sync.RWMutex + lockTestConnection sync.RWMutex + lockType sync.RWMutex } -// Type calls TypeFunc. -func (mock *Runner) Type() datasource.Type { - callInfo := struct { - }{} - mock.lockType.Lock() - mock.calls.Type = append(mock.calls.Type, callInfo) - mock.lockType.Unlock() - if mock.TypeFunc == nil { - var ( - typeOut datasource.Type - ) - return typeOut - } - return mock.TypeFunc() -} - -// TypeCalls gets all the calls that were made to Type. -// Check the length with: -// -// len(mockeddatasource.Runner.TypeCalls()) -func (mock *Runner) TypeCalls() []struct { -} { - var calls []struct { - } - mock.lockType.RLock() - calls = mock.calls.Type - mock.lockType.RUnlock() - return calls -} - -// TestConnection calls TestConnectionFunc. -func (mock *Runner) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { +// MySQL calls MySQLFunc. +func (mock *Runner) MySQL(ctx context.Context) (datasource.MySQL, error) { callInfo := struct { Ctx context.Context }{ Ctx: ctx, } - mock.lockTestConnection.Lock() - mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) - mock.lockTestConnection.Unlock() - if mock.TestConnectionFunc == nil { + mock.lockMySQL.Lock() + mock.calls.MySQL = append(mock.calls.MySQL, callInfo) + mock.lockMySQL.Unlock() + if mock.MySQLFunc == nil { var ( - connectionStatusOut processor.ConnectionStatus - errOut error + mySQLOut datasource.MySQL + errOut error ) - return connectionStatusOut, errOut + return mySQLOut, errOut } - return mock.TestConnectionFunc(ctx) + return mock.MySQLFunc(ctx) } -// TestConnectionCalls gets all the calls that were made to TestConnection. +// MySQLCalls gets all the calls that were made to MySQL. // Check the length with: // -// len(mockeddatasource.Runner.TestConnectionCalls()) -func (mock *Runner) TestConnectionCalls() []struct { +// len(mockedRunner.MySQLCalls()) +func (mock *Runner) MySQLCalls() []struct { Ctx context.Context } { var calls []struct { Ctx context.Context } - mock.lockTestConnection.RLock() - calls = mock.calls.TestConnection - mock.lockTestConnection.RUnlock() - return calls -} - -// Prometheus calls PrometheusFunc. -func (mock *Runner) Prometheus(ctx context.Context) (datasource.Prometheus, error) { - callInfo := struct { - Ctx context.Context - }{ - Ctx: ctx, - } - mock.lockPrometheus.Lock() - mock.calls.Prometheus = append(mock.calls.Prometheus, callInfo) - mock.lockPrometheus.Unlock() - if mock.PrometheusFunc == nil { - var ( - prometheusOut datasource.Prometheus - errOut error - ) - return prometheusOut, errOut - } - return mock.PrometheusFunc(ctx) -} - -// PrometheusCalls gets all the calls that were made to Prometheus. -// Check the length with: -// -// len(mockeddatasource.Runner.PrometheusCalls()) -func (mock *Runner) PrometheusCalls() []struct { - Ctx context.Context -} { - var calls []struct { - Ctx context.Context - } - mock.lockPrometheus.RLock() - calls = mock.calls.Prometheus - mock.lockPrometheus.RUnlock() + mock.lockMySQL.RLock() + calls = mock.calls.MySQL + mock.lockMySQL.RUnlock() return calls } @@ -228,7 +162,7 @@ func (mock *Runner) PostgreSQL(ctx context.Context) (datasource.PostgreSQL, erro // PostgreSQLCalls gets all the calls that were made to PostgreSQL. // Check the length with: // -// len(mockeddatasource.Runner.PostgreSQLCalls()) +// len(mockedRunner.PostgreSQLCalls()) func (mock *Runner) PostgreSQLCalls() []struct { Ctx context.Context } { @@ -241,39 +175,39 @@ func (mock *Runner) PostgreSQLCalls() []struct { return calls } -// MySQL calls MySQLFunc. -func (mock *Runner) MySQL(ctx context.Context) (datasource.MySQL, error) { +// Prometheus calls PrometheusFunc. +func (mock *Runner) Prometheus(ctx context.Context) (datasource.Prometheus, error) { callInfo := struct { Ctx context.Context }{ Ctx: ctx, } - mock.lockMySQL.Lock() - mock.calls.MySQL = append(mock.calls.MySQL, callInfo) - mock.lockMySQL.Unlock() - if mock.MySQLFunc == nil { + mock.lockPrometheus.Lock() + mock.calls.Prometheus = append(mock.calls.Prometheus, callInfo) + mock.lockPrometheus.Unlock() + if mock.PrometheusFunc == nil { var ( - mySQLOut datasource.MySQL - errOut error + prometheusOut datasource.Prometheus + errOut error ) - return mySQLOut, errOut + return prometheusOut, errOut } - return mock.MySQLFunc(ctx) + return mock.PrometheusFunc(ctx) } -// MySQLCalls gets all the calls that were made to MySQL. +// PrometheusCalls gets all the calls that were made to Prometheus. // Check the length with: // -// len(mockeddatasource.Runner.MySQLCalls()) -func (mock *Runner) MySQLCalls() []struct { +// len(mockedRunner.PrometheusCalls()) +func (mock *Runner) PrometheusCalls() []struct { Ctx context.Context } { var calls []struct { Ctx context.Context } - mock.lockMySQL.RLock() - calls = mock.calls.MySQL - mock.lockMySQL.RUnlock() + mock.lockPrometheus.RLock() + calls = mock.calls.Prometheus + mock.lockPrometheus.RUnlock() return calls } @@ -300,7 +234,7 @@ func (mock *Runner) SQL(ctx context.Context) (datasource.SQL, error) { // SQLCalls gets all the calls that were made to SQL. // Check the length with: // -// len(mockeddatasource.Runner.SQLCalls()) +// len(mockedRunner.SQLCalls()) func (mock *Runner) SQLCalls() []struct { Ctx context.Context } { @@ -312,3 +246,69 @@ func (mock *Runner) SQLCalls() []struct { mock.lockSQL.RUnlock() return calls } + +// TestConnection calls TestConnectionFunc. +func (mock *Runner) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockTestConnection.Lock() + mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) + mock.lockTestConnection.Unlock() + if mock.TestConnectionFunc == nil { + var ( + connectionStatusOut processor.ConnectionStatus + errOut error + ) + return connectionStatusOut, errOut + } + return mock.TestConnectionFunc(ctx) +} + +// TestConnectionCalls gets all the calls that were made to TestConnection. +// Check the length with: +// +// len(mockedRunner.TestConnectionCalls()) +func (mock *Runner) TestConnectionCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockTestConnection.RLock() + calls = mock.calls.TestConnection + mock.lockTestConnection.RUnlock() + return calls +} + +// Type calls TypeFunc. +func (mock *Runner) Type() datasource.Type { + callInfo := struct { + }{} + mock.lockType.Lock() + mock.calls.Type = append(mock.calls.Type, callInfo) + mock.lockType.Unlock() + if mock.TypeFunc == nil { + var ( + typeOut datasource.Type + ) + return typeOut + } + return mock.TypeFunc() +} + +// TypeCalls gets all the calls that were made to Type. +// Check the length with: +// +// len(mockedRunner.TypeCalls()) +func (mock *Runner) TypeCalls() []struct { +} { + var calls []struct { + } + mock.lockType.RLock() + calls = mock.calls.Type + mock.lockType.RUnlock() + return calls +} diff --git a/server/core/internal/datasource/_mock/sql.go b/server/core/internal/datasource/_mock/sql.go index df6fd315..79924b93 100644 --- a/server/core/internal/datasource/_mock/sql.go +++ b/server/core/internal/datasource/_mock/sql.go @@ -17,42 +17,37 @@ var _ datasource.SQL = &SQL{} // SQL is a mock implementation of datasource.SQL. // -// func TestSomethingThatUsesdatasource.SQL(t *testing.T) { +// func TestSomethingThatUsesSQL(t *testing.T) { // // // make and configure a mocked datasource.SQL -// mockeddatasource.SQL := &SQL{ -// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { -// panic("mock out the TestConnection method") -// }, +// mockedSQL := &SQL{ // MetadataFunc: func(ctx context.Context) (*processor.SQLMetadataResult, error) { // panic("mock out the Metadata method") // }, // QueryLabelsFunc: func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) { // panic("mock out the QueryLabels method") // }, +// TestConnectionFunc: func(ctx context.Context) (processor.ConnectionStatus, error) { +// panic("mock out the TestConnection method") +// }, // } // -// // use mockeddatasource.SQL in code that requires datasource.SQL +// // use mockedSQL in code that requires datasource.SQL // // and then make assertions. // // } type SQL struct { - // TestConnectionFunc mocks the TestConnection method. - TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) - // MetadataFunc mocks the Metadata method. MetadataFunc func(ctx context.Context) (*processor.SQLMetadataResult, error) // QueryLabelsFunc mocks the QueryLabels method. QueryLabelsFunc func(ctx context.Context, q string, tr processor.TimeRange) (map[string]string, error) + // TestConnectionFunc mocks the TestConnection method. + TestConnectionFunc func(ctx context.Context) (processor.ConnectionStatus, error) + // calls tracks calls to the methods. calls struct { - // TestConnection holds details about calls to the TestConnection method. - TestConnection []struct { - // Ctx is the ctx argument value. - Ctx context.Context - } // Metadata holds details about calls to the Metadata method. Metadata []struct { // Ctx is the ctx argument value. @@ -67,46 +62,15 @@ type SQL struct { // Tr is the tr argument value. Tr processor.TimeRange } + // TestConnection holds details about calls to the TestConnection method. + TestConnection []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } } - lockTestConnection sync.RWMutex lockMetadata sync.RWMutex lockQueryLabels sync.RWMutex -} - -// TestConnection calls TestConnectionFunc. -func (mock *SQL) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { - callInfo := struct { - Ctx context.Context - }{ - Ctx: ctx, - } - mock.lockTestConnection.Lock() - mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) - mock.lockTestConnection.Unlock() - if mock.TestConnectionFunc == nil { - var ( - connectionStatusOut processor.ConnectionStatus - errOut error - ) - return connectionStatusOut, errOut - } - return mock.TestConnectionFunc(ctx) -} - -// TestConnectionCalls gets all the calls that were made to TestConnection. -// Check the length with: -// -// len(mockeddatasource.SQL.TestConnectionCalls()) -func (mock *SQL) TestConnectionCalls() []struct { - Ctx context.Context -} { - var calls []struct { - Ctx context.Context - } - mock.lockTestConnection.RLock() - calls = mock.calls.TestConnection - mock.lockTestConnection.RUnlock() - return calls + lockTestConnection sync.RWMutex } // Metadata calls MetadataFunc. @@ -132,7 +96,7 @@ func (mock *SQL) Metadata(ctx context.Context) (*processor.SQLMetadataResult, er // MetadataCalls gets all the calls that were made to Metadata. // Check the length with: // -// len(mockeddatasource.SQL.MetadataCalls()) +// len(mockedSQL.MetadataCalls()) func (mock *SQL) MetadataCalls() []struct { Ctx context.Context } { @@ -172,7 +136,7 @@ func (mock *SQL) QueryLabels(ctx context.Context, q string, tr processor.TimeRan // QueryLabelsCalls gets all the calls that were made to QueryLabels. // Check the length with: // -// len(mockeddatasource.SQL.QueryLabelsCalls()) +// len(mockedSQL.QueryLabelsCalls()) func (mock *SQL) QueryLabelsCalls() []struct { Ctx context.Context Q string @@ -188,3 +152,39 @@ func (mock *SQL) QueryLabelsCalls() []struct { mock.lockQueryLabels.RUnlock() return calls } + +// TestConnection calls TestConnectionFunc. +func (mock *SQL) TestConnection(ctx context.Context) (processor.ConnectionStatus, error) { + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockTestConnection.Lock() + mock.calls.TestConnection = append(mock.calls.TestConnection, callInfo) + mock.lockTestConnection.Unlock() + if mock.TestConnectionFunc == nil { + var ( + connectionStatusOut processor.ConnectionStatus + errOut error + ) + return connectionStatusOut, errOut + } + return mock.TestConnectionFunc(ctx) +} + +// TestConnectionCalls gets all the calls that were made to TestConnection. +// Check the length with: +// +// len(mockedSQL.TestConnectionCalls()) +func (mock *SQL) TestConnectionCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockTestConnection.RLock() + calls = mock.calls.TestConnection + mock.lockTestConnection.RUnlock() + return calls +} diff --git a/server/core/internal/datasource/_mock/status_store.go b/server/core/internal/datasource/_mock/status_store.go index 74b7fe65..ca89ce89 100644 --- a/server/core/internal/datasource/_mock/status_store.go +++ b/server/core/internal/datasource/_mock/status_store.go @@ -18,16 +18,16 @@ var _ datasource.StatusStore = &StatusStore{} // StatusStore is a mock implementation of datasource.StatusStore. // -// func TestSomethingThatUsesdatasource.StatusStore(t *testing.T) { +// func TestSomethingThatUsesStatusStore(t *testing.T) { // // // make and configure a mocked datasource.StatusStore -// mockeddatasource.StatusStore := &StatusStore{ +// mockedStatusStore := &StatusStore{ // UpdateDataSourceStatusFunc: func(ctx context.Context, id xid.ID, organizationID string, status processor.ConnectionStatus) error { // panic("mock out the UpdateDataSourceStatus method") // }, // } // -// // use mockeddatasource.StatusStore in code that requires datasource.StatusStore +// // use mockedStatusStore in code that requires datasource.StatusStore // // and then make assertions. // // } @@ -41,8 +41,8 @@ type StatusStore struct { UpdateDataSourceStatus []struct { // Ctx is the ctx argument value. Ctx context.Context - // Id is the id argument value. - Id xid.ID + // ID is the id argument value. + ID xid.ID // OrganizationID is the organizationID argument value. OrganizationID string // Status is the status argument value. @@ -56,12 +56,12 @@ type StatusStore struct { func (mock *StatusStore) UpdateDataSourceStatus(ctx context.Context, id xid.ID, organizationID string, status processor.ConnectionStatus) error { callInfo := struct { Ctx context.Context - Id xid.ID + ID xid.ID OrganizationID string Status processor.ConnectionStatus }{ Ctx: ctx, - Id: id, + ID: id, OrganizationID: organizationID, Status: status, } @@ -80,16 +80,16 @@ func (mock *StatusStore) UpdateDataSourceStatus(ctx context.Context, id xid.ID, // UpdateDataSourceStatusCalls gets all the calls that were made to UpdateDataSourceStatus. // Check the length with: // -// len(mockeddatasource.StatusStore.UpdateDataSourceStatusCalls()) +// len(mockedStatusStore.UpdateDataSourceStatusCalls()) func (mock *StatusStore) UpdateDataSourceStatusCalls() []struct { Ctx context.Context - Id xid.ID + ID xid.ID OrganizationID string Status processor.ConnectionStatus } { var calls []struct { Ctx context.Context - Id xid.ID + ID xid.ID OrganizationID string Status processor.ConnectionStatus } diff --git a/server/core/internal/datasource/runner.go b/server/core/internal/datasource/runner.go index 66932392..4dc31430 100644 --- a/server/core/internal/datasource/runner.go +++ b/server/core/internal/datasource/runner.go @@ -287,7 +287,7 @@ type Prometheus interface { // SQL represents a SQL-based data source processor. // -//go:generate ../../scripts/codegen/mock SQL +//go:generate ../../scripts/codegen/mock SQL sql type SQL interface { connectionTester @@ -300,7 +300,7 @@ type SQL interface { // PostgreSQL represents a PostgreSQL data source processor. // -//go:generate ../../scripts/codegen/mock PostgreSQL +//go:generate ../../scripts/codegen/mock PostgreSQL postgresql type PostgreSQL interface { SQL @@ -310,7 +310,7 @@ type PostgreSQL interface { // MySQL represents a MySQL data source processor. // -//go:generate ../../scripts/codegen/mock MySQL +//go:generate ../../scripts/codegen/mock MySQL mysql type MySQL interface { SQL diff --git a/server/core/internal/datasource/runner_test.go b/server/core/internal/datasource/runner_test.go index d63080ec..2b52b633 100644 --- a/server/core/internal/datasource/runner_test.go +++ b/server/core/internal/datasource/runner_test.go @@ -344,7 +344,7 @@ func Test_connect(t *testing.T) { ff := store.UpdateDataSourceStatusCalls() require.Len(t, ff, 1) - assert.Equal(t, r.ds.ID, ff[0].Id) + assert.Equal(t, r.ds.ID, ff[0].ID) assert.Equal(t, "org", ff[0].OrganizationID) assert.Equal(t, processor.ConnectionStatusSuccess, ff[0].Status) diff --git a/server/core/internal/datasource/simulation/simulation.go b/server/core/internal/datasource/simulation/simulation.go index 2383a945..fb10b0ba 100644 --- a/server/core/internal/datasource/simulation/simulation.go +++ b/server/core/internal/datasource/simulation/simulation.go @@ -30,8 +30,8 @@ var ErrNotSimulated = errutil.New( // Result is what running a simulated metric block reports back. type Result struct { - // Cleared reports whether the block's real data has arrived and the - // simulation has been taken off it. + // Cleared indicates whether the block's real data has arrived and + // the simulation has been switched off. Cleared bool `json:"cleared"` } @@ -100,8 +100,8 @@ var _probeSpans = map[string]time.Duration{ // rows. const _queryQuery = "query" -// Checker probes the data source of a simulated metric block and takes -// the simulation off the block once real data answers. +// Checker probes the data source of a simulated metric block and +// switches the simulation off once real data answers. type Checker struct { // log is the component logger. log *slog.Logger @@ -112,7 +112,7 @@ type Checker struct { // runners hands out the client that speaks to a data source. runners Runners - // applier writes the cleared attribute onto the live document. + // applier writes the switched-off flag onto the live document. applier Applier // results remembers each block's last verdict for _resultTTL. @@ -141,7 +141,7 @@ func (c *Checker) Start(ctx context.Context) { c.results.Start(ctx) } -// Check reports whether the simulation was taken off the block, probing +// Check reports whether the block's simulation was switched off, probing // the block's data source when no recent verdict is remembered. A data // source that cannot be reached, or that answers with nothing, leaves the // block simulating and is not an error: it is the state the simulation @@ -152,7 +152,7 @@ func (c *Checker) Check( block document.Block, organizationID string, ) (Result, error) { - if _, simulated := block.Attrs.Value(document.AttrSimulationPreset); !simulated { + if !simulated(block) { return Result{}, ErrNotSimulated } @@ -304,7 +304,8 @@ func (c *Checker) query( } } -// clear takes the simulation off the block on the live document. +// clear switches the block's simulation off on the live document. The +// preset stays, so the block remembers which series it drew. func (c *Checker) clear( ctx context.Context, documentID, branchID xid.ID, @@ -312,7 +313,7 @@ func (c *Checker) clear( ) error { res, err := c.applier.Apply(ctx, documentID, branchID, []edit.Operation{ edit.UpdateAttrs(blockUID, map[string]any{ - document.AttrSimulationPreset: nil, + document.AttrSimulationActive: false, }), }, true) if err != nil { @@ -342,6 +343,21 @@ func cacheKey(documentID, branchID xid.ID, blockUID string) string { return documentID.String() + "/" + branchID.String() + "/" + blockUID } +// simulated reports whether the block draws generated data: it names a +// preset and its simulation is switched on. +func simulated(block document.Block) bool { + if _, ok := block.Attrs.Value(document.AttrSimulationPreset); !ok { + return false + } + + active, ok := block.Attrs.Get(document.AttrSimulationActive) + if !ok { + return false + } + + return active.Bool() +} + // probeSpan reads how far back the block's window reaches. func probeSpan(block document.Block) time.Duration { raw, ok := block.Attrs.Value(document.AttrTimeRange) diff --git a/server/core/internal/datasource/simulation/simulation_test.go b/server/core/internal/datasource/simulation/simulation_test.go index a624cccd..f051c2a0 100644 --- a/server/core/internal/datasource/simulation/simulation_test.go +++ b/server/core/internal/datasource/simulation/simulation_test.go @@ -45,6 +45,7 @@ func metricAttrs() document.Attributes { map[string]any{"name": "Query 1", "query": "up", "legendFormat": ""}, }, document.AttrSimulationPreset: "cpu_usage", + document.AttrSimulationActive: true, } } @@ -368,11 +369,26 @@ func Test_Checker_Check(t *testing.T) { }), Prometheus: sampled(), }, - "The block is not simulating": { + "The block names no preset": { Attrs: withoutAttr(document.AttrSimulationPreset), Prometheus: sampled(), Err: ErrNotSimulated, }, + "The simulation is switched off": { + Attrs: withAttr(document.AttrSimulationActive, false), + Prometheus: sampled(), + Err: ErrNotSimulated, + }, + "The block carries a preset and no flag": { + Attrs: withoutAttr(document.AttrSimulationActive), + Prometheus: sampled(), + Err: ErrNotSimulated, + }, + "The flag is not a boolean": { + Attrs: withAttr(document.AttrSimulationActive, "true"), + Prometheus: sampled(), + Err: ErrNotSimulated, + }, "The block carries no uid": { Attrs: withoutAttr(document.AttrUID), Prometheus: sampled(), @@ -499,7 +515,7 @@ func Test_Checker_Check(t *testing.T) { assert.JSONEq( t, - `{"kind":"update_attrs","block_uid":"block-1","attrs":{"simulationPreset":null}}`, + `{"kind":"update_attrs","block_uid":"block-1","attrs":{"simulationActive":false}}`, string(raw), ) } diff --git a/server/core/internal/document/attribute_keys.go b/server/core/internal/document/attribute_keys.go index 8b83584d..e7751e19 100644 --- a/server/core/internal/document/attribute_keys.go +++ b/server/core/internal/document/attribute_keys.go @@ -87,9 +87,15 @@ const ( AttrAxisBoundsMax = "axisBoundsMax" // AttrSimulationPreset names the generated series a metric block - // draws while its data source has no real data to answer with. It - // is unset on a block that queries normally. + // draws while AttrSimulationActive is set. It is unset on a block + // nobody has simulated. Once set, it stays after the simulation ends. AttrSimulationPreset = "simulationPreset" + + // AttrSimulationActive is true while a metric block draws its + // AttrSimulationPreset because its data source has no real data yet. + // Only the editor and core use it. Tools and document readers never + // see it. + AttrSimulationActive = "simulationActive" ) // MarkComment is the inline mark type anchoring a comment to a range of diff --git a/server/core/internal/search/manager/0mock_db_test.go b/server/core/internal/search/manager/0mock_db_test.go index 893783af..0d7d1e43 100644 --- a/server/core/internal/search/manager/0mock_db_test.go +++ b/server/core/internal/search/manager/0mock_db_test.go @@ -5,10 +5,11 @@ package manager import ( "context" + "sync" + "github.com/oxynote/oxynote/server/core/internal/document" "github.com/oxynote/oxynote/server/core/internal/search" "github.com/rs/xid" - "sync" ) // Ensure, that DBMock does implement DB. @@ -150,10 +151,10 @@ func (mock *DBMock) FetchDocumentBranchesUnsafe(ctx context.Context, docID xid.I mock.lockFetchDocumentBranchesUnsafe.Unlock() if mock.FetchDocumentBranchesUnsafeFunc == nil { var ( - out0 []document.BranchSummary - errOut error + branchSummarysOut []document.BranchSummary + errOut error ) - return out0, errOut + return branchSummarysOut, errOut } return mock.FetchDocumentBranchesUnsafeFunc(ctx, docID) } @@ -190,10 +191,10 @@ func (mock *DBMock) FetchDocumentUnsafeByBranchID(ctx context.Context, branchID mock.lockFetchDocumentUnsafeByBranchID.Unlock() if mock.FetchDocumentUnsafeByBranchIDFunc == nil { var ( - out0 *document.Document - errOut error + documentOut *document.Document + errOut error ) - return out0, errOut + return documentOut, errOut } return mock.FetchDocumentUnsafeByBranchIDFunc(ctx, branchID) } @@ -232,10 +233,10 @@ func (mock *DBMock) FetchSearchJobs(ctx context.Context, offsetID int64, limit i mock.lockFetchSearchJobs.Unlock() if mock.FetchSearchJobsFunc == nil { var ( - out0 []search.Job - errOut error + jobsOut []search.Job + errOut error ) - return out0, errOut + return jobsOut, errOut } return mock.FetchSearchJobsFunc(ctx, offsetID, limit) } diff --git a/server/core/internal/search/manager/0mock_index_test.go b/server/core/internal/search/manager/0mock_index_test.go index 1b5d8af3..2b36e9a4 100644 --- a/server/core/internal/search/manager/0mock_index_test.go +++ b/server/core/internal/search/manager/0mock_index_test.go @@ -5,9 +5,10 @@ package manager import ( "context" + "sync" + "github.com/oxynote/oxynote/server/core/internal/search" "github.com/rs/xid" - "sync" ) // Ensure, that IndexMock does implement Index. diff --git a/server/core/internal/server/0mock_db_test.go b/server/core/internal/server/0mock_db_test.go index 77a907bd..7d763ca7 100644 --- a/server/core/internal/server/0mock_db_test.go +++ b/server/core/internal/server/0mock_db_test.go @@ -9,14 +9,14 @@ import ( "github.com/guregu/null/v5" slackCore "github.com/oxynote/oxynote/server/core/internal/apps/slack" - "github.com/oxynote/oxynote/server/core/internal/datasource" - documentCore "github.com/oxynote/oxynote/server/core/internal/document" + datasourceCore "github.com/oxynote/oxynote/server/core/internal/datasource" + "github.com/oxynote/oxynote/server/core/internal/document" "github.com/oxynote/oxynote/server/core/internal/document/comment" "github.com/oxynote/oxynote/server/core/internal/document/file" "github.com/oxynote/oxynote/server/core/internal/document/hook" notificationCore "github.com/oxynote/oxynote/server/core/internal/notification" "github.com/oxynote/oxynote/server/core/internal/search" - tagCore "github.com/oxynote/oxynote/server/core/internal/tag" + "github.com/oxynote/oxynote/server/core/internal/tag" "github.com/oxynote/oxynote/server/core/pkg/httpserver" "github.com/rs/xid" ) @@ -97,31 +97,34 @@ var _ DB = &DBMock{} // DeleteTagFunc: func(ctx context.Context, id xid.ID, organizationID string) error { // panic("mock out the DeleteTag method") // }, -// FetchBranchReviewerFunc: func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) { +// DetachDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { +// panic("mock out the DetachDocumentHooksByBranchID method") +// }, +// FetchBranchReviewerFunc: func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*document.BranchReviewer, error) { // panic("mock out the FetchBranchReviewer method") // }, -// FetchBranchReviewersFunc: func(ctx context.Context, branchID xid.ID, organizationID string) ([]documentCore.BranchReviewer, error) { +// FetchBranchReviewersFunc: func(ctx context.Context, branchID xid.ID, organizationID string) ([]document.BranchReviewer, error) { // panic("mock out the FetchBranchReviewers method") // }, // FetchBranchTagIDsFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]xid.ID, error) { // panic("mock out the FetchBranchTagIDs method") // }, -// FetchDataSourceFunc: func(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { +// FetchDataSourceFunc: func(ctx context.Context, id xid.ID, organizationID string) (*datasourceCore.DataSource, error) { // panic("mock out the FetchDataSource method") // }, -// FetchDataSourcesFunc: func(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { +// FetchDataSourcesFunc: func(ctx context.Context, organizationID string) ([]datasourceCore.DataSource, error) { // panic("mock out the FetchDataSources method") // }, -// FetchDocumentFunc: func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*documentCore.Document, error) { +// FetchDocumentFunc: func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) { // panic("mock out the FetchDocument method") // }, -// FetchDocumentBranchesFunc: func(ctx context.Context, docID xid.ID, organizationID string) ([]documentCore.BranchSummary, error) { +// FetchDocumentBranchesFunc: func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) { // panic("mock out the FetchDocumentBranches method") // }, -// FetchDocumentBranchesUnsafeFunc: func(ctx context.Context, docID xid.ID) ([]documentCore.BranchSummary, error) { +// FetchDocumentBranchesUnsafeFunc: func(ctx context.Context, docID xid.ID) ([]document.BranchSummary, error) { // panic("mock out the FetchDocumentBranchesUnsafe method") // }, -// FetchDocumentByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) (*documentCore.Document, error) { +// FetchDocumentByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) { // panic("mock out the FetchDocumentByBranchID method") // }, // FetchDocumentCommentFunc: func(ctx context.Context, id xid.ID, documentID xid.ID, organizationID string) (*comment.Comment, error) { @@ -151,13 +154,13 @@ var _ DB = &DBMock{} // FetchDocumentMaintainersFunc: func(ctx context.Context, documentID xid.ID, organizationID string) ([]string, error) { // panic("mock out the FetchDocumentMaintainers method") // }, -// FetchDocumentTreeFunc: func(ctx context.Context, organizationID string) (documentCore.Summaries, error) { +// FetchDocumentTreeFunc: func(ctx context.Context, organizationID string) (document.Summaries, error) { // panic("mock out the FetchDocumentTree method") // }, -// FetchDocumentTreeByDocumentParentIDFunc: func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (documentCore.Summaries, error) { +// FetchDocumentTreeByDocumentParentIDFunc: func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) { // panic("mock out the FetchDocumentTreeByDocumentParentID method") // }, -// FetchDocumentUnsafeByBranchIDFunc: func(ctx context.Context, branchID xid.ID) (*documentCore.Document, error) { +// FetchDocumentUnsafeByBranchIDFunc: func(ctx context.Context, branchID xid.ID) (*document.Document, error) { // panic("mock out the FetchDocumentUnsafeByBranchID method") // }, // FetchGithubInstallationByOrganizationIDFunc: func(ctx context.Context, organizationID string) (int64, error) { @@ -190,19 +193,19 @@ var _ DB = &DBMock{} // FetchSlackUserLinkByUserIDFunc: func(ctx context.Context, userID string, organizationID string) (*slackCore.UserLink, error) { // panic("mock out the FetchSlackUserLinkByUserID method") // }, -// FetchTagTreeFunc: func(ctx context.Context, organizationID string, userID string) (tagCore.Summaries, error) { +// FetchTagTreeFunc: func(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) { // panic("mock out the FetchTagTree method") // }, -// InsertBranchReviewerFunc: func(ctx context.Context, reviewer documentCore.BranchReviewer) error { +// InsertBranchReviewerFunc: func(ctx context.Context, reviewer document.BranchReviewer) error { // panic("mock out the InsertBranchReviewer method") // }, -// InsertDataSourceFunc: func(ctx context.Context, ds *datasource.DataSource) error { +// InsertDataSourceFunc: func(ctx context.Context, ds *datasourceCore.DataSource) error { // panic("mock out the InsertDataSource method") // }, -// InsertDocumentFunc: func(ctx context.Context, doc documentCore.Document) error { +// InsertDocumentFunc: func(ctx context.Context, doc document.Document) error { // panic("mock out the InsertDocument method") // }, -// InsertDocumentBranchFunc: func(ctx context.Context, doc documentCore.Document) error { +// InsertDocumentBranchFunc: func(ctx context.Context, doc document.Document) error { // panic("mock out the InsertDocumentBranch method") // }, // InsertDocumentCommentFunc: func(ctx context.Context, c comment.Comment) error { @@ -217,12 +220,12 @@ var _ DB = &DBMock{} // InsertDocumentHookFunc: func(ctx context.Context, hk hook.Hook) error { // panic("mock out the InsertDocumentHook method") // }, -// InsertSearchJobFunc: func(ctx context.Context, job search.Job) error { -// panic("mock out the InsertSearchJob method") -// }, // InsertGithubInstallationFunc: func(ctx context.Context, installationID int64) error { // panic("mock out the InsertGithubInstallation method") // }, +// InsertSearchJobFunc: func(ctx context.Context, job search.Job) error { +// panic("mock out the InsertSearchJob method") +// }, // InsertSlackAppFunc: func(ctx context.Context, app slackCore.App) error { // panic("mock out the InsertSlackApp method") // }, @@ -232,7 +235,7 @@ var _ DB = &DBMock{} // InsertSlackUserLinkFunc: func(ctx context.Context, link slackCore.UserLink) error { // panic("mock out the InsertSlackUserLink method") // }, -// InsertTagFunc: func(ctx context.Context, t tagCore.Tag) error { +// InsertTagFunc: func(ctx context.Context, t tag.Tag) error { // panic("mock out the InsertTag method") // }, // MarkReadByNotificationsIDsFunc: func(ctx context.Context, organizationID string, userID string, ids []xid.ID) error { @@ -247,12 +250,9 @@ var _ DB = &DBMock{} // ReplaceDocumentCommentFunc: func(ctx context.Context, c comment.Comment) error { // panic("mock out the ReplaceDocumentComment method") // }, -// SetTagVisibilityFunc: func(ctx context.Context, organizationID string, userID string, id xid.ID, inp tagCore.VisibilityInput) error { +// SetTagVisibilityFunc: func(ctx context.Context, organizationID string, userID string, id xid.ID, inp tag.VisibilityInput) error { // panic("mock out the SetTagVisibility method") // }, -// DetachDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { -// panic("mock out the DetachDocumentHooksByBranchID method") -// }, // UnassignBranchTagFunc: func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { // panic("mock out the UnassignBranchTag method") // }, @@ -262,16 +262,16 @@ var _ DB = &DBMock{} // UnassignSlackAppOrganizationFunc: func(ctx context.Context, organizationID string) error { // panic("mock out the UnassignSlackAppOrganization method") // }, -// UpdateBranchReviewerFunc: func(ctx context.Context, reviewer documentCore.BranchReviewer) error { +// UpdateBranchReviewerFunc: func(ctx context.Context, reviewer document.BranchReviewer) error { // panic("mock out the UpdateBranchReviewer method") // }, -// UpdateDataSourceFunc: func(ctx context.Context, ds *datasource.DataSource) error { +// UpdateDataSourceFunc: func(ctx context.Context, ds *datasourceCore.DataSource) error { // panic("mock out the UpdateDataSource method") // }, -// UpdateDocumentFunc: func(ctx context.Context, doc documentCore.Document) error { +// UpdateDocumentFunc: func(ctx context.Context, doc document.Document) error { // panic("mock out the UpdateDocument method") // }, -// UpdateDocumentBranchMetadataFunc: func(ctx context.Context, doc documentCore.Document) error { +// UpdateDocumentBranchMetadataFunc: func(ctx context.Context, doc document.Document) error { // panic("mock out the UpdateDocumentBranchMetadata method") // }, // UpdateDocumentCommentFunc: func(ctx context.Context, c comment.Comment) error { @@ -286,7 +286,7 @@ var _ DB = &DBMock{} // UpdateDocumentParentIDFunc: func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error { // panic("mock out the UpdateDocumentParentID method") // }, -// UpdateDocumentTreeFunc: func(ctx context.Context, ss documentCore.Summaries, organizationID string) error { +// UpdateDocumentTreeFunc: func(ctx context.Context, ss document.Summaries, organizationID string) error { // panic("mock out the UpdateDocumentTree method") // }, // UpdateGithubInstallationOrganizationIDFunc: func(ctx context.Context, installationID int64, organizationID string) error { @@ -301,7 +301,7 @@ var _ DB = &DBMock{} // UpdateSlackUserLinkFunc: func(ctx context.Context, link slackCore.UserLink) error { // panic("mock out the UpdateSlackUserLink method") // }, -// UpdateTagTreeFunc: func(ctx context.Context, tree tagCore.Summaries, organizationID string) error { +// UpdateTagTreeFunc: func(ctx context.Context, tree tag.Summaries, organizationID string) error { // panic("mock out the UpdateTagTree method") // }, // UpdateUserImageFunc: func(ctx context.Context, userID string, image string) error { @@ -383,32 +383,35 @@ type DBMock struct { // DeleteTagFunc mocks the DeleteTag method. DeleteTagFunc func(ctx context.Context, id xid.ID, organizationID string) error + // DetachDocumentHooksByBranchIDFunc mocks the DetachDocumentHooksByBranchID method. + DetachDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error + // FetchBranchReviewerFunc mocks the FetchBranchReviewer method. - FetchBranchReviewerFunc func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) + FetchBranchReviewerFunc func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*document.BranchReviewer, error) // FetchBranchReviewersFunc mocks the FetchBranchReviewers method. - FetchBranchReviewersFunc func(ctx context.Context, branchID xid.ID, organizationID string) ([]documentCore.BranchReviewer, error) + FetchBranchReviewersFunc func(ctx context.Context, branchID xid.ID, organizationID string) ([]document.BranchReviewer, error) // FetchBranchTagIDsFunc mocks the FetchBranchTagIDs method. FetchBranchTagIDsFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID) ([]xid.ID, error) // FetchDataSourceFunc mocks the FetchDataSource method. - FetchDataSourceFunc func(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) + FetchDataSourceFunc func(ctx context.Context, id xid.ID, organizationID string) (*datasourceCore.DataSource, error) // FetchDataSourcesFunc mocks the FetchDataSources method. - FetchDataSourcesFunc func(ctx context.Context, organizationID string) ([]datasource.DataSource, error) + FetchDataSourcesFunc func(ctx context.Context, organizationID string) ([]datasourceCore.DataSource, error) // FetchDocumentFunc mocks the FetchDocument method. - FetchDocumentFunc func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*documentCore.Document, error) + FetchDocumentFunc func(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) // FetchDocumentBranchesFunc mocks the FetchDocumentBranches method. - FetchDocumentBranchesFunc func(ctx context.Context, docID xid.ID, organizationID string) ([]documentCore.BranchSummary, error) + FetchDocumentBranchesFunc func(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) // FetchDocumentBranchesUnsafeFunc mocks the FetchDocumentBranchesUnsafe method. - FetchDocumentBranchesUnsafeFunc func(ctx context.Context, docID xid.ID) ([]documentCore.BranchSummary, error) + FetchDocumentBranchesUnsafeFunc func(ctx context.Context, docID xid.ID) ([]document.BranchSummary, error) // FetchDocumentByBranchIDFunc mocks the FetchDocumentByBranchID method. - FetchDocumentByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) (*documentCore.Document, error) + FetchDocumentByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) // FetchDocumentCommentFunc mocks the FetchDocumentComment method. FetchDocumentCommentFunc func(ctx context.Context, id xid.ID, documentID xid.ID, organizationID string) (*comment.Comment, error) @@ -438,13 +441,13 @@ type DBMock struct { FetchDocumentMaintainersFunc func(ctx context.Context, documentID xid.ID, organizationID string) ([]string, error) // FetchDocumentTreeFunc mocks the FetchDocumentTree method. - FetchDocumentTreeFunc func(ctx context.Context, organizationID string) (documentCore.Summaries, error) + FetchDocumentTreeFunc func(ctx context.Context, organizationID string) (document.Summaries, error) // FetchDocumentTreeByDocumentParentIDFunc mocks the FetchDocumentTreeByDocumentParentID method. - FetchDocumentTreeByDocumentParentIDFunc func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (documentCore.Summaries, error) + FetchDocumentTreeByDocumentParentIDFunc func(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) // FetchDocumentUnsafeByBranchIDFunc mocks the FetchDocumentUnsafeByBranchID method. - FetchDocumentUnsafeByBranchIDFunc func(ctx context.Context, branchID xid.ID) (*documentCore.Document, error) + FetchDocumentUnsafeByBranchIDFunc func(ctx context.Context, branchID xid.ID) (*document.Document, error) // FetchGithubInstallationByOrganizationIDFunc mocks the FetchGithubInstallationByOrganizationID method. FetchGithubInstallationByOrganizationIDFunc func(ctx context.Context, organizationID string) (int64, error) @@ -477,19 +480,19 @@ type DBMock struct { FetchSlackUserLinkByUserIDFunc func(ctx context.Context, userID string, organizationID string) (*slackCore.UserLink, error) // FetchTagTreeFunc mocks the FetchTagTree method. - FetchTagTreeFunc func(ctx context.Context, organizationID string, userID string) (tagCore.Summaries, error) + FetchTagTreeFunc func(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) // InsertBranchReviewerFunc mocks the InsertBranchReviewer method. - InsertBranchReviewerFunc func(ctx context.Context, reviewer documentCore.BranchReviewer) error + InsertBranchReviewerFunc func(ctx context.Context, reviewer document.BranchReviewer) error // InsertDataSourceFunc mocks the InsertDataSource method. - InsertDataSourceFunc func(ctx context.Context, ds *datasource.DataSource) error + InsertDataSourceFunc func(ctx context.Context, ds *datasourceCore.DataSource) error // InsertDocumentFunc mocks the InsertDocument method. - InsertDocumentFunc func(ctx context.Context, doc documentCore.Document) error + InsertDocumentFunc func(ctx context.Context, doc document.Document) error // InsertDocumentBranchFunc mocks the InsertDocumentBranch method. - InsertDocumentBranchFunc func(ctx context.Context, doc documentCore.Document) error + InsertDocumentBranchFunc func(ctx context.Context, doc document.Document) error // InsertDocumentCommentFunc mocks the InsertDocumentComment method. InsertDocumentCommentFunc func(ctx context.Context, c comment.Comment) error @@ -503,12 +506,12 @@ type DBMock struct { // InsertDocumentHookFunc mocks the InsertDocumentHook method. InsertDocumentHookFunc func(ctx context.Context, hk hook.Hook) error - // InsertSearchJobFunc mocks the InsertSearchJob method. - InsertSearchJobFunc func(ctx context.Context, job search.Job) error - // InsertGithubInstallationFunc mocks the InsertGithubInstallation method. InsertGithubInstallationFunc func(ctx context.Context, installationID int64) error + // InsertSearchJobFunc mocks the InsertSearchJob method. + InsertSearchJobFunc func(ctx context.Context, job search.Job) error + // InsertSlackAppFunc mocks the InsertSlackApp method. InsertSlackAppFunc func(ctx context.Context, app slackCore.App) error @@ -519,7 +522,7 @@ type DBMock struct { InsertSlackUserLinkFunc func(ctx context.Context, link slackCore.UserLink) error // InsertTagFunc mocks the InsertTag method. - InsertTagFunc func(ctx context.Context, t tagCore.Tag) error + InsertTagFunc func(ctx context.Context, t tag.Tag) error // MarkReadByNotificationsIDsFunc mocks the MarkReadByNotificationsIDs method. MarkReadByNotificationsIDsFunc func(ctx context.Context, organizationID string, userID string, ids []xid.ID) error @@ -534,10 +537,7 @@ type DBMock struct { ReplaceDocumentCommentFunc func(ctx context.Context, c comment.Comment) error // SetTagVisibilityFunc mocks the SetTagVisibility method. - SetTagVisibilityFunc func(ctx context.Context, organizationID string, userID string, id xid.ID, inp tagCore.VisibilityInput) error - - // DetachDocumentHooksByBranchIDFunc mocks the DetachDocumentHooksByBranchID method. - DetachDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error + SetTagVisibilityFunc func(ctx context.Context, organizationID string, userID string, id xid.ID, inp tag.VisibilityInput) error // UnassignBranchTagFunc mocks the UnassignBranchTag method. UnassignBranchTagFunc func(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error @@ -549,16 +549,16 @@ type DBMock struct { UnassignSlackAppOrganizationFunc func(ctx context.Context, organizationID string) error // UpdateBranchReviewerFunc mocks the UpdateBranchReviewer method. - UpdateBranchReviewerFunc func(ctx context.Context, reviewer documentCore.BranchReviewer) error + UpdateBranchReviewerFunc func(ctx context.Context, reviewer document.BranchReviewer) error // UpdateDataSourceFunc mocks the UpdateDataSource method. - UpdateDataSourceFunc func(ctx context.Context, ds *datasource.DataSource) error + UpdateDataSourceFunc func(ctx context.Context, ds *datasourceCore.DataSource) error // UpdateDocumentFunc mocks the UpdateDocument method. - UpdateDocumentFunc func(ctx context.Context, doc documentCore.Document) error + UpdateDocumentFunc func(ctx context.Context, doc document.Document) error // UpdateDocumentBranchMetadataFunc mocks the UpdateDocumentBranchMetadata method. - UpdateDocumentBranchMetadataFunc func(ctx context.Context, doc documentCore.Document) error + UpdateDocumentBranchMetadataFunc func(ctx context.Context, doc document.Document) error // UpdateDocumentCommentFunc mocks the UpdateDocumentComment method. UpdateDocumentCommentFunc func(ctx context.Context, c comment.Comment) error @@ -573,7 +573,7 @@ type DBMock struct { UpdateDocumentParentIDFunc func(ctx context.Context, id xid.ID, parentID null.Value[xid.ID], organizationID string) error // UpdateDocumentTreeFunc mocks the UpdateDocumentTree method. - UpdateDocumentTreeFunc func(ctx context.Context, ss documentCore.Summaries, organizationID string) error + UpdateDocumentTreeFunc func(ctx context.Context, ss document.Summaries, organizationID string) error // UpdateGithubInstallationOrganizationIDFunc mocks the UpdateGithubInstallationOrganizationID method. UpdateGithubInstallationOrganizationIDFunc func(ctx context.Context, installationID int64, organizationID string) error @@ -588,7 +588,7 @@ type DBMock struct { UpdateSlackUserLinkFunc func(ctx context.Context, link slackCore.UserLink) error // UpdateTagTreeFunc mocks the UpdateTagTree method. - UpdateTagTreeFunc func(ctx context.Context, tree tagCore.Summaries, organizationID string) error + UpdateTagTreeFunc func(ctx context.Context, tree tag.Summaries, organizationID string) error // UpdateUserImageFunc mocks the UpdateUserImage method. UpdateUserImageFunc func(ctx context.Context, userID string, image string) error @@ -796,6 +796,15 @@ type DBMock struct { // OrganizationID is the organizationID argument value. OrganizationID string } + // DetachDocumentHooksByBranchID holds details about calls to the DetachDocumentHooksByBranchID method. + DetachDocumentHooksByBranchID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // BranchID is the branchID argument value. + BranchID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } // FetchBranchReviewer holds details about calls to the FetchBranchReviewer method. FetchBranchReviewer []struct { // Ctx is the ctx argument value. @@ -1083,28 +1092,28 @@ type DBMock struct { // Ctx is the ctx argument value. Ctx context.Context // Reviewer is the reviewer argument value. - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer } // InsertDataSource holds details about calls to the InsertDataSource method. InsertDataSource []struct { // Ctx is the ctx argument value. Ctx context.Context // Ds is the ds argument value. - Ds *datasource.DataSource + Ds *datasourceCore.DataSource } // InsertDocument holds details about calls to the InsertDocument method. InsertDocument []struct { // Ctx is the ctx argument value. Ctx context.Context // Doc is the doc argument value. - Doc documentCore.Document + Doc document.Document } // InsertDocumentBranch holds details about calls to the InsertDocumentBranch method. InsertDocumentBranch []struct { // Ctx is the ctx argument value. Ctx context.Context // Doc is the doc argument value. - Doc documentCore.Document + Doc document.Document } // InsertDocumentComment holds details about calls to the InsertDocumentComment method. InsertDocumentComment []struct { @@ -1134,13 +1143,6 @@ type DBMock struct { // Hk is the hk argument value. Hk hook.Hook } - // InsertSearchJob holds details about calls to the InsertSearchJob method. - InsertSearchJob []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Job is the job argument value. - Job search.Job - } // InsertGithubInstallation holds details about calls to the InsertGithubInstallation method. InsertGithubInstallation []struct { // Ctx is the ctx argument value. @@ -1148,6 +1150,13 @@ type DBMock struct { // InstallationID is the installationID argument value. InstallationID int64 } + // InsertSearchJob holds details about calls to the InsertSearchJob method. + InsertSearchJob []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Job is the job argument value. + Job search.Job + } // InsertSlackApp holds details about calls to the InsertSlackApp method. InsertSlackApp []struct { // Ctx is the ctx argument value. @@ -1174,7 +1183,7 @@ type DBMock struct { // Ctx is the ctx argument value. Ctx context.Context // T is the t argument value. - T tagCore.Tag + T tag.Tag } // MarkReadByNotificationsIDs holds details about calls to the MarkReadByNotificationsIDs method. MarkReadByNotificationsIDs []struct { @@ -1227,16 +1236,7 @@ type DBMock struct { // ID is the id argument value. ID xid.ID // Inp is the inp argument value. - Inp tagCore.VisibilityInput - } - // DetachDocumentHooksByBranchID holds details about calls to the DetachDocumentHooksByBranchID method. - DetachDocumentHooksByBranchID []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // BranchID is the branchID argument value. - BranchID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string + Inp tag.VisibilityInput } // UnassignBranchTag holds details about calls to the UnassignBranchTag method. UnassignBranchTag []struct { @@ -1270,28 +1270,28 @@ type DBMock struct { // Ctx is the ctx argument value. Ctx context.Context // Reviewer is the reviewer argument value. - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer } // UpdateDataSource holds details about calls to the UpdateDataSource method. UpdateDataSource []struct { // Ctx is the ctx argument value. Ctx context.Context // Ds is the ds argument value. - Ds *datasource.DataSource + Ds *datasourceCore.DataSource } // UpdateDocument holds details about calls to the UpdateDocument method. UpdateDocument []struct { // Ctx is the ctx argument value. Ctx context.Context // Doc is the doc argument value. - Doc documentCore.Document + Doc document.Document } // UpdateDocumentBranchMetadata holds details about calls to the UpdateDocumentBranchMetadata method. UpdateDocumentBranchMetadata []struct { // Ctx is the ctx argument value. Ctx context.Context // Doc is the doc argument value. - Doc documentCore.Document + Doc document.Document } // UpdateDocumentComment holds details about calls to the UpdateDocumentComment method. UpdateDocumentComment []struct { @@ -1330,7 +1330,7 @@ type DBMock struct { // Ctx is the ctx argument value. Ctx context.Context // Ss is the ss argument value. - Ss documentCore.Summaries + Ss document.Summaries // OrganizationID is the organizationID argument value. OrganizationID string } @@ -1373,7 +1373,7 @@ type DBMock struct { // Ctx is the ctx argument value. Ctx context.Context // Tree is the tree argument value. - Tree tagCore.Summaries + Tree tag.Summaries // OrganizationID is the organizationID argument value. OrganizationID string } @@ -1420,6 +1420,7 @@ type DBMock struct { lockDeleteSlackAppsByOrganizationID sync.RWMutex lockDeleteSlackUserLink sync.RWMutex lockDeleteTag sync.RWMutex + lockDetachDocumentHooksByBranchID sync.RWMutex lockFetchBranchReviewer sync.RWMutex lockFetchBranchReviewers sync.RWMutex lockFetchBranchTagIDs sync.RWMutex @@ -1460,8 +1461,8 @@ type DBMock struct { lockInsertDocumentCommentReply sync.RWMutex lockInsertDocumentFile sync.RWMutex lockInsertDocumentHook sync.RWMutex - lockInsertSearchJob sync.RWMutex lockInsertGithubInstallation sync.RWMutex + lockInsertSearchJob sync.RWMutex lockInsertSlackApp sync.RWMutex lockInsertSlackMessage sync.RWMutex lockInsertSlackUserLink sync.RWMutex @@ -1471,7 +1472,6 @@ type DBMock struct { lockReplaceBranchTags sync.RWMutex lockReplaceDocumentComment sync.RWMutex lockSetTagVisibility sync.RWMutex - lockDetachDocumentHooksByBranchID sync.RWMutex lockUnassignBranchTag sync.RWMutex lockUnassignGithubInstallationOrganization sync.RWMutex lockUnassignSlackAppOrganization sync.RWMutex @@ -1512,7 +1512,9 @@ func (mock *DBMock) AssignBranchTag(ctx context.Context, organizationID string, mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) mock.lockAssignBranchTag.Unlock() if mock.AssignBranchTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) @@ -1733,7 +1735,9 @@ func (mock *DBMock) CopyBranchTags(ctx context.Context, organizationID string, f mock.calls.CopyBranchTags = append(mock.calls.CopyBranchTags, callInfo) mock.lockCopyBranchTags.Unlock() if mock.CopyBranchTagsFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.CopyBranchTagsFunc(ctx, organizationID, fromBranchID, toBranchID) @@ -2411,7 +2415,9 @@ func (mock *DBMock) DeleteTag(ctx context.Context, id xid.ID, organizationID str mock.calls.DeleteTag = append(mock.calls.DeleteTag, callInfo) mock.lockDeleteTag.Unlock() if mock.DeleteTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.DeleteTagFunc(ctx, id, organizationID) @@ -2437,8 +2443,51 @@ func (mock *DBMock) DeleteTagCalls() []struct { return calls } +// DetachDocumentHooksByBranchID calls DetachDocumentHooksByBranchIDFunc. +func (mock *DBMock) DetachDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) error { + callInfo := struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + }{ + Ctx: ctx, + BranchID: branchID, + OrganizationID: organizationID, + } + mock.lockDetachDocumentHooksByBranchID.Lock() + mock.calls.DetachDocumentHooksByBranchID = append(mock.calls.DetachDocumentHooksByBranchID, callInfo) + mock.lockDetachDocumentHooksByBranchID.Unlock() + if mock.DetachDocumentHooksByBranchIDFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.DetachDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) +} + +// DetachDocumentHooksByBranchIDCalls gets all the calls that were made to DetachDocumentHooksByBranchID. +// Check the length with: +// +// len(mockedDB.DetachDocumentHooksByBranchIDCalls()) +func (mock *DBMock) DetachDocumentHooksByBranchIDCalls() []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + } + mock.lockDetachDocumentHooksByBranchID.RLock() + calls = mock.calls.DetachDocumentHooksByBranchID + mock.lockDetachDocumentHooksByBranchID.RUnlock() + return calls +} + // FetchBranchReviewer calls FetchBranchReviewerFunc. -func (mock *DBMock) FetchBranchReviewer(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) { +func (mock *DBMock) FetchBranchReviewer(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*document.BranchReviewer, error) { callInfo := struct { Ctx context.Context BranchID xid.ID @@ -2455,7 +2504,7 @@ func (mock *DBMock) FetchBranchReviewer(ctx context.Context, branchID xid.ID, us mock.lockFetchBranchReviewer.Unlock() if mock.FetchBranchReviewerFunc == nil { var ( - branchReviewerOut *documentCore.BranchReviewer + branchReviewerOut *document.BranchReviewer errOut error ) return branchReviewerOut, errOut @@ -2486,7 +2535,7 @@ func (mock *DBMock) FetchBranchReviewerCalls() []struct { } // FetchBranchReviewers calls FetchBranchReviewersFunc. -func (mock *DBMock) FetchBranchReviewers(ctx context.Context, branchID xid.ID, organizationID string) ([]documentCore.BranchReviewer, error) { +func (mock *DBMock) FetchBranchReviewers(ctx context.Context, branchID xid.ID, organizationID string) ([]document.BranchReviewer, error) { callInfo := struct { Ctx context.Context BranchID xid.ID @@ -2501,7 +2550,7 @@ func (mock *DBMock) FetchBranchReviewers(ctx context.Context, branchID xid.ID, o mock.lockFetchBranchReviewers.Unlock() if mock.FetchBranchReviewersFunc == nil { var ( - branchReviewersOut []documentCore.BranchReviewer + branchReviewersOut []document.BranchReviewer errOut error ) return branchReviewersOut, errOut @@ -2547,10 +2596,10 @@ func (mock *DBMock) FetchBranchTagIDs(ctx context.Context, organizationID string mock.lockFetchBranchTagIDs.Unlock() if mock.FetchBranchTagIDsFunc == nil { var ( - idsOut []xid.ID + iDsOut []xid.ID errOut error ) - return idsOut, errOut + return iDsOut, errOut } return mock.FetchBranchTagIDsFunc(ctx, organizationID, documentID, branchID) } @@ -2578,7 +2627,7 @@ func (mock *DBMock) FetchBranchTagIDsCalls() []struct { } // FetchDataSource calls FetchDataSourceFunc. -func (mock *DBMock) FetchDataSource(ctx context.Context, id xid.ID, organizationID string) (*datasource.DataSource, error) { +func (mock *DBMock) FetchDataSource(ctx context.Context, id xid.ID, organizationID string) (*datasourceCore.DataSource, error) { callInfo := struct { Ctx context.Context ID xid.ID @@ -2593,7 +2642,7 @@ func (mock *DBMock) FetchDataSource(ctx context.Context, id xid.ID, organization mock.lockFetchDataSource.Unlock() if mock.FetchDataSourceFunc == nil { var ( - dataSourceOut *datasource.DataSource + dataSourceOut *datasourceCore.DataSource errOut error ) return dataSourceOut, errOut @@ -2622,7 +2671,7 @@ func (mock *DBMock) FetchDataSourceCalls() []struct { } // FetchDataSources calls FetchDataSourcesFunc. -func (mock *DBMock) FetchDataSources(ctx context.Context, organizationID string) ([]datasource.DataSource, error) { +func (mock *DBMock) FetchDataSources(ctx context.Context, organizationID string) ([]datasourceCore.DataSource, error) { callInfo := struct { Ctx context.Context OrganizationID string @@ -2635,7 +2684,7 @@ func (mock *DBMock) FetchDataSources(ctx context.Context, organizationID string) mock.lockFetchDataSources.Unlock() if mock.FetchDataSourcesFunc == nil { var ( - dataSourcesOut []datasource.DataSource + dataSourcesOut []datasourceCore.DataSource errOut error ) return dataSourcesOut, errOut @@ -2662,7 +2711,7 @@ func (mock *DBMock) FetchDataSourcesCalls() []struct { } // FetchDocument calls FetchDocumentFunc. -func (mock *DBMock) FetchDocument(ctx context.Context, id xid.ID, organizationID string, branchName string) (*documentCore.Document, error) { +func (mock *DBMock) FetchDocument(ctx context.Context, id xid.ID, organizationID string, branchName string) (*document.Document, error) { callInfo := struct { Ctx context.Context ID xid.ID @@ -2679,7 +2728,7 @@ func (mock *DBMock) FetchDocument(ctx context.Context, id xid.ID, organizationID mock.lockFetchDocument.Unlock() if mock.FetchDocumentFunc == nil { var ( - documentOut *documentCore.Document + documentOut *document.Document errOut error ) return documentOut, errOut @@ -2710,7 +2759,7 @@ func (mock *DBMock) FetchDocumentCalls() []struct { } // FetchDocumentBranches calls FetchDocumentBranchesFunc. -func (mock *DBMock) FetchDocumentBranches(ctx context.Context, docID xid.ID, organizationID string) ([]documentCore.BranchSummary, error) { +func (mock *DBMock) FetchDocumentBranches(ctx context.Context, docID xid.ID, organizationID string) ([]document.BranchSummary, error) { callInfo := struct { Ctx context.Context DocID xid.ID @@ -2725,7 +2774,7 @@ func (mock *DBMock) FetchDocumentBranches(ctx context.Context, docID xid.ID, org mock.lockFetchDocumentBranches.Unlock() if mock.FetchDocumentBranchesFunc == nil { var ( - branchSummarysOut []documentCore.BranchSummary + branchSummarysOut []document.BranchSummary errOut error ) return branchSummarysOut, errOut @@ -2754,7 +2803,7 @@ func (mock *DBMock) FetchDocumentBranchesCalls() []struct { } // FetchDocumentBranchesUnsafe calls FetchDocumentBranchesUnsafeFunc. -func (mock *DBMock) FetchDocumentBranchesUnsafe(ctx context.Context, docID xid.ID) ([]documentCore.BranchSummary, error) { +func (mock *DBMock) FetchDocumentBranchesUnsafe(ctx context.Context, docID xid.ID) ([]document.BranchSummary, error) { callInfo := struct { Ctx context.Context DocID xid.ID @@ -2767,7 +2816,7 @@ func (mock *DBMock) FetchDocumentBranchesUnsafe(ctx context.Context, docID xid.I mock.lockFetchDocumentBranchesUnsafe.Unlock() if mock.FetchDocumentBranchesUnsafeFunc == nil { var ( - branchSummarysOut []documentCore.BranchSummary + branchSummarysOut []document.BranchSummary errOut error ) return branchSummarysOut, errOut @@ -2794,7 +2843,7 @@ func (mock *DBMock) FetchDocumentBranchesUnsafeCalls() []struct { } // FetchDocumentByBranchID calls FetchDocumentByBranchIDFunc. -func (mock *DBMock) FetchDocumentByBranchID(ctx context.Context, branchID xid.ID, organizationID string) (*documentCore.Document, error) { +func (mock *DBMock) FetchDocumentByBranchID(ctx context.Context, branchID xid.ID, organizationID string) (*document.Document, error) { callInfo := struct { Ctx context.Context BranchID xid.ID @@ -2809,7 +2858,7 @@ func (mock *DBMock) FetchDocumentByBranchID(ctx context.Context, branchID xid.ID mock.lockFetchDocumentByBranchID.Unlock() if mock.FetchDocumentByBranchIDFunc == nil { var ( - documentOut *documentCore.Document + documentOut *document.Document errOut error ) return documentOut, errOut @@ -3242,7 +3291,7 @@ func (mock *DBMock) FetchDocumentMaintainersCalls() []struct { } // FetchDocumentTree calls FetchDocumentTreeFunc. -func (mock *DBMock) FetchDocumentTree(ctx context.Context, organizationID string) (documentCore.Summaries, error) { +func (mock *DBMock) FetchDocumentTree(ctx context.Context, organizationID string) (document.Summaries, error) { callInfo := struct { Ctx context.Context OrganizationID string @@ -3255,7 +3304,7 @@ func (mock *DBMock) FetchDocumentTree(ctx context.Context, organizationID string mock.lockFetchDocumentTree.Unlock() if mock.FetchDocumentTreeFunc == nil { var ( - summariesOut documentCore.Summaries + summariesOut document.Summaries errOut error ) return summariesOut, errOut @@ -3282,7 +3331,7 @@ func (mock *DBMock) FetchDocumentTreeCalls() []struct { } // FetchDocumentTreeByDocumentParentID calls FetchDocumentTreeByDocumentParentIDFunc. -func (mock *DBMock) FetchDocumentTreeByDocumentParentID(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (documentCore.Summaries, error) { +func (mock *DBMock) FetchDocumentTreeByDocumentParentID(ctx context.Context, parentID null.Value[xid.ID], organizationID string) (document.Summaries, error) { callInfo := struct { Ctx context.Context ParentID null.Value[xid.ID] @@ -3297,7 +3346,7 @@ func (mock *DBMock) FetchDocumentTreeByDocumentParentID(ctx context.Context, par mock.lockFetchDocumentTreeByDocumentParentID.Unlock() if mock.FetchDocumentTreeByDocumentParentIDFunc == nil { var ( - summariesOut documentCore.Summaries + summariesOut document.Summaries errOut error ) return summariesOut, errOut @@ -3326,7 +3375,7 @@ func (mock *DBMock) FetchDocumentTreeByDocumentParentIDCalls() []struct { } // FetchDocumentUnsafeByBranchID calls FetchDocumentUnsafeByBranchIDFunc. -func (mock *DBMock) FetchDocumentUnsafeByBranchID(ctx context.Context, branchID xid.ID) (*documentCore.Document, error) { +func (mock *DBMock) FetchDocumentUnsafeByBranchID(ctx context.Context, branchID xid.ID) (*document.Document, error) { callInfo := struct { Ctx context.Context BranchID xid.ID @@ -3339,7 +3388,7 @@ func (mock *DBMock) FetchDocumentUnsafeByBranchID(ctx context.Context, branchID mock.lockFetchDocumentUnsafeByBranchID.Unlock() if mock.FetchDocumentUnsafeByBranchIDFunc == nil { var ( - documentOut *documentCore.Document + documentOut *document.Document errOut error ) return documentOut, errOut @@ -3791,7 +3840,7 @@ func (mock *DBMock) FetchSlackUserLinkByUserIDCalls() []struct { } // FetchTagTree calls FetchTagTreeFunc. -func (mock *DBMock) FetchTagTree(ctx context.Context, organizationID string, userID string) (tagCore.Summaries, error) { +func (mock *DBMock) FetchTagTree(ctx context.Context, organizationID string, userID string) (tag.Summaries, error) { callInfo := struct { Ctx context.Context OrganizationID string @@ -3806,7 +3855,7 @@ func (mock *DBMock) FetchTagTree(ctx context.Context, organizationID string, use mock.lockFetchTagTree.Unlock() if mock.FetchTagTreeFunc == nil { var ( - summariesOut tagCore.Summaries + summariesOut tag.Summaries errOut error ) return summariesOut, errOut @@ -3835,10 +3884,10 @@ func (mock *DBMock) FetchTagTreeCalls() []struct { } // InsertBranchReviewer calls InsertBranchReviewerFunc. -func (mock *DBMock) InsertBranchReviewer(ctx context.Context, reviewer documentCore.BranchReviewer) error { +func (mock *DBMock) InsertBranchReviewer(ctx context.Context, reviewer document.BranchReviewer) error { callInfo := struct { Ctx context.Context - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer }{ Ctx: ctx, Reviewer: reviewer, @@ -3861,11 +3910,11 @@ func (mock *DBMock) InsertBranchReviewer(ctx context.Context, reviewer documentC // len(mockedDB.InsertBranchReviewerCalls()) func (mock *DBMock) InsertBranchReviewerCalls() []struct { Ctx context.Context - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer } { var calls []struct { Ctx context.Context - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer } mock.lockInsertBranchReviewer.RLock() calls = mock.calls.InsertBranchReviewer @@ -3874,10 +3923,10 @@ func (mock *DBMock) InsertBranchReviewerCalls() []struct { } // InsertDataSource calls InsertDataSourceFunc. -func (mock *DBMock) InsertDataSource(ctx context.Context, ds *datasource.DataSource) error { +func (mock *DBMock) InsertDataSource(ctx context.Context, ds *datasourceCore.DataSource) error { callInfo := struct { Ctx context.Context - Ds *datasource.DataSource + Ds *datasourceCore.DataSource }{ Ctx: ctx, Ds: ds, @@ -3900,11 +3949,11 @@ func (mock *DBMock) InsertDataSource(ctx context.Context, ds *datasource.DataSou // len(mockedDB.InsertDataSourceCalls()) func (mock *DBMock) InsertDataSourceCalls() []struct { Ctx context.Context - Ds *datasource.DataSource + Ds *datasourceCore.DataSource } { var calls []struct { Ctx context.Context - Ds *datasource.DataSource + Ds *datasourceCore.DataSource } mock.lockInsertDataSource.RLock() calls = mock.calls.InsertDataSource @@ -3913,10 +3962,10 @@ func (mock *DBMock) InsertDataSourceCalls() []struct { } // InsertDocument calls InsertDocumentFunc. -func (mock *DBMock) InsertDocument(ctx context.Context, doc documentCore.Document) error { +func (mock *DBMock) InsertDocument(ctx context.Context, doc document.Document) error { callInfo := struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document }{ Ctx: ctx, Doc: doc, @@ -3939,11 +3988,11 @@ func (mock *DBMock) InsertDocument(ctx context.Context, doc documentCore.Documen // len(mockedDB.InsertDocumentCalls()) func (mock *DBMock) InsertDocumentCalls() []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } { var calls []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } mock.lockInsertDocument.RLock() calls = mock.calls.InsertDocument @@ -3952,10 +4001,10 @@ func (mock *DBMock) InsertDocumentCalls() []struct { } // InsertDocumentBranch calls InsertDocumentBranchFunc. -func (mock *DBMock) InsertDocumentBranch(ctx context.Context, doc documentCore.Document) error { +func (mock *DBMock) InsertDocumentBranch(ctx context.Context, doc document.Document) error { callInfo := struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document }{ Ctx: ctx, Doc: doc, @@ -3978,11 +4027,11 @@ func (mock *DBMock) InsertDocumentBranch(ctx context.Context, doc documentCore.D // len(mockedDB.InsertDocumentBranchCalls()) func (mock *DBMock) InsertDocumentBranchCalls() []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } { var calls []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } mock.lockInsertDocumentBranch.RLock() calls = mock.calls.InsertDocumentBranch @@ -4146,45 +4195,6 @@ func (mock *DBMock) InsertDocumentHookCalls() []struct { return calls } -// InsertSearchJob calls InsertSearchJobFunc. -func (mock *DBMock) InsertSearchJob(ctx context.Context, job search.Job) error { - callInfo := struct { - Ctx context.Context - Job search.Job - }{ - Ctx: ctx, - Job: job, - } - mock.lockInsertSearchJob.Lock() - mock.calls.InsertSearchJob = append(mock.calls.InsertSearchJob, callInfo) - mock.lockInsertSearchJob.Unlock() - if mock.InsertSearchJobFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.InsertSearchJobFunc(ctx, job) -} - -// InsertSearchJobCalls gets all the calls that were made to InsertSearchJob. -// Check the length with: -// -// len(mockedDB.InsertSearchJobCalls()) -func (mock *DBMock) InsertSearchJobCalls() []struct { - Ctx context.Context - Job search.Job -} { - var calls []struct { - Ctx context.Context - Job search.Job - } - mock.lockInsertSearchJob.RLock() - calls = mock.calls.InsertSearchJob - mock.lockInsertSearchJob.RUnlock() - return calls -} - // InsertGithubInstallation calls InsertGithubInstallationFunc. func (mock *DBMock) InsertGithubInstallation(ctx context.Context, installationID int64) error { callInfo := struct { @@ -4224,6 +4234,45 @@ func (mock *DBMock) InsertGithubInstallationCalls() []struct { return calls } +// InsertSearchJob calls InsertSearchJobFunc. +func (mock *DBMock) InsertSearchJob(ctx context.Context, job search.Job) error { + callInfo := struct { + Ctx context.Context + Job search.Job + }{ + Ctx: ctx, + Job: job, + } + mock.lockInsertSearchJob.Lock() + mock.calls.InsertSearchJob = append(mock.calls.InsertSearchJob, callInfo) + mock.lockInsertSearchJob.Unlock() + if mock.InsertSearchJobFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.InsertSearchJobFunc(ctx, job) +} + +// InsertSearchJobCalls gets all the calls that were made to InsertSearchJob. +// Check the length with: +// +// len(mockedDB.InsertSearchJobCalls()) +func (mock *DBMock) InsertSearchJobCalls() []struct { + Ctx context.Context + Job search.Job +} { + var calls []struct { + Ctx context.Context + Job search.Job + } + mock.lockInsertSearchJob.RLock() + calls = mock.calls.InsertSearchJob + mock.lockInsertSearchJob.RUnlock() + return calls +} + // InsertSlackApp calls InsertSlackAppFunc. func (mock *DBMock) InsertSlackApp(ctx context.Context, app slackCore.App) error { callInfo := struct { @@ -4342,10 +4391,10 @@ func (mock *DBMock) InsertSlackUserLinkCalls() []struct { } // InsertTag calls InsertTagFunc. -func (mock *DBMock) InsertTag(ctx context.Context, t tagCore.Tag) error { +func (mock *DBMock) InsertTag(ctx context.Context, t tag.Tag) error { callInfo := struct { Ctx context.Context - T tagCore.Tag + T tag.Tag }{ Ctx: ctx, T: t, @@ -4354,7 +4403,9 @@ func (mock *DBMock) InsertTag(ctx context.Context, t tagCore.Tag) error { mock.calls.InsertTag = append(mock.calls.InsertTag, callInfo) mock.lockInsertTag.Unlock() if mock.InsertTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.InsertTagFunc(ctx, t) @@ -4366,11 +4417,11 @@ func (mock *DBMock) InsertTag(ctx context.Context, t tagCore.Tag) error { // len(mockedDB.InsertTagCalls()) func (mock *DBMock) InsertTagCalls() []struct { Ctx context.Context - T tagCore.Tag + T tag.Tag } { var calls []struct { Ctx context.Context - T tagCore.Tag + T tag.Tag } mock.lockInsertTag.RLock() calls = mock.calls.InsertTag @@ -4489,7 +4540,9 @@ func (mock *DBMock) ReplaceBranchTags(ctx context.Context, organizationID string mock.calls.ReplaceBranchTags = append(mock.calls.ReplaceBranchTags, callInfo) mock.lockReplaceBranchTags.Unlock() if mock.ReplaceBranchTagsFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.ReplaceBranchTagsFunc(ctx, organizationID, fromBranchID, toBranchID) @@ -4557,13 +4610,13 @@ func (mock *DBMock) ReplaceDocumentCommentCalls() []struct { } // SetTagVisibility calls SetTagVisibilityFunc. -func (mock *DBMock) SetTagVisibility(ctx context.Context, organizationID string, userID string, id xid.ID, inp tagCore.VisibilityInput) error { +func (mock *DBMock) SetTagVisibility(ctx context.Context, organizationID string, userID string, id xid.ID, inp tag.VisibilityInput) error { callInfo := struct { Ctx context.Context OrganizationID string UserID string ID xid.ID - Inp tagCore.VisibilityInput + Inp tag.VisibilityInput }{ Ctx: ctx, OrganizationID: organizationID, @@ -4575,7 +4628,9 @@ func (mock *DBMock) SetTagVisibility(ctx context.Context, organizationID string, mock.calls.SetTagVisibility = append(mock.calls.SetTagVisibility, callInfo) mock.lockSetTagVisibility.Unlock() if mock.SetTagVisibilityFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.SetTagVisibilityFunc(ctx, organizationID, userID, id, inp) @@ -4590,14 +4645,14 @@ func (mock *DBMock) SetTagVisibilityCalls() []struct { OrganizationID string UserID string ID xid.ID - Inp tagCore.VisibilityInput + Inp tag.VisibilityInput } { var calls []struct { Ctx context.Context OrganizationID string UserID string ID xid.ID - Inp tagCore.VisibilityInput + Inp tag.VisibilityInput } mock.lockSetTagVisibility.RLock() calls = mock.calls.SetTagVisibility @@ -4605,49 +4660,6 @@ func (mock *DBMock) SetTagVisibilityCalls() []struct { return calls } -// DetachDocumentHooksByBranchID calls DetachDocumentHooksByBranchIDFunc. -func (mock *DBMock) DetachDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) error { - callInfo := struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - }{ - Ctx: ctx, - BranchID: branchID, - OrganizationID: organizationID, - } - mock.lockDetachDocumentHooksByBranchID.Lock() - mock.calls.DetachDocumentHooksByBranchID = append(mock.calls.DetachDocumentHooksByBranchID, callInfo) - mock.lockDetachDocumentHooksByBranchID.Unlock() - if mock.DetachDocumentHooksByBranchIDFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.DetachDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) -} - -// DetachDocumentHooksByBranchIDCalls gets all the calls that were made to DetachDocumentHooksByBranchID. -// Check the length with: -// -// len(mockedDB.DetachDocumentHooksByBranchIDCalls()) -func (mock *DBMock) DetachDocumentHooksByBranchIDCalls() []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - } - mock.lockDetachDocumentHooksByBranchID.RLock() - calls = mock.calls.DetachDocumentHooksByBranchID - mock.lockDetachDocumentHooksByBranchID.RUnlock() - return calls -} - // UnassignBranchTag calls UnassignBranchTagFunc. func (mock *DBMock) UnassignBranchTag(ctx context.Context, organizationID string, documentID xid.ID, branchID xid.ID, tagID xid.ID) error { callInfo := struct { @@ -4667,7 +4679,9 @@ func (mock *DBMock) UnassignBranchTag(ctx context.Context, organizationID string mock.calls.UnassignBranchTag = append(mock.calls.UnassignBranchTag, callInfo) mock.lockUnassignBranchTag.Unlock() if mock.UnassignBranchTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.UnassignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) @@ -4776,10 +4790,10 @@ func (mock *DBMock) UnassignSlackAppOrganizationCalls() []struct { } // UpdateBranchReviewer calls UpdateBranchReviewerFunc. -func (mock *DBMock) UpdateBranchReviewer(ctx context.Context, reviewer documentCore.BranchReviewer) error { +func (mock *DBMock) UpdateBranchReviewer(ctx context.Context, reviewer document.BranchReviewer) error { callInfo := struct { Ctx context.Context - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer }{ Ctx: ctx, Reviewer: reviewer, @@ -4802,11 +4816,11 @@ func (mock *DBMock) UpdateBranchReviewer(ctx context.Context, reviewer documentC // len(mockedDB.UpdateBranchReviewerCalls()) func (mock *DBMock) UpdateBranchReviewerCalls() []struct { Ctx context.Context - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer } { var calls []struct { Ctx context.Context - Reviewer documentCore.BranchReviewer + Reviewer document.BranchReviewer } mock.lockUpdateBranchReviewer.RLock() calls = mock.calls.UpdateBranchReviewer @@ -4815,10 +4829,10 @@ func (mock *DBMock) UpdateBranchReviewerCalls() []struct { } // UpdateDataSource calls UpdateDataSourceFunc. -func (mock *DBMock) UpdateDataSource(ctx context.Context, ds *datasource.DataSource) error { +func (mock *DBMock) UpdateDataSource(ctx context.Context, ds *datasourceCore.DataSource) error { callInfo := struct { Ctx context.Context - Ds *datasource.DataSource + Ds *datasourceCore.DataSource }{ Ctx: ctx, Ds: ds, @@ -4841,11 +4855,11 @@ func (mock *DBMock) UpdateDataSource(ctx context.Context, ds *datasource.DataSou // len(mockedDB.UpdateDataSourceCalls()) func (mock *DBMock) UpdateDataSourceCalls() []struct { Ctx context.Context - Ds *datasource.DataSource + Ds *datasourceCore.DataSource } { var calls []struct { Ctx context.Context - Ds *datasource.DataSource + Ds *datasourceCore.DataSource } mock.lockUpdateDataSource.RLock() calls = mock.calls.UpdateDataSource @@ -4854,10 +4868,10 @@ func (mock *DBMock) UpdateDataSourceCalls() []struct { } // UpdateDocument calls UpdateDocumentFunc. -func (mock *DBMock) UpdateDocument(ctx context.Context, doc documentCore.Document) error { +func (mock *DBMock) UpdateDocument(ctx context.Context, doc document.Document) error { callInfo := struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document }{ Ctx: ctx, Doc: doc, @@ -4880,11 +4894,11 @@ func (mock *DBMock) UpdateDocument(ctx context.Context, doc documentCore.Documen // len(mockedDB.UpdateDocumentCalls()) func (mock *DBMock) UpdateDocumentCalls() []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } { var calls []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } mock.lockUpdateDocument.RLock() calls = mock.calls.UpdateDocument @@ -4893,10 +4907,10 @@ func (mock *DBMock) UpdateDocumentCalls() []struct { } // UpdateDocumentBranchMetadata calls UpdateDocumentBranchMetadataFunc. -func (mock *DBMock) UpdateDocumentBranchMetadata(ctx context.Context, doc documentCore.Document) error { +func (mock *DBMock) UpdateDocumentBranchMetadata(ctx context.Context, doc document.Document) error { callInfo := struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document }{ Ctx: ctx, Doc: doc, @@ -4919,11 +4933,11 @@ func (mock *DBMock) UpdateDocumentBranchMetadata(ctx context.Context, doc docume // len(mockedDB.UpdateDocumentBranchMetadataCalls()) func (mock *DBMock) UpdateDocumentBranchMetadataCalls() []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } { var calls []struct { Ctx context.Context - Doc documentCore.Document + Doc document.Document } mock.lockUpdateDocumentBranchMetadata.RLock() calls = mock.calls.UpdateDocumentBranchMetadata @@ -5096,10 +5110,10 @@ func (mock *DBMock) UpdateDocumentParentIDCalls() []struct { } // UpdateDocumentTree calls UpdateDocumentTreeFunc. -func (mock *DBMock) UpdateDocumentTree(ctx context.Context, ss documentCore.Summaries, organizationID string) error { +func (mock *DBMock) UpdateDocumentTree(ctx context.Context, ss document.Summaries, organizationID string) error { callInfo := struct { Ctx context.Context - Ss documentCore.Summaries + Ss document.Summaries OrganizationID string }{ Ctx: ctx, @@ -5124,12 +5138,12 @@ func (mock *DBMock) UpdateDocumentTree(ctx context.Context, ss documentCore.Summ // len(mockedDB.UpdateDocumentTreeCalls()) func (mock *DBMock) UpdateDocumentTreeCalls() []struct { Ctx context.Context - Ss documentCore.Summaries + Ss document.Summaries OrganizationID string } { var calls []struct { Ctx context.Context - Ss documentCore.Summaries + Ss document.Summaries OrganizationID string } mock.lockUpdateDocumentTree.RLock() @@ -5307,10 +5321,10 @@ func (mock *DBMock) UpdateSlackUserLinkCalls() []struct { } // UpdateTagTree calls UpdateTagTreeFunc. -func (mock *DBMock) UpdateTagTree(ctx context.Context, tree tagCore.Summaries, organizationID string) error { +func (mock *DBMock) UpdateTagTree(ctx context.Context, tree tag.Summaries, organizationID string) error { callInfo := struct { Ctx context.Context - Tree tagCore.Summaries + Tree tag.Summaries OrganizationID string }{ Ctx: ctx, @@ -5321,7 +5335,9 @@ func (mock *DBMock) UpdateTagTree(ctx context.Context, tree tagCore.Summaries, o mock.calls.UpdateTagTree = append(mock.calls.UpdateTagTree, callInfo) mock.lockUpdateTagTree.Unlock() if mock.UpdateTagTreeFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.UpdateTagTreeFunc(ctx, tree, organizationID) @@ -5333,12 +5349,12 @@ func (mock *DBMock) UpdateTagTree(ctx context.Context, tree tagCore.Summaries, o // len(mockedDB.UpdateTagTreeCalls()) func (mock *DBMock) UpdateTagTreeCalls() []struct { Ctx context.Context - Tree tagCore.Summaries + Tree tag.Summaries OrganizationID string } { var calls []struct { Ctx context.Context - Tree tagCore.Summaries + Tree tag.Summaries OrganizationID string } mock.lockUpdateTagTree.RLock() diff --git a/server/core/internal/server/0mock_search_trigger_test.go b/server/core/internal/server/0mock_search_trigger_test.go index 703dd90b..871227cc 100644 --- a/server/core/internal/server/0mock_search_trigger_test.go +++ b/server/core/internal/server/0mock_search_trigger_test.go @@ -17,7 +17,7 @@ var _ SearchTrigger = &SearchTriggerMock{} // // // make and configure a mocked SearchTrigger // mockedSearchTrigger := &SearchTriggerMock{ -// TriggerFunc: func() { +// TriggerFunc: func() { // panic("mock out the Trigger method") // }, // } diff --git a/server/core/internal/server/internal/assistant/0mock_manager_test.go b/server/core/internal/server/internal/assistant/0mock_manager_test.go index 003b4768..d4ae996a 100644 --- a/server/core/internal/server/internal/assistant/0mock_manager_test.go +++ b/server/core/internal/server/internal/assistant/0mock_manager_test.go @@ -23,6 +23,9 @@ var _ Manager = &ManagerMock{} // ChatFunc: func(ctx context.Context, orgID string, userID string, conn protocol.SessionConn) error { // panic("mock out the Chat method") // }, +// ConfiguredFunc: func() bool { +// panic("mock out the Configured method") +// }, // } // // // use mockedManager in code that requires Manager @@ -30,17 +33,14 @@ var _ Manager = &ManagerMock{} // // } type ManagerMock struct { - // ConfiguredFunc mocks the Configured method. - ConfiguredFunc func() bool - // ChatFunc mocks the Chat method. ChatFunc func(ctx context.Context, orgID string, userID string, conn protocol.SessionConn) error + // ConfiguredFunc mocks the Configured method. + ConfiguredFunc func() bool + // calls tracks calls to the methods. calls struct { - // Configured holds details about calls to the Configured method. - Configured []struct { - } // Chat holds details about calls to the Chat method. Chat []struct { // Ctx is the ctx argument value. @@ -52,9 +52,12 @@ type ManagerMock struct { // Conn is the conn argument value. Conn protocol.SessionConn } + // Configured holds details about calls to the Configured method. + Configured []struct { + } } - lockConfigured sync.RWMutex lockChat sync.RWMutex + lockConfigured sync.RWMutex } // Chat calls ChatFunc. diff --git a/server/core/internal/server/internal/block/0mock_runner_test.go b/server/core/internal/server/internal/block/0mock_runner_test.go index 4828507d..adbce94c 100644 --- a/server/core/internal/server/internal/block/0mock_runner_test.go +++ b/server/core/internal/server/internal/block/0mock_runner_test.go @@ -72,10 +72,10 @@ func (mock *RunnerMock) Run(ctx context.Context, documentID xid.ID, branchID xid mock.lockRun.Unlock() if mock.RunFunc == nil { var ( - ifaceValOut any - errOut error + vOut any + errOut error ) - return ifaceValOut, errOut + return vOut, errOut } return mock.RunFunc(ctx, documentID, branchID, blockUID, organizationID) } diff --git a/server/core/internal/server/internal/document/0mock_db_test.go b/server/core/internal/server/internal/document/0mock_db_test.go index b9c4ea0d..d44a004d 100644 --- a/server/core/internal/server/internal/document/0mock_db_test.go +++ b/server/core/internal/server/internal/document/0mock_db_test.go @@ -55,6 +55,9 @@ var _ DB = &DBMock{} // DeleteDocumentCommentsByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { // panic("mock out the DeleteDocumentCommentsByBranchID method") // }, +// DetachDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { +// panic("mock out the DetachDocumentHooksByBranchID method") +// }, // FetchBranchReviewerFunc: func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) { // panic("mock out the FetchBranchReviewer method") // }, @@ -118,9 +121,6 @@ var _ DB = &DBMock{} // ReplaceBranchTagsFunc: func(ctx context.Context, organizationID string, fromBranchID xid.ID, toBranchID xid.ID) error { // panic("mock out the ReplaceBranchTags method") // }, -// DetachDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { -// panic("mock out the DetachDocumentHooksByBranchID method") -// }, // UpdateBranchReviewerFunc: func(ctx context.Context, reviewer documentCore.BranchReviewer) error { // panic("mock out the UpdateBranchReviewer method") // }, @@ -176,6 +176,9 @@ type DBMock struct { // DeleteDocumentCommentsByBranchIDFunc mocks the DeleteDocumentCommentsByBranchID method. DeleteDocumentCommentsByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error + // DetachDocumentHooksByBranchIDFunc mocks the DetachDocumentHooksByBranchID method. + DetachDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error + // FetchBranchReviewerFunc mocks the FetchBranchReviewer method. FetchBranchReviewerFunc func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) @@ -239,9 +242,6 @@ type DBMock struct { // ReplaceBranchTagsFunc mocks the ReplaceBranchTags method. ReplaceBranchTagsFunc func(ctx context.Context, organizationID string, fromBranchID xid.ID, toBranchID xid.ID) error - // DetachDocumentHooksByBranchIDFunc mocks the DetachDocumentHooksByBranchID method. - DetachDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error - // UpdateBranchReviewerFunc mocks the UpdateBranchReviewer method. UpdateBranchReviewerFunc func(ctx context.Context, reviewer documentCore.BranchReviewer) error @@ -356,6 +356,15 @@ type DBMock struct { // OrganizationID is the organizationID argument value. OrganizationID string } + // DetachDocumentHooksByBranchID holds details about calls to the DetachDocumentHooksByBranchID method. + DetachDocumentHooksByBranchID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // BranchID is the branchID argument value. + BranchID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } // FetchBranchReviewer holds details about calls to the FetchBranchReviewer method. FetchBranchReviewer []struct { // Ctx is the ctx argument value. @@ -535,15 +544,6 @@ type DBMock struct { // ToBranchID is the toBranchID argument value. ToBranchID xid.ID } - // DetachDocumentHooksByBranchID holds details about calls to the DetachDocumentHooksByBranchID method. - DetachDocumentHooksByBranchID []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // BranchID is the branchID argument value. - BranchID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } // UpdateBranchReviewer holds details about calls to the UpdateBranchReviewer method. UpdateBranchReviewer []struct { // Ctx is the ctx argument value. @@ -607,6 +607,7 @@ type DBMock struct { lockDeleteDocument sync.RWMutex lockDeleteDocumentBranchByID sync.RWMutex lockDeleteDocumentCommentsByBranchID sync.RWMutex + lockDetachDocumentHooksByBranchID sync.RWMutex lockFetchBranchReviewer sync.RWMutex lockFetchBranchReviewers sync.RWMutex lockFetchDocument sync.RWMutex @@ -628,7 +629,6 @@ type DBMock struct { lockInsertSearchJob sync.RWMutex lockPromoteBranchApprovals sync.RWMutex lockReplaceBranchTags sync.RWMutex - lockDetachDocumentHooksByBranchID sync.RWMutex lockUpdateBranchReviewer sync.RWMutex lockUpdateDocument sync.RWMutex lockUpdateDocumentBranchMetadata sync.RWMutex @@ -828,7 +828,9 @@ func (mock *DBMock) CopyBranchTags(ctx context.Context, organizationID string, f mock.calls.CopyBranchTags = append(mock.calls.CopyBranchTags, callInfo) mock.lockCopyBranchTags.Unlock() if mock.CopyBranchTagsFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.CopyBranchTagsFunc(ctx, organizationID, fromBranchID, toBranchID) @@ -1077,6 +1079,49 @@ func (mock *DBMock) DeleteDocumentCommentsByBranchIDCalls() []struct { return calls } +// DetachDocumentHooksByBranchID calls DetachDocumentHooksByBranchIDFunc. +func (mock *DBMock) DetachDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) error { + callInfo := struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + }{ + Ctx: ctx, + BranchID: branchID, + OrganizationID: organizationID, + } + mock.lockDetachDocumentHooksByBranchID.Lock() + mock.calls.DetachDocumentHooksByBranchID = append(mock.calls.DetachDocumentHooksByBranchID, callInfo) + mock.lockDetachDocumentHooksByBranchID.Unlock() + if mock.DetachDocumentHooksByBranchIDFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.DetachDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) +} + +// DetachDocumentHooksByBranchIDCalls gets all the calls that were made to DetachDocumentHooksByBranchID. +// Check the length with: +// +// len(mockedDB.DetachDocumentHooksByBranchIDCalls()) +func (mock *DBMock) DetachDocumentHooksByBranchIDCalls() []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + } + mock.lockDetachDocumentHooksByBranchID.RLock() + calls = mock.calls.DetachDocumentHooksByBranchID + mock.lockDetachDocumentHooksByBranchID.RUnlock() + return calls +} + // FetchBranchReviewer calls FetchBranchReviewerFunc. func (mock *DBMock) FetchBranchReviewer(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) { callInfo := struct { @@ -1943,7 +1988,9 @@ func (mock *DBMock) ReplaceBranchTags(ctx context.Context, organizationID string mock.calls.ReplaceBranchTags = append(mock.calls.ReplaceBranchTags, callInfo) mock.lockReplaceBranchTags.Unlock() if mock.ReplaceBranchTagsFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.ReplaceBranchTagsFunc(ctx, organizationID, fromBranchID, toBranchID) @@ -1971,49 +2018,6 @@ func (mock *DBMock) ReplaceBranchTagsCalls() []struct { return calls } -// DetachDocumentHooksByBranchID calls DetachDocumentHooksByBranchIDFunc. -func (mock *DBMock) DetachDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) error { - callInfo := struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - }{ - Ctx: ctx, - BranchID: branchID, - OrganizationID: organizationID, - } - mock.lockDetachDocumentHooksByBranchID.Lock() - mock.calls.DetachDocumentHooksByBranchID = append(mock.calls.DetachDocumentHooksByBranchID, callInfo) - mock.lockDetachDocumentHooksByBranchID.Unlock() - if mock.DetachDocumentHooksByBranchIDFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.DetachDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) -} - -// DetachDocumentHooksByBranchIDCalls gets all the calls that were made to DetachDocumentHooksByBranchID. -// Check the length with: -// -// len(mockedDB.DetachDocumentHooksByBranchIDCalls()) -func (mock *DBMock) DetachDocumentHooksByBranchIDCalls() []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - } - mock.lockDetachDocumentHooksByBranchID.RLock() - calls = mock.calls.DetachDocumentHooksByBranchID - mock.lockDetachDocumentHooksByBranchID.RUnlock() - return calls -} - // UpdateBranchReviewer calls UpdateBranchReviewerFunc. func (mock *DBMock) UpdateBranchReviewer(ctx context.Context, reviewer documentCore.BranchReviewer) error { callInfo := struct { diff --git a/server/core/internal/server/internal/document/0mock_search_trigger_test.go b/server/core/internal/server/internal/document/0mock_search_trigger_test.go index 3448bf1d..749af9e2 100644 --- a/server/core/internal/server/internal/document/0mock_search_trigger_test.go +++ b/server/core/internal/server/internal/document/0mock_search_trigger_test.go @@ -17,7 +17,7 @@ var _ SearchTrigger = &SearchTriggerMock{} // // // make and configure a mocked SearchTrigger // mockedSearchTrigger := &SearchTriggerMock{ -// TriggerFunc: func() { +// TriggerFunc: func() { // panic("mock out the Trigger method") // }, // } diff --git a/server/core/internal/server/internal/document/0mock_searcher_test.go b/server/core/internal/server/internal/document/0mock_searcher_test.go index 53b08431..de30297d 100644 --- a/server/core/internal/server/internal/document/0mock_searcher_test.go +++ b/server/core/internal/server/internal/document/0mock_searcher_test.go @@ -62,10 +62,10 @@ func (mock *SearcherMock) SearchDocuments(ctx context.Context, organizationID st mock.lockSearchDocuments.Unlock() if mock.SearchDocumentsFunc == nil { var ( - out0 []byte - errOut error + bytesOut []byte + errOut error ) - return out0, errOut + return bytesOut, errOut } return mock.SearchDocumentsFunc(ctx, organizationID, query) } diff --git a/server/core/internal/server/internal/document/0mock_tx_test.go b/server/core/internal/server/internal/document/0mock_tx_test.go index 1151a1ee..c14a8b79 100644 --- a/server/core/internal/server/internal/document/0mock_tx_test.go +++ b/server/core/internal/server/internal/document/0mock_tx_test.go @@ -55,6 +55,9 @@ var _ Tx = &TxMock{} // DeleteDocumentCommentsByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { // panic("mock out the DeleteDocumentCommentsByBranchID method") // }, +// DetachDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { +// panic("mock out the DetachDocumentHooksByBranchID method") +// }, // FetchBranchReviewerFunc: func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) { // panic("mock out the FetchBranchReviewer method") // }, @@ -121,9 +124,6 @@ var _ Tx = &TxMock{} // RollbackFunc: func() error { // panic("mock out the Rollback method") // }, -// DetachDocumentHooksByBranchIDFunc: func(ctx context.Context, branchID xid.ID, organizationID string) error { -// panic("mock out the DetachDocumentHooksByBranchID method") -// }, // UpdateBranchReviewerFunc: func(ctx context.Context, reviewer documentCore.BranchReviewer) error { // panic("mock out the UpdateBranchReviewer method") // }, @@ -179,6 +179,9 @@ type TxMock struct { // DeleteDocumentCommentsByBranchIDFunc mocks the DeleteDocumentCommentsByBranchID method. DeleteDocumentCommentsByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error + // DetachDocumentHooksByBranchIDFunc mocks the DetachDocumentHooksByBranchID method. + DetachDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error + // FetchBranchReviewerFunc mocks the FetchBranchReviewer method. FetchBranchReviewerFunc func(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) @@ -245,9 +248,6 @@ type TxMock struct { // RollbackFunc mocks the Rollback method. RollbackFunc func() error - // DetachDocumentHooksByBranchIDFunc mocks the DetachDocumentHooksByBranchID method. - DetachDocumentHooksByBranchIDFunc func(ctx context.Context, branchID xid.ID, organizationID string) error - // UpdateBranchReviewerFunc mocks the UpdateBranchReviewer method. UpdateBranchReviewerFunc func(ctx context.Context, reviewer documentCore.BranchReviewer) error @@ -358,6 +358,15 @@ type TxMock struct { // OrganizationID is the organizationID argument value. OrganizationID string } + // DetachDocumentHooksByBranchID holds details about calls to the DetachDocumentHooksByBranchID method. + DetachDocumentHooksByBranchID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // BranchID is the branchID argument value. + BranchID xid.ID + // OrganizationID is the organizationID argument value. + OrganizationID string + } // FetchBranchReviewer holds details about calls to the FetchBranchReviewer method. FetchBranchReviewer []struct { // Ctx is the ctx argument value. @@ -540,15 +549,6 @@ type TxMock struct { // Rollback holds details about calls to the Rollback method. Rollback []struct { } - // DetachDocumentHooksByBranchID holds details about calls to the DetachDocumentHooksByBranchID method. - DetachDocumentHooksByBranchID []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // BranchID is the branchID argument value. - BranchID xid.ID - // OrganizationID is the organizationID argument value. - OrganizationID string - } // UpdateBranchReviewer holds details about calls to the UpdateBranchReviewer method. UpdateBranchReviewer []struct { // Ctx is the ctx argument value. @@ -612,6 +612,7 @@ type TxMock struct { lockDeleteDocument sync.RWMutex lockDeleteDocumentBranchByID sync.RWMutex lockDeleteDocumentCommentsByBranchID sync.RWMutex + lockDetachDocumentHooksByBranchID sync.RWMutex lockFetchBranchReviewer sync.RWMutex lockFetchBranchReviewers sync.RWMutex lockFetchDocument sync.RWMutex @@ -634,7 +635,6 @@ type TxMock struct { lockPromoteBranchApprovals sync.RWMutex lockReplaceBranchTags sync.RWMutex lockRollback sync.RWMutex - lockDetachDocumentHooksByBranchID sync.RWMutex lockUpdateBranchReviewer sync.RWMutex lockUpdateDocument sync.RWMutex lockUpdateDocumentBranchMetadata sync.RWMutex @@ -825,7 +825,9 @@ func (mock *TxMock) CopyBranchTags(ctx context.Context, organizationID string, f mock.calls.CopyBranchTags = append(mock.calls.CopyBranchTags, callInfo) mock.lockCopyBranchTags.Unlock() if mock.CopyBranchTagsFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.CopyBranchTagsFunc(ctx, organizationID, fromBranchID, toBranchID) @@ -1074,6 +1076,49 @@ func (mock *TxMock) DeleteDocumentCommentsByBranchIDCalls() []struct { return calls } +// DetachDocumentHooksByBranchID calls DetachDocumentHooksByBranchIDFunc. +func (mock *TxMock) DetachDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) error { + callInfo := struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + }{ + Ctx: ctx, + BranchID: branchID, + OrganizationID: organizationID, + } + mock.lockDetachDocumentHooksByBranchID.Lock() + mock.calls.DetachDocumentHooksByBranchID = append(mock.calls.DetachDocumentHooksByBranchID, callInfo) + mock.lockDetachDocumentHooksByBranchID.Unlock() + if mock.DetachDocumentHooksByBranchIDFunc == nil { + var ( + errOut error + ) + return errOut + } + return mock.DetachDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) +} + +// DetachDocumentHooksByBranchIDCalls gets all the calls that were made to DetachDocumentHooksByBranchID. +// Check the length with: +// +// len(mockedTx.DetachDocumentHooksByBranchIDCalls()) +func (mock *TxMock) DetachDocumentHooksByBranchIDCalls() []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string +} { + var calls []struct { + Ctx context.Context + BranchID xid.ID + OrganizationID string + } + mock.lockDetachDocumentHooksByBranchID.RLock() + calls = mock.calls.DetachDocumentHooksByBranchID + mock.lockDetachDocumentHooksByBranchID.RUnlock() + return calls +} + // FetchBranchReviewer calls FetchBranchReviewerFunc. func (mock *TxMock) FetchBranchReviewer(ctx context.Context, branchID xid.ID, userID string, organizationID string) (*documentCore.BranchReviewer, error) { callInfo := struct { @@ -1940,7 +1985,9 @@ func (mock *TxMock) ReplaceBranchTags(ctx context.Context, organizationID string mock.calls.ReplaceBranchTags = append(mock.calls.ReplaceBranchTags, callInfo) mock.lockReplaceBranchTags.Unlock() if mock.ReplaceBranchTagsFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.ReplaceBranchTagsFunc(ctx, organizationID, fromBranchID, toBranchID) @@ -1998,49 +2045,6 @@ func (mock *TxMock) RollbackCalls() []struct { return calls } -// DetachDocumentHooksByBranchID calls DetachDocumentHooksByBranchIDFunc. -func (mock *TxMock) DetachDocumentHooksByBranchID(ctx context.Context, branchID xid.ID, organizationID string) error { - callInfo := struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - }{ - Ctx: ctx, - BranchID: branchID, - OrganizationID: organizationID, - } - mock.lockDetachDocumentHooksByBranchID.Lock() - mock.calls.DetachDocumentHooksByBranchID = append(mock.calls.DetachDocumentHooksByBranchID, callInfo) - mock.lockDetachDocumentHooksByBranchID.Unlock() - if mock.DetachDocumentHooksByBranchIDFunc == nil { - var ( - errOut error - ) - return errOut - } - return mock.DetachDocumentHooksByBranchIDFunc(ctx, branchID, organizationID) -} - -// DetachDocumentHooksByBranchIDCalls gets all the calls that were made to DetachDocumentHooksByBranchID. -// Check the length with: -// -// len(mockedTx.DetachDocumentHooksByBranchIDCalls()) -func (mock *TxMock) DetachDocumentHooksByBranchIDCalls() []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string -} { - var calls []struct { - Ctx context.Context - BranchID xid.ID - OrganizationID string - } - mock.lockDetachDocumentHooksByBranchID.RLock() - calls = mock.calls.DetachDocumentHooksByBranchID - mock.lockDetachDocumentHooksByBranchID.RUnlock() - return calls -} - // UpdateBranchReviewer calls UpdateBranchReviewerFunc. func (mock *TxMock) UpdateBranchReviewer(ctx context.Context, reviewer documentCore.BranchReviewer) error { callInfo := struct { diff --git a/server/core/internal/server/internal/org/0mock_db_test.go b/server/core/internal/server/internal/org/0mock_db_test.go index 42d4220e..b2668e95 100644 --- a/server/core/internal/server/internal/org/0mock_db_test.go +++ b/server/core/internal/server/internal/org/0mock_db_test.go @@ -236,7 +236,9 @@ func (mock *DBMock) AssignBranchTag(ctx context.Context, organizationID string, mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) mock.lockAssignBranchTag.Unlock() if mock.AssignBranchTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) @@ -593,7 +595,9 @@ func (mock *DBMock) InsertTag(ctx context.Context, t tag.Tag) error { mock.calls.InsertTag = append(mock.calls.InsertTag, callInfo) mock.lockInsertTag.Unlock() if mock.InsertTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.InsertTagFunc(ctx, t) diff --git a/server/core/internal/server/internal/org/0mock_search_trigger_test.go b/server/core/internal/server/internal/org/0mock_search_trigger_test.go index 633effe8..bc470795 100644 --- a/server/core/internal/server/internal/org/0mock_search_trigger_test.go +++ b/server/core/internal/server/internal/org/0mock_search_trigger_test.go @@ -17,7 +17,7 @@ var _ SearchTrigger = &SearchTriggerMock{} // // // make and configure a mocked SearchTrigger // mockedSearchTrigger := &SearchTriggerMock{ -// TriggerFunc: func() { +// TriggerFunc: func() { // panic("mock out the Trigger method") // }, // } diff --git a/server/core/internal/server/internal/org/0mock_tx_test.go b/server/core/internal/server/internal/org/0mock_tx_test.go index a50f39d2..7d6d87d0 100644 --- a/server/core/internal/server/internal/org/0mock_tx_test.go +++ b/server/core/internal/server/internal/org/0mock_tx_test.go @@ -242,7 +242,9 @@ func (mock *TxMock) AssignBranchTag(ctx context.Context, organizationID string, mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) mock.lockAssignBranchTag.Unlock() if mock.AssignBranchTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) @@ -590,7 +592,9 @@ func (mock *TxMock) InsertTag(ctx context.Context, t tag.Tag) error { mock.calls.InsertTag = append(mock.calls.InsertTag, callInfo) mock.lockInsertTag.Unlock() if mock.InsertTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.InsertTagFunc(ctx, t) diff --git a/server/core/internal/server/internal/tag/0mock_db_test.go b/server/core/internal/server/internal/tag/0mock_db_test.go index 82302c25..2f9afb58 100644 --- a/server/core/internal/server/internal/tag/0mock_db_test.go +++ b/server/core/internal/server/internal/tag/0mock_db_test.go @@ -192,7 +192,9 @@ func (mock *DBMock) AssignBranchTag(ctx context.Context, organizationID string, mock.calls.AssignBranchTag = append(mock.calls.AssignBranchTag, callInfo) mock.lockAssignBranchTag.Unlock() if mock.AssignBranchTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.AssignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) @@ -237,7 +239,9 @@ func (mock *DBMock) DeleteTag(ctx context.Context, id xid.ID, organizationID str mock.calls.DeleteTag = append(mock.calls.DeleteTag, callInfo) mock.lockDeleteTag.Unlock() if mock.DeleteTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.DeleteTagFunc(ctx, id, organizationID) @@ -281,10 +285,10 @@ func (mock *DBMock) FetchBranchTagIDs(ctx context.Context, organizationID string mock.lockFetchBranchTagIDs.Unlock() if mock.FetchBranchTagIDsFunc == nil { var ( - idsOut []xid.ID + iDsOut []xid.ID errOut error ) - return idsOut, errOut + return iDsOut, errOut } return mock.FetchBranchTagIDsFunc(ctx, organizationID, documentID, branchID) } @@ -368,7 +372,9 @@ func (mock *DBMock) InsertTag(ctx context.Context, t tagCore.Tag) error { mock.calls.InsertTag = append(mock.calls.InsertTag, callInfo) mock.lockInsertTag.Unlock() if mock.InsertTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.InsertTagFunc(ctx, t) @@ -411,7 +417,9 @@ func (mock *DBMock) SetTagVisibility(ctx context.Context, organizationID string, mock.calls.SetTagVisibility = append(mock.calls.SetTagVisibility, callInfo) mock.lockSetTagVisibility.Unlock() if mock.SetTagVisibilityFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.SetTagVisibilityFunc(ctx, organizationID, userID, id, inp) @@ -460,7 +468,9 @@ func (mock *DBMock) UnassignBranchTag(ctx context.Context, organizationID string mock.calls.UnassignBranchTag = append(mock.calls.UnassignBranchTag, callInfo) mock.lockUnassignBranchTag.Unlock() if mock.UnassignBranchTagFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.UnassignBranchTagFunc(ctx, organizationID, documentID, branchID, tagID) @@ -505,7 +515,9 @@ func (mock *DBMock) UpdateTagTree(ctx context.Context, tree tagCore.Summaries, o mock.calls.UpdateTagTree = append(mock.calls.UpdateTagTree, callInfo) mock.lockUpdateTagTree.Unlock() if mock.UpdateTagTreeFunc == nil { - var errOut error + var ( + errOut error + ) return errOut } return mock.UpdateTagTreeFunc(ctx, tree, organizationID) diff --git a/web/app/components/editor/blocks/metrics/MainBlock.nuxt.test.ts b/web/app/components/editor/blocks/metrics/MainBlock.nuxt.test.ts index 81f9a616..b6409d41 100644 --- a/web/app/components/editor/blocks/metrics/MainBlock.nuxt.test.ts +++ b/web/app/components/editor/blocks/metrics/MainBlock.nuxt.test.ts @@ -313,8 +313,65 @@ describe("", { concurrent: false }, () => { ) await nextTick() + expect(updateAttributes).toHaveBeenCalledTimes(1) expect(updateAttributes).toHaveBeenCalledWith({ simulationPreset: MetricSimulationPreset.HTTPLatency, + simulationActive: true, + }) + }) + + // only the server switches the flag off. An edit that neither starts + // nor stops the simulation does not send it + it("changes only the preset of a block that is simulating", async ({ + expect, + }) => { + const updateAttributes = vi.fn() + const uid = nextUid() + await mountBlock({ + uid: uid, + updateAttributes: updateAttributes, + attrs: { + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }, + underTooltipProvider: true, + }) + + const config = storedConfig(uid) + if (config) { + config.simulationPreset = MetricSimulationPreset.DiskUsage + } + + expect(updateAttributes).toHaveBeenCalledTimes(1) + expect(updateAttributes).toHaveBeenCalledWith({ + simulationPreset: MetricSimulationPreset.DiskUsage, + }) + }) + + it("stops a simulation by unsetting the preset and the flag together", async ({ + expect, + }) => { + const updateAttributes = vi.fn() + const uid = nextUid() + await mountBlock({ + uid: uid, + updateAttributes: updateAttributes, + attrs: { + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }, + underTooltipProvider: true, + }) + + const config = storedConfig(uid) + if (config) { + config.simulationPreset = null + } + + expect(updateAttributes).toHaveBeenCalledTimes(1) + expect(updateAttributes).toHaveBeenCalledWith({ + simulationPreset: null, + simulationActive: false, }) }) @@ -325,13 +382,30 @@ describe("", { concurrent: false }, () => { await mountBlock({ uid: uid, - attrs: { simulationPreset: MetricSimulationPreset.DiskUsage }, + attrs: { + simulationPreset: MetricSimulationPreset.DiskUsage, + simulationActive: true, + }, underTooltipProvider: true, }) expect(storedConfig(uid)?.simulationPreset).toBe( MetricSimulationPreset.DiskUsage, ) + expect(storedConfig(uid)?.simulationActive).toBe(true) + }) + + it("reads a block without a simulation flag as not simulating", async ({ + expect, + }) => { + const uid = nextUid() + + await mountBlock({ + uid: uid, + attrs: { simulationPreset: MetricSimulationPreset.DiskUsage }, + }) + + expect(storedConfig(uid)?.simulationActive).toBe(false) }) it("shows the simulation icon while the visualization simulates", async ({ @@ -384,6 +458,8 @@ describe("", { concurrent: false }, () => { dataSourceId: "ds-1", visualizationType: GenericQueryChartType.Gauge, unitCustom: "req/s", + simulationPreset: null, + simulationActive: false, config: null, }), ) diff --git a/web/app/components/editor/blocks/metrics/MainBlock.vue b/web/app/components/editor/blocks/metrics/MainBlock.vue index ecc272f2..57054185 100644 --- a/web/app/components/editor/blocks/metrics/MainBlock.vue +++ b/web/app/components/editor/blocks/metrics/MainBlock.vue @@ -86,6 +86,7 @@ function migrateLegacyIfNeeded(fieldAttrs: Record) { axisBoundsMin: legacy.axisBounds?.min ?? null, axisBoundsMax: legacy.axisBounds?.max ?? null, simulationPreset: null, + simulationActive: false, // overlay caller's edit and clear legacy blob ...fieldAttrs, config: null, @@ -231,9 +232,27 @@ const config = reactive({ (props.node.attrs.simulationPreset as MetricConfig["simulationPreset"]) ?? null, set: (v) => { - migrateLegacyIfNeeded({ simulationPreset: v }) + if (v === null) { + migrateLegacyIfNeeded({ + simulationPreset: null, + simulationActive: false, + }) + + return + } + + if (props.node.attrs.simulationActive === true) { + migrateLegacyIfNeeded({ simulationPreset: v }) + + return + } + + migrateLegacyIfNeeded({ simulationPreset: v, simulationActive: true }) }, }), + simulationActive: computed( + () => props.node.attrs.simulationActive === true, + ), }) const otherEditingUsers = editingUsersRef(() => props.node.attrs.uid as string) diff --git a/web/app/components/editor/blocks/metrics/VisualizationContainer.nuxt.test.ts b/web/app/components/editor/blocks/metrics/VisualizationContainer.nuxt.test.ts index 674ecd33..6f30dc84 100644 --- a/web/app/components/editor/blocks/metrics/VisualizationContainer.nuxt.test.ts +++ b/web/app/components/editor/blocks/metrics/VisualizationContainer.nuxt.test.ts @@ -433,13 +433,72 @@ describe("", { concurrent: false }, () => { ]) }) + it("asks for the preset the block kept from its last simulation", async ({ + expect, + }) => { + mockEndpoint("GET", QUERY_URL, () => ({ + status: GenericQueryResultStatus.NoData, + data: [], + })) + + const wrapper = await mountContainer( + metricConfig({ simulationPreset: MetricSimulationPreset.ErrorRate }), + ) + + await vi.waitFor(() => { + expect(wrapper.text()).toContain( + t("editor.metrics.status.no-data-loaded.simulate-action-button"), + ) + }, WAIT_FOR_OPTIONS) + await findButtonByText( + wrapper, + t("editor.metrics.status.no-data-loaded.simulate-action-button"), + ).trigger("click") + + expect(wrapper.emitted("simulate")).toEqual([ + [MetricSimulationPreset.ErrorRate], + ]) + }) + + // the preset stays after the simulation ends, so a preset alone does + // not mean the block simulates + it("queries like any block once its simulation is switched off", async ({ + expect, + }) => { + const uid = nextUid() + const checks = mockEndpoint("POST", simulationCheckURL(uid), () => ({ + cleared: false, + })) + const calls = mockEndpoint("GET", QUERY_URL, () => seriesResult()) + + const wrapper = await mountContainer( + metricConfig({ + simulationPreset: MetricSimulationPreset.HTTPLatency, + simulationActive: false, + }), + { uid: uid }, + ) + + await vi.waitFor(() => { + expect( + wrapper.findComponent({ name: "LineChart" }).props("seriesData"), + ).toHaveLength(1) + }, WAIT_FOR_OPTIONS) + expect(calls.length).toBeGreaterThan(0) + expect(simulationVisible(wrapper)).toBe(false) + expect(checks).toHaveLength(0) + }) + it("draws generated data without querying the data source", async ({ expect, }) => { const calls = mockEndpoint("GET", QUERY_URL, () => seriesResult()) const wrapper = await mountContainer( - metricConfig({ simulationPreset: MetricSimulationPreset.HTTPLatency }), + metricConfig({ + simulationPreset: MetricSimulationPreset.HTTPLatency, + simulationActive: true, + }), ) expect(chartNames(wrapper)).toEqual(["LineChart"]) @@ -485,6 +544,7 @@ describe("", { concurrent: false }, () => { const wrapper = await mountContainer( metricConfig({ simulationPreset: "pie_of_the_day" as MetricSimulationPreset, + simulationActive: true, }), ) @@ -510,6 +570,7 @@ describe("", { concurrent: false }, () => { const wrapper = await mountContainer( metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }), ) @@ -526,7 +587,10 @@ describe("", { concurrent: false }, () => { mockEndpoint("GET", QUERY_URL, () => seriesResult()) const wrapper = await mountContainer( - metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage }), + metricConfig({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), ) expect(simulationVisible(wrapper)).toBe(true) @@ -539,6 +603,7 @@ describe("", { concurrent: false }, () => { metricConfig({ timeRange: TimeRangePreset.Last15Minutes, simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }), ) @@ -570,6 +635,7 @@ describe("", { concurrent: false }, () => { metricConfig({ visualizationType: type, simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }), ) @@ -582,7 +648,10 @@ describe("", { concurrent: false }, () => { mockEndpoint("GET", QUERY_URL, () => seriesResult()) const wrapper = await mountContainer( - metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage }), + metricConfig({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), ) expect(simulationVisible(wrapper)).toBe(true) @@ -604,7 +673,10 @@ describe("", { concurrent: false }, () => { mockEndpoint("GET", QUERY_URL, () => seriesResult()) await mountContainer( - metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage }), + metricConfig({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), { uid: uid }, ) @@ -627,6 +699,7 @@ describe("", { concurrent: false }, () => { metricConfig({ refreshInterval: RefreshInterval.D1, simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }), { uid: uid }, ) @@ -649,7 +722,10 @@ describe("", { concurrent: false }, () => { useEditorStore().updateActiveBranchId(null) await mountContainer( - metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage }), + metricConfig({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), { uid: uid }, ) @@ -669,7 +745,10 @@ describe("", { concurrent: false }, () => { })) await mountContainer( - metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage }), + metricConfig({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), { uid: uid, disableRefresh: true }, ) @@ -692,12 +771,13 @@ describe("", { concurrent: false }, () => { }) const config = metricConfig({ simulationPreset: MetricSimulationPreset.HTTPLatency, + simulationActive: true, }) const wrapper = await mountContainer(config) await wrapper.setProps({ - config: { ...config, simulationPreset: null }, + config: { ...config, simulationActive: false }, }) await nextTick() @@ -732,12 +812,13 @@ describe("", { concurrent: false }, () => { { name: "Query 2", query: "", legendFormat: "" }, ], simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }) const wrapper = await mountContainer(config) await wrapper.setProps({ - config: { ...config, simulationPreset: null }, + config: { ...config, simulationActive: false }, }) await nextTick() @@ -777,12 +858,13 @@ describe("", { concurrent: false }, () => { config: { ...config, simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }, }) await nextTick() await wrapper.setProps({ - config: { ...config, simulationPreset: null }, + config: { ...config, simulationActive: false }, }) await vi.waitFor(() => { @@ -799,6 +881,7 @@ describe("", { concurrent: false }, () => { const calls = mockEndpoint("GET", QUERY_URL, () => seriesResult()) const config = metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }) const wrapper = await mountContainer(config, { uid: uid }) @@ -808,7 +891,7 @@ describe("", { concurrent: false }, () => { // core removes the attribute on the live document, which reaches // the editor as a node attribute change await wrapper.setProps({ - config: { ...config, simulationPreset: null }, + config: { ...config, simulationActive: false }, }) await vi.waitFor(() => { @@ -826,7 +909,10 @@ describe("", { concurrent: false }, () => { }) const wrapper = await mountContainer( - metricConfig({ simulationPreset: MetricSimulationPreset.CPUUsage }), + metricConfig({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), { uid: uid }, ) diff --git a/web/app/components/editor/blocks/metrics/VisualizationContainer.vue b/web/app/components/editor/blocks/metrics/VisualizationContainer.vue index b591962d..c43dc496 100644 --- a/web/app/components/editor/blocks/metrics/VisualizationContainer.vue +++ b/web/app/components/editor/blocks/metrics/VisualizationContainer.vue @@ -58,12 +58,17 @@ const dataSourceUnavailable = computed(() => { return !!dataSource && dataSource.status !== DataSourceStatus.Success }) -// an unknown preset reads as "not simulating", so a block carrying one -// falls back to querying instead of breaking the render for every viewer +// the preset the block is drawing, null when it queries instead. An +// unknown preset reads as "not simulating", so a block carrying one falls +// back to querying instead of breaking the render for every viewer const simulationPreset = computed(() => { const preset: unknown = props.config.simulationPreset - if (dataSourceUnavailable.value || !isSimulationPreset(preset)) { + if ( + !props.config.simulationActive || + dataSourceUnavailable.value || + !isSimulationPreset(preset) + ) { return null } @@ -418,7 +423,9 @@ async function checkSimulation() { } function startSimulation() { - emit("simulate", DEFAULT_SIMULATION_PRESET) + const kept: unknown = props.config.simulationPreset + + emit("simulate", isSimulationPreset(kept) ? kept : DEFAULT_SIMULATION_PRESET) } function openModal() { diff --git a/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.nuxt.test.ts b/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.nuxt.test.ts index 1fd0c8fc..a25a0b64 100644 --- a/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.nuxt.test.ts +++ b/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.nuxt.test.ts @@ -521,12 +521,27 @@ describe("", { concurrent: false }, () => { expect(wrapper.findComponent(SimulationPresetSelect).exists()).toBe(false) }) + it("stays hidden once the real data has arrived", async ({ expect }) => { + const wrapper = await mountSidebar({ + modelValue: configWith({ + simulationPreset: MetricSimulationPreset.HTTPLatency, + simulationActive: false, + }), + }) + + expect(wrapper.text()).not.toContain( + t("editor.metrics.simulation.section-title"), + ) + expect(wrapper.findComponent(SimulationPresetSelect).exists()).toBe(false) + }) + it("explains the simulation and shows the chart it draws", async ({ expect, }) => { const wrapper = await mountSidebar({ modelValue: configWith({ simulationPreset: MetricSimulationPreset.HTTPLatency, + simulationActive: true, }), }) @@ -544,6 +559,7 @@ describe("", { concurrent: false }, () => { it("switches the block to another preset", async ({ expect }) => { const config = configWith({ simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }) const wrapper = await mountSidebar({ modelValue: config }) @@ -561,6 +577,7 @@ describe("", { concurrent: false }, () => { it("turns the simulation off again", async ({ expect }) => { const config = configWith({ simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }) const wrapper = await mountSidebar({ modelValue: config }) @@ -572,12 +589,133 @@ describe("", { concurrent: false }, () => { expect(config.simulationPreset).toBeNull() }) + // a diff compares what each side chose. It shows the preset even + // when the simulation is already off + it("shows the preset a diff replaced beside the new one", async ({ + expect, + }) => { + const wrapper = await mountSidebar({ + modelValue: configWith({ + simulationPreset: MetricSimulationPreset.DiskUsage, + simulationActive: false, + }), + diffStatus: DiffStatus.Modified, + oldConfig: configWith({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: false, + }), + }) + + const selects = wrapper.findAllComponents(SimulationPresetSelect) + + expect(selects).toHaveLength(2) + expect(at(selects, 0).text()).toContain( + t("editor.metrics.simulation.preset-options.disk_usage"), + ) + expect(at(selects, 0).find("button").classes()).toContain( + "bg-diff-field-added", + ) + expect(at(selects, 1).text()).toContain( + t("editor.metrics.simulation.preset-options.cpu_usage"), + ) + expect(at(selects, 1).find("button").classes()).toContain( + "bg-diff-field-removed", + ) + }) + + it("shows only the new side of a preset a diff added", async ({ + expect, + }) => { + const wrapper = await mountSidebar({ + modelValue: configWith({ + simulationPreset: MetricSimulationPreset.DiskUsage, + simulationActive: true, + }), + diffStatus: DiffStatus.Modified, + oldConfig: configWith(), + }) + + const selects = wrapper.findAllComponents(SimulationPresetSelect) + + expect(selects).toHaveLength(1) + expect(at(selects, 0).find("button").classes()).toContain( + "bg-diff-field-added", + ) + }) + + it("shows only the old side of a preset a diff removed", async ({ + expect, + }) => { + const wrapper = await mountSidebar({ + modelValue: configWith(), + diffStatus: DiffStatus.Modified, + oldConfig: configWith({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), + }) + + const selects = wrapper.findAllComponents(SimulationPresetSelect) + + expect(wrapper.text()).toContain( + t("editor.metrics.simulation.section-title"), + ) + expect(selects).toHaveLength(1) + expect(at(selects, 0).text()).toContain( + t("editor.metrics.simulation.preset-options.cpu_usage"), + ) + expect(at(selects, 0).find("button").classes()).toContain( + "bg-diff-field-removed", + ) + }) + + it("leaves a preset both sides share unmarked", async ({ expect }) => { + const wrapper = await mountSidebar({ + modelValue: configWith({ + title: "After", + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: false, + }), + diffStatus: DiffStatus.Modified, + oldConfig: configWith({ + title: "Before", + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), + }) + + const selects = wrapper.findAllComponents(SimulationPresetSelect) + + expect(selects).toHaveLength(1) + expect(at(selects, 0).find("button").classes()).not.toContain( + "bg-diff-field-added", + ) + }) + + it("does not offer the switch-off button in a diff", async ({ expect }) => { + const wrapper = await mountSidebar({ + modelValue: configWith({ + simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, + }), + diffStatus: DiffStatus.Unchanged, + }) + + expect(wrapper.text()).toContain( + t("editor.metrics.simulation.section-title"), + ) + expect(wrapper.text()).not.toContain( + t("editor.metrics.simulation.stop-button"), + ) + }) + it("does not offer a reader the switch-off button", async ({ expect }) => { useEditorMeta().setEditable(false) const wrapper = await mountSidebar({ modelValue: configWith({ simulationPreset: MetricSimulationPreset.CPUUsage, + simulationActive: true, }), }) diff --git a/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.vue b/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.vue index f5271b08..d24617a4 100644 --- a/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.vue +++ b/web/app/components/editor/blocks/metrics/config-modal/ConfigSidebar.vue @@ -155,6 +155,24 @@ const isBoundsMaxModified = computed(() => { props.oldConfig.axisBounds.max !== config.value.axisBounds.max ) }) +const isSimulationPresetModified = computed(() => { + return ( + isDiffModified.value && + !!props.oldConfig && + props.oldConfig.simulationPreset !== config.value.simulationPreset + ) +}) +// outside a diff the section shows only while the block simulates. +// A diff shows it when either side has a preset. +const isSimulationSectionVisible = computed(() => { + if (props.diffStatus) { + return ( + !!config.value.simulationPreset || !!props.oldConfig?.simulationPreset + ) + } + + return !!config.value.simulationPreset && config.value.simulationActive +}) interface ThresholdEntry { value?: number @@ -287,7 +305,7 @@ function removeThreshold(index: number) {
-
+
{{ $t("editor.metrics.simulation.section-title") }} @@ -301,10 +319,21 @@ function removeThreshold(index: number) { {{ $t("editor.metrics.simulation.preset-label") }} - + + import { cn } from "~/lib/utils" import { MetricSimulationPreset } from "../utils" +import { DiffStatus } from "~/components/editor/diff/position-map" const selectedPreset = defineModel() +const props = defineProps<{ + diffStatus?: DiffStatus | null +}>() const { isEditable } = useEditorMeta() const editorStore = useEditorStore() @@ -26,6 +30,8 @@ function selectPreset(preset: MetricSimulationPreset) { cn( 'h-[1.775rem]! justify-between gap-1 px-1.5 text-2sm font-normal opacity-100!', isEditingDisabled && 'pointer-events-none select-text', + props.diffStatus === DiffStatus.Added && 'bg-diff-field-added', + props.diffStatus === DiffStatus.Removed && 'bg-diff-field-removed', ) " > diff --git a/web/app/components/editor/blocks/metrics/index.test.ts b/web/app/components/editor/blocks/metrics/index.test.ts index a7efbb79..e55af8a1 100644 --- a/web/app/components/editor/blocks/metrics/index.test.ts +++ b/web/app/components/editor/blocks/metrics/index.test.ts @@ -238,6 +238,7 @@ describe("MetricBlock", () => { axisBoundsMin: null, axisBoundsMax: null, simulationPreset: null, + simulationActive: false, width: MetricBlockWidth.Standard, }) }) @@ -274,6 +275,10 @@ describe("MetricBlock", () => { widthAttribute().renderHTML?.({ width: MetricBlockWidth.Compact }), ).toEqual({ "data-width": MetricBlockWidth.Compact }) }) + + it("keeps the simulation flag out of the rendered HTML", ({ expect }) => { + expect(metricAttributes().simulationActive?.rendered).toBe(false) + }) }) describe("insertMetricBlock", () => { @@ -332,42 +337,6 @@ describe("MetricBlock", () => { }) }) -// the width attribute owns the only parse/render pair among the block -// attributes, so the tests reach it through the declaration -function widthAttribute() { - const addAttributes = MetricBlock.config.addAttributes - - if (!addAttributes) { - throw new Error("MetricBlock declares no attributes") - } - - const attributes = addAttributes.call({} as never) as Record< - string, - { - parseHTML?: (element: HTMLElement) => unknown - renderHTML?: (attributes: Record) => unknown - } - > - - const width = attributes.width - - if (!width) { - throw new Error("MetricBlock declares no width attribute") - } - - return width -} - -function metricBlockCommands() { - const addCommands = MetricBlock.config.addCommands - - if (!addCommands) { - throw new Error("MetricBlock declares no commands") - } - - return addCommands.call({} as never) -} - describe("setUpMetricBlock", () => { it("wraps the metric block in a grid at the document root", ({ expect }) => { const state = EditorState.create({ @@ -478,3 +447,42 @@ describe("insertMetricBlock", () => { ]) }) }) + +// how an attribute reaches HTML is only visible on its declaration, so the +// tests read it from there +function metricAttributes() { + const addAttributes = MetricBlock.config.addAttributes + + if (!addAttributes) { + throw new Error("MetricBlock declares no attributes") + } + + return addAttributes.call({} as never) as Record< + string, + { + rendered?: boolean + parseHTML?: (element: HTMLElement) => unknown + renderHTML?: (attributes: Record) => unknown + } + > +} + +function widthAttribute() { + const width = metricAttributes().width + + if (!width) { + throw new Error("MetricBlock declares no width attribute") + } + + return width +} + +function metricBlockCommands() { + const addCommands = MetricBlock.config.addCommands + + if (!addCommands) { + throw new Error("MetricBlock declares no commands") + } + + return addCommands.call({} as never) +} diff --git a/web/app/components/editor/blocks/metrics/index.ts b/web/app/components/editor/blocks/metrics/index.ts index 51c42946..2ce66b1a 100644 --- a/web/app/components/editor/blocks/metrics/index.ts +++ b/web/app/components/editor/blocks/metrics/index.ts @@ -114,6 +114,10 @@ export const MetricBlock = Node.create({ axisBoundsMin: { default: defaults.axisBounds.min ?? null }, axisBoundsMax: { default: defaults.axisBounds.max ?? null }, simulationPreset: { default: defaults.simulationPreset }, + simulationActive: { + default: defaults.simulationActive, + rendered: false, + }, width: { default: MetricBlockWidth.Standard, parseHTML: (element) => diff --git a/web/app/components/editor/blocks/metrics/simulation.ts b/web/app/components/editor/blocks/metrics/simulation.ts index c20a37c9..794c88f5 100644 --- a/web/app/components/editor/blocks/metrics/simulation.ts +++ b/web/app/components/editor/blocks/metrics/simulation.ts @@ -15,6 +15,10 @@ export const DEFAULT_SIMULATION_PRESET = MetricSimulationPreset.CPUUsage // metric went live. export const SIMULATION_CHECK_INTERVAL_MS = 10_000 +// the node attribute behind MetricConfig.simulationActive. The server +// sets it, not a writer, so a branch diff leaves it out +export const SIMULATION_ACTIVE_ATTR = "simulationActive" + // how many points a simulated series aims for across its time range. The // step derived from it is what buckets are aligned to, so a window that // slides forward keeps the points it already showed. diff --git a/web/app/components/editor/blocks/metrics/utils.test.ts b/web/app/components/editor/blocks/metrics/utils.test.ts index a182b1c7..1aae506e 100644 --- a/web/app/components/editor/blocks/metrics/utils.test.ts +++ b/web/app/components/editor/blocks/metrics/utils.test.ts @@ -39,6 +39,7 @@ describe("defaultMetricConfig", () => { unit: { type: null, custom: null }, axisBounds: { min: null, max: null }, simulationPreset: null, + simulationActive: false, }) }) @@ -86,6 +87,7 @@ describe("buildConfigFromNodeAttrs", () => { unit: { type: VisualizationTimeUnit.Seconds, custom: null }, axisBounds: { min: 0, max: 100 }, simulationPreset: null, + simulationActive: false, }) }) @@ -113,6 +115,7 @@ describe("buildConfigFromNodeAttrs", () => { unit: { type: null, custom: null }, axisBounds: { min: null, max: null }, simulationPreset: null, + simulationActive: false, }) }) @@ -146,6 +149,7 @@ describe("buildConfigFromNodeAttrs", () => { unit: { type: VisualizationDataUnit.Megabytes, custom: "reqs" }, axisBounds: { min: -1, max: 1 }, simulationPreset: null, + simulationActive: false, }) }) @@ -157,6 +161,27 @@ describe("buildConfigFromNodeAttrs", () => { ).toBe(MetricSimulationPreset.HTTPLatency) }) + it.for([ + { name: "a set flag", input: true, expected: true }, + { name: "a cleared flag", input: false, expected: false }, + { + name: "a block saved before the flag existed", + input: undefined, + expected: false, + }, + { name: "a flag that is not a boolean", input: "true", expected: false }, + ])( + "reads $name as simulating: $expected", + ({ input, expected }, { expect }) => { + expect( + buildConfigFromNodeAttrs({ + simulationPreset: MetricSimulationPreset.HTTPLatency, + simulationActive: input, + }).simulationActive, + ).toBe(expected) + }, + ) + it("fills defaults when there are no attributes at all", ({ expect }) => { expect(buildConfigFromNodeAttrs({})).toEqual({ title: "", @@ -171,6 +196,7 @@ describe("buildConfigFromNodeAttrs", () => { unit: { type: null, custom: null }, axisBounds: { min: null, max: null }, simulationPreset: null, + simulationActive: false, }) }) }) diff --git a/web/app/components/editor/blocks/metrics/utils.ts b/web/app/components/editor/blocks/metrics/utils.ts index 86cd06c5..dd01fa01 100644 --- a/web/app/components/editor/blocks/metrics/utils.ts +++ b/web/app/components/editor/blocks/metrics/utils.ts @@ -106,9 +106,13 @@ export interface MetricConfig { min?: number | null max?: number | null } - // non-null while the block renders generated data instead of querying - // its data source + // the generated series the block draws while simulationActive is set. + // It stays after the simulation ends, so a block that simulates again + // reuses it. Null on a block nobody has simulated simulationPreset: MetricSimulationPreset | null + // true while the block renders its preset instead of querying its data + // source. The server switches it off once real data answers + simulationActive: boolean } export function defaultMetricConfig(): MetricConfig { @@ -135,6 +139,7 @@ export function defaultMetricConfig(): MetricConfig { max: null, }, simulationPreset: null, + simulationActive: false, } } @@ -171,6 +176,7 @@ export function buildConfigFromNodeAttrs( }, // the legacy blob predates simulation, so it never carries one simulationPreset: null, + simulationActive: false, } } @@ -198,6 +204,7 @@ export function buildConfigFromNodeAttrs( simulationPreset: (attrs.simulationPreset as MetricSimulationPreset | null | undefined) ?? null, + simulationActive: attrs.simulationActive === true, } } diff --git a/web/app/components/editor/diff/compute-merged-document.test.ts b/web/app/components/editor/diff/compute-merged-document.test.ts index ad664146..386f6fcb 100644 --- a/web/app/components/editor/diff/compute-merged-document.test.ts +++ b/web/app/components/editor/diff/compute-merged-document.test.ts @@ -105,6 +105,36 @@ describe("computeMergedDocument", () => { ]) }) + it.for([ + { + name: "a metric block whose only change is its simulation preset as modified", + original: { simulationPreset: "cpu_usage", simulationActive: false }, + modified: { simulationPreset: "error_rate", simulationActive: false }, + expected: DiffStatus.Modified, + }, + { + name: "a metric block whose only change is its simulation flag as unchanged", + original: { simulationPreset: "cpu_usage", simulationActive: true }, + modified: { simulationPreset: "cpu_usage", simulationActive: false }, + expected: DiffStatus.Unchanged, + }, + ])("marks $name", ({ original, modified, expected }) => { + const grid = (attrs: Record): JSONContent => ({ + type: "metricGrid", + attrs: { uid: "g1" }, + content: [{ type: "metricBlock", attrs: { uid: "m1", ...attrs } }], + }) + + const result = computeMergedDocument( + doc(grid(original)), + doc(grid(modified)), + ) + + expect(result.doc.content?.[0]?.content?.[0]?.attrs?.diffStatus).toBe( + expected, + ) + }) + it("matches blocks without uids by content through the LCS fallback", () => { const original = doc(paragraph("same"), paragraph("gone")) const modified = doc(paragraph("same"), paragraph("new")) diff --git a/web/app/components/editor/diff/config.ts b/web/app/components/editor/diff/config.ts index c1779675..83c0c4ee 100644 --- a/web/app/components/editor/diff/config.ts +++ b/web/app/components/editor/diff/config.ts @@ -17,6 +17,7 @@ import Paragraph from "@tiptap/extension-paragraph" import HorizontalRule from "@tiptap/extension-horizontal-rule" import { COMMENT_MARK_NAME } from "~/components/editor/mark-names" import { NODE_COMMENT_ID_ATTR } from "~/components/editor/comments/node-comment-extension" +import { SIMULATION_ACTIVE_ATTR } from "~/components/editor/blocks/metrics/simulation" import { BulletList, OrderedList, @@ -56,7 +57,7 @@ export const MODIFIED_TEXT_CONTENT_TYPES = new Set([MERMAID_BLOCK_NAME]) export const DEFAULT_MERGE_OPTIONS: MergeOptions = { excludeMarks: [COMMENT_MARK_NAME], - excludeAttributes: [NODE_COMMENT_ID_ATTR], + excludeAttributes: [NODE_COMMENT_ID_ATTR, SIMULATION_ACTIVE_ATTR], useUidMatching: true, uidAttribute: "uid", unwrapTypes: [ diff --git a/web/app/components/editor/diff/content-hash.test.ts b/web/app/components/editor/diff/content-hash.test.ts index 82796532..d6c6aaa1 100644 --- a/web/app/components/editor/diff/content-hash.test.ts +++ b/web/app/components/editor/diff/content-hash.test.ts @@ -35,6 +35,42 @@ describe("hashBlockContent", () => { expect(hashBlockContent(commented)).toBe(hashBlockContent(clean)) }) + // the server switches a simulation off on whichever branch is open. + // That is not a user change, so the hash ignores the flag + it("ignores a metric block's simulation flag by default", () => { + const simulating = { + type: "metricBlock", + attrs: { + uid: "m1", + simulationPreset: "cpu_usage", + simulationActive: true, + }, + } + const answered = { + type: "metricBlock", + attrs: { + uid: "m1", + simulationPreset: "cpu_usage", + simulationActive: false, + }, + } + + expect(hashBlockContent(simulating)).toBe(hashBlockContent(answered)) + }) + + it("keeps a metric block's simulation preset significant", () => { + const a = { + type: "metricBlock", + attrs: { uid: "m1", simulationPreset: "cpu_usage" }, + } + const b = { + type: "metricBlock", + attrs: { uid: "m1", simulationPreset: "error_rate" }, + } + + expect(hashBlockContent(a)).not.toBe(hashBlockContent(b)) + }) + it("merges text runs split by a comment boundary", () => { const split = paragraph([ text("hel", [{ type: "comment", attrs: { commentId: "c1" } }]), diff --git a/web/app/components/editor/diff/content-hash.ts b/web/app/components/editor/diff/content-hash.ts index 25a4c06d..9204fe04 100644 --- a/web/app/components/editor/diff/content-hash.ts +++ b/web/app/components/editor/diff/content-hash.ts @@ -1,6 +1,7 @@ import type { JSONContent } from "@tiptap/core" import { COMMENT_MARK_NAME } from "~/components/editor/mark-names" import { NODE_COMMENT_ID_ATTR } from "~/components/editor/comments/node-comment-extension" +import { SIMULATION_ACTIVE_ATTR } from "~/components/editor/blocks/metrics/simulation" export interface HashOptions { /** mark types to strip before hashing (e.g. ['comment']) */ @@ -11,7 +12,7 @@ export interface HashOptions { const DEFAULT_OPTIONS: HashOptions = { excludeMarks: [COMMENT_MARK_NAME], - excludeAttributes: [NODE_COMMENT_ID_ATTR], + excludeAttributes: [NODE_COMMENT_ID_ATTR, SIMULATION_ACTIVE_ATTR], } /** diff --git a/web/app/stores/editor.nuxt.test.ts b/web/app/stores/editor.nuxt.test.ts index 3ce7aee7..1986422a 100644 --- a/web/app/stores/editor.nuxt.test.ts +++ b/web/app/stores/editor.nuxt.test.ts @@ -28,6 +28,7 @@ function metricConfig(title: string): MetricConfig { unit: {}, axisBounds: {}, simulationPreset: null, + simulationActive: false, } }