Fix FakeNodeHandler Update behaviour
Two problems: 1. Get is always using Existing nodes slice, and you will for sure miss any updated data 2. Each Update duplicates node entry in UpdatedNodes slice For the 1st, try to find a node in UpdatedNodes slice (same as for the List). 2nd - append only if there is no node with same name as updated, if there is just replace object. Change-Id: I9ef1cca2788ba946eee37fa1b037c124ad76074c
This commit is contained in:
parent
8f4c0bbcb7
commit
0ddaa20bf1
@ -107,6 +107,12 @@ func (m *FakeNodeHandler) Get(name string) (*api.Node, error) {
|
||||
m.RequestCount++
|
||||
m.lock.Unlock()
|
||||
}()
|
||||
for i := range m.UpdatedNodes {
|
||||
if m.UpdatedNodes[i].Name == name {
|
||||
nodeCopy := *m.UpdatedNodes[i]
|
||||
return &nodeCopy, nil
|
||||
}
|
||||
}
|
||||
for i := range m.Existing {
|
||||
if m.Existing[i].Name == name {
|
||||
nodeCopy := *m.Existing[i]
|
||||
@ -169,6 +175,12 @@ func (m *FakeNodeHandler) Update(node *api.Node) (*api.Node, error) {
|
||||
m.lock.Unlock()
|
||||
}()
|
||||
nodeCopy := *node
|
||||
for i, updateNode := range m.UpdatedNodes {
|
||||
if updateNode.Name == nodeCopy.Name {
|
||||
m.UpdatedNodes[i] = &nodeCopy
|
||||
return node, nil
|
||||
}
|
||||
}
|
||||
m.UpdatedNodes = append(m.UpdatedNodes, &nodeCopy)
|
||||
return node, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user