From 5fdc64238cbfae762014a1e9666e4370b92d88d7 Mon Sep 17 00:00:00 2001 From: Rangel Reale Date: Tue, 17 Oct 2023 16:22:40 -0300 Subject: [PATCH] allows empty table ID in data.Merge --- table.go | 6 +++++- table_test.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/table.go b/table.go index cbe7ddb..5ecdfd2 100644 --- a/table.go +++ b/table.go @@ -39,7 +39,11 @@ type Table struct { // Merge merges source into d. A deep copy is done to ensure source is never modified. func (t *Table) Merge(source *Table) error { - if source.ID != t.ID { + if source.ID != "" && t.ID == "" { + t.ID = source.ID + } else if source.ID == "" && t.ID != "" { + // do nothing, can't change source + } else if source.ID != t.ID { return fmt.Errorf("table IDs don't match (%s - %s)", source.ID, t.ID) } diff --git a/table_test.go b/table_test.go index 70bbe64..76d46b9 100644 --- a/table_test.go +++ b/table_test.go @@ -108,7 +108,7 @@ func TestDataMerge(t *testing.T) { data2 := &Data{ Tables: map[string]*Table{ "tags": { - ID: "tags", + // ID: "tags", // if data already exists, not setting will keep previous value Rows: Rows{ Row{Fields: map[string]any{"x": 3}}, Row{Fields: map[string]any{"x": 4}},