diff --git a/cli/context/store/store.go b/cli/context/store/store.go index d4657b99bd..03fac95515 100644 --- a/cli/context/store/store.go +++ b/cli/context/store/store.go @@ -136,11 +136,10 @@ func (s *store) CreateOrUpdate(meta Metadata) error { } func (s *store) Remove(name string) error { - id := contextdirOf(name) if err := s.meta.remove(name); err != nil { return patchErrContextName(err, name) } - return patchErrContextName(s.tls.removeAllContextData(id), name) + return patchErrContextName(s.tls.removeAllContextData(name), name) } func (s *store) GetMetadata(name string) (Metadata, error) { @@ -151,7 +150,7 @@ func (s *store) GetMetadata(name string) (Metadata, error) { func (s *store) ResetTLSMaterial(name string, data *ContextTLSData) error { id := contextdirOf(name) - if err := s.tls.removeAllContextData(id); err != nil { + if err := s.tls.removeAllContextData(name); err != nil { return patchErrContextName(err, name) } if data == nil { diff --git a/cli/context/store/tlsstore.go b/cli/context/store/tlsstore.go index 8267e87964..9b1eda5891 100644 --- a/cli/context/store/tlsstore.go +++ b/cli/context/store/tlsstore.go @@ -55,8 +55,8 @@ func (s *tlsStore) removeAllEndpointData(contextID contextdir, endpointName stri return os.RemoveAll(s.endpointDir(contextID, endpointName)) } -func (s *tlsStore) removeAllContextData(contextID contextdir) error { - return os.RemoveAll(s.contextDir(contextID)) +func (s *tlsStore) removeAllContextData(name string) error { + return os.RemoveAll(s.contextDir(contextdirOf(name))) } func (s *tlsStore) listContextData(contextID contextdir) (map[string]EndpointFiles, error) { diff --git a/cli/context/store/tlsstore_test.go b/cli/context/store/tlsstore_test.go index 5af9acda3b..80b5d0d5f2 100644 --- a/cli/context/store/tlsstore_test.go +++ b/cli/context/store/tlsstore_test.go @@ -45,26 +45,28 @@ func TestTlsListAndBatchRemove(t *testing.T) { "ep2": {"f1", "f2", "f3"}, } + const contextName = "test-ctx" + contextID := contextdirOf(contextName) for name, files := range all { for _, file := range files { - err := testee.createOrUpdate("test-ctx", name, file, []byte("data")) + err := testee.createOrUpdate(contextID, name, file, []byte("data")) assert.NilError(t, err) } } - resAll, err := testee.listContextData("test-ctx") + resAll, err := testee.listContextData(contextID) assert.NilError(t, err) assert.DeepEqual(t, resAll, all) - err = testee.removeAllEndpointData("test-ctx", "ep3") + err = testee.removeAllEndpointData(contextID, "ep3") assert.NilError(t, err) - resEp1ep2, err := testee.listContextData("test-ctx") + resEp1ep2, err := testee.listContextData(contextID) assert.NilError(t, err) assert.DeepEqual(t, resEp1ep2, ep1ep2) - err = testee.removeAllContextData("test-ctx") + err = testee.removeAllContextData(contextName) assert.NilError(t, err) - resEmpty, err := testee.listContextData("test-ctx") + resEmpty, err := testee.listContextData(contextID) assert.NilError(t, err) assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{}) }