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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-28 17:47:30 +02:00
parent 0bcdff2571
commit 712cc9a1c7
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 6 additions and 5 deletions

View File

@ -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
}

View File

@ -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")