Skip to content

Commit

Permalink
allows empty table ID in data.Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Oct 17, 2023
1 parent 541e4f8 commit 5fdc642
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down

0 comments on commit 5fdc642

Please sign in to comment.