From 712cc9a1c7ee91521ed334d339878bd67aa3895c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 28 Sep 2022 17:47:30 +0200 Subject: [PATCH] cli/context/store: remove(): accept name instead of ID This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn --- cli/context/store/tlsstore.go | 6 ++++-- cli/context/store/tlsstore_test.go | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cli/context/store/tlsstore.go b/cli/context/store/tlsstore.go index ec1dd43de2..777c9c04f0 100644 --- a/cli/context/store/tlsstore.go +++ b/cli/context/store/tlsstore.go @@ -44,8 +44,10 @@ func (s *tlsStore) getData(name, endpointName, filename string) ([]byte, error) return data, nil } -func (s *tlsStore) remove(contextID contextdir, endpointName, filename string) error { - err := os.Remove(s.filePath(contextID, endpointName, filename)) +// remove removes a TLS data from an endpoint +// TODO(thaJeztah) tlsStore.remove() is not used anywhere outside of tests; should we use removeAllEndpointData() only? +func (s *tlsStore) remove(name, endpointName, filename string) error { + err := os.Remove(s.filePath(contextdirOf(name), endpointName, filename)) if os.IsNotExist(err) { return nil } diff --git a/cli/context/store/tlsstore_test.go b/cli/context/store/tlsstore_test.go index 66b3d4ffd7..3f6b6c4443 100644 --- a/cli/context/store/tlsstore_test.go +++ b/cli/context/store/tlsstore_test.go @@ -10,7 +10,6 @@ func TestTlsCreateUpdateGetRemove(t *testing.T) { testee := tlsStore{root: t.TempDir()} const contextName = "test-ctx" - contextID := contextdirOf(contextName) _, err := testee.getData(contextName, "test-ep", "test-data") assert.Equal(t, true, IsErrTLSDataDoesNotExist(err)) @@ -26,9 +25,9 @@ func TestTlsCreateUpdateGetRemove(t *testing.T) { assert.NilError(t, err) assert.Equal(t, string(data), "data2") - err = testee.remove(contextID, "test-ep", "test-data") + err = testee.remove(contextName, "test-ep", "test-data") assert.NilError(t, err) - err = testee.remove(contextID, "test-ep", "test-data") + err = testee.remove(contextName, "test-ep", "test-data") assert.NilError(t, err) _, err = testee.getData(contextName, "test-ep", "test-data")