Commit 0ddaa20b authored by Dmitry Shulyak's avatar Dmitry Shulyak

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
parent 8f4c0bbc
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment