Always convert empty list to nil when saving orderIDs index.

This commit is contained in:
max furman 2020-06-01 18:04:51 -07:00
parent 619f6f6ce0
commit 41a1a053d8
3 changed files with 72 additions and 4 deletions

View file

@ -516,7 +516,7 @@ func Test_newOrder(t *testing.T) {
}
}
func TestOrderIDsSave(t *testing.T) {
func TestOrderIDs_save(t *testing.T) {
accID := "acc-id"
newOids := func() orderIDs {
return []string{"1", "2"}
@ -591,6 +591,26 @@ func TestOrderIDsSave(t *testing.T) {
},
}
},
"ok/new-empty-saved-as-nil": func(t *testing.T) test {
oldOids := newOids()
oids := []string{}
oldb, err := json.Marshal(oldOids)
assert.FatalError(t, err)
return test{
oids: oids,
old: oldOids,
db: &db.MockNoSQLDB{
MCmpAndSwap: func(bucket, key, old, newval []byte) ([]byte, bool, error) {
assert.Equals(t, old, oldb)
assert.Equals(t, newval, nil)
assert.Equals(t, bucket, ordersByAccountIDTable)
assert.Equals(t, key, []byte(accID))
return nil, true, nil
},
},
}
},
}
for name, run := range tests {
t.Run(name, func(t *testing.T) {