types: persist Node JSON slices via named IsZero types
Endpoints, Tags and ApprovedRoutes serialize as JSON on Node. GORM's
struct Updates path skips fields it considers zero, and reflect treats
a nil slice as zero — clearing any of these columns via the State
persist path would leave the previous value in the database.
Introduce Strings, Prefixes and AddrPorts as named slice types whose
IsZero() always reports false, so GORM keeps the column in the UPDATE
regardless of the slice being nil or empty. JSON marshalling is
unchanged: nil serializes to null, empty to []. List() returns the
underlying unnamed slice for callers (mainly testify assertions over
reflect.DeepEqual) that distinguish the named type from its base.
Regenerated types_clone.go and types_view.go follow the field-type
swap. Test assertions across hscontrol/{db,state,servertest} updated
to call .List() where reflect.DeepEqual previously matched the raw
slice type.
Fixes #3110
This commit is contained in:
parent
e78a24b892
commit
7a20db9f49
8 changed files with 64 additions and 18 deletions
|
|
@ -684,7 +684,7 @@ func TestNodeStoreOperations(t *testing.T) {
|
|||
finalNode := snapshot.nodesByID[1]
|
||||
assert.Equal(t, "multi-update-hostname", finalNode.Hostname)
|
||||
assert.Equal(t, "multi-update-givenname", finalNode.GivenName)
|
||||
assert.Equal(t, []string{"tag1", "tag2"}, finalNode.Tags)
|
||||
assert.Equal(t, []string{"tag1", "tag2"}, finalNode.Tags.List())
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -722,14 +722,14 @@ func TestNodeStoreOperations(t *testing.T) {
|
|||
assert.NotNil(t, nodePtr)
|
||||
assert.Equal(t, "db-save-hostname", nodePtr.Hostname)
|
||||
assert.Equal(t, "db-save-given", nodePtr.GivenName)
|
||||
assert.Equal(t, []string{"db-tag1", "db-tag2"}, nodePtr.Tags)
|
||||
assert.Equal(t, []string{"db-tag1", "db-tag2"}, nodePtr.Tags.List())
|
||||
|
||||
// Verify the snapshot also reflects the same state
|
||||
snapshot := store.data.Load()
|
||||
storedNode := snapshot.nodesByID[1]
|
||||
assert.Equal(t, "db-save-hostname", storedNode.Hostname)
|
||||
assert.Equal(t, "db-save-given", storedNode.GivenName)
|
||||
assert.Equal(t, []string{"db-tag1", "db-tag2"}, storedNode.Tags)
|
||||
assert.Equal(t, []string{"db-tag1", "db-tag2"}, storedNode.Tags.List())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -792,15 +792,15 @@ func TestNodeStoreOperations(t *testing.T) {
|
|||
// All should have the complete final state
|
||||
assert.Equal(t, "concurrent-db-hostname", nodePtr1.Hostname)
|
||||
assert.Equal(t, "concurrent-db-given", nodePtr1.GivenName)
|
||||
assert.Equal(t, []string{"concurrent-tag"}, nodePtr1.Tags)
|
||||
assert.Equal(t, []string{"concurrent-tag"}, nodePtr1.Tags.List())
|
||||
|
||||
assert.Equal(t, "concurrent-db-hostname", nodePtr2.Hostname)
|
||||
assert.Equal(t, "concurrent-db-given", nodePtr2.GivenName)
|
||||
assert.Equal(t, []string{"concurrent-tag"}, nodePtr2.Tags)
|
||||
assert.Equal(t, []string{"concurrent-tag"}, nodePtr2.Tags.List())
|
||||
|
||||
assert.Equal(t, "concurrent-db-hostname", nodePtr3.Hostname)
|
||||
assert.Equal(t, "concurrent-db-given", nodePtr3.GivenName)
|
||||
assert.Equal(t, []string{"concurrent-tag"}, nodePtr3.Tags)
|
||||
assert.Equal(t, []string{"concurrent-tag"}, nodePtr3.Tags.List())
|
||||
|
||||
// Verify consistency with stored state
|
||||
snapshot := store.data.Load()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue