From 0618c29be295087eb8765ad68c72fcbe6d6c0f99 Mon Sep 17 00:00:00 2001 From: Anton Tiurin Date: Thu, 2 Apr 2015 00:01:38 +0300 Subject: [PATCH] [Store] Drop an index variable in Store.All Signed-off-by: Anton Tiurin --- state/store.go | 6 ++---- state/store_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/state/store.go b/state/store.go index 94a73253a9..0c5b6addce 100644 --- a/state/store.go +++ b/state/store.go @@ -122,11 +122,9 @@ func (s *Store) All() []*RequestedState { s.RLock() defer s.RUnlock() - states := make([]*RequestedState, len(s.values)) - i := 0 + states := make([]*RequestedState, 0, len(s.values)) for _, state := range s.values { - states[i] = state - i = i + 1 + states = append(states, state) } return states } diff --git a/state/store_test.go b/state/store_test.go index 7eb379cb91..1c903f944f 100644 --- a/state/store_test.go +++ b/state/store_test.go @@ -40,6 +40,14 @@ func TestStore(t *testing.T) { assert.NoError(t, err) assert.Equal(t, c2.Name, ret.Name) + // Only one item in the store + all := store.All() + assert.Equal(t, 1, len(all)) + // The same name + assert.Equal(t, c2.Name, all[0].Name) + // It's actually the same pointer + assert.Equal(t, c2, all[0]) + // Initialize a brand new store and retrieve "foo" again. // This is to ensure data load on initialization works correctly. store = NewStore(dir)