mirror of https://github.com/docker/cli.git
cli/context/store: removeAllContextData(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and path internally. This also fixes a test which incorrectly used "names" as pseudo-IDs. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f843c42c05
commit
d0398c423f
|
@ -136,11 +136,10 @@ func (s *store) CreateOrUpdate(meta Metadata) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) Remove(name string) error {
|
func (s *store) Remove(name string) error {
|
||||||
id := contextdirOf(name)
|
|
||||||
if err := s.meta.remove(name); err != nil {
|
if err := s.meta.remove(name); err != nil {
|
||||||
return patchErrContextName(err, name)
|
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) {
|
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 {
|
func (s *store) ResetTLSMaterial(name string, data *ContextTLSData) error {
|
||||||
id := contextdirOf(name)
|
id := contextdirOf(name)
|
||||||
if err := s.tls.removeAllContextData(id); err != nil {
|
if err := s.tls.removeAllContextData(name); err != nil {
|
||||||
return patchErrContextName(err, name)
|
return patchErrContextName(err, name)
|
||||||
}
|
}
|
||||||
if data == nil {
|
if data == nil {
|
||||||
|
|
|
@ -55,8 +55,8 @@ func (s *tlsStore) removeAllEndpointData(contextID contextdir, endpointName stri
|
||||||
return os.RemoveAll(s.endpointDir(contextID, endpointName))
|
return os.RemoveAll(s.endpointDir(contextID, endpointName))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *tlsStore) removeAllContextData(contextID contextdir) error {
|
func (s *tlsStore) removeAllContextData(name string) error {
|
||||||
return os.RemoveAll(s.contextDir(contextID))
|
return os.RemoveAll(s.contextDir(contextdirOf(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *tlsStore) listContextData(contextID contextdir) (map[string]EndpointFiles, error) {
|
func (s *tlsStore) listContextData(contextID contextdir) (map[string]EndpointFiles, error) {
|
||||||
|
|
|
@ -45,26 +45,28 @@ func TestTlsListAndBatchRemove(t *testing.T) {
|
||||||
"ep2": {"f1", "f2", "f3"},
|
"ep2": {"f1", "f2", "f3"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contextName = "test-ctx"
|
||||||
|
contextID := contextdirOf(contextName)
|
||||||
for name, files := range all {
|
for name, files := range all {
|
||||||
for _, file := range files {
|
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)
|
assert.NilError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resAll, err := testee.listContextData("test-ctx")
|
resAll, err := testee.listContextData(contextID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.DeepEqual(t, resAll, all)
|
assert.DeepEqual(t, resAll, all)
|
||||||
|
|
||||||
err = testee.removeAllEndpointData("test-ctx", "ep3")
|
err = testee.removeAllEndpointData(contextID, "ep3")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
resEp1ep2, err := testee.listContextData("test-ctx")
|
resEp1ep2, err := testee.listContextData(contextID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.DeepEqual(t, resEp1ep2, ep1ep2)
|
assert.DeepEqual(t, resEp1ep2, ep1ep2)
|
||||||
|
|
||||||
err = testee.removeAllContextData("test-ctx")
|
err = testee.removeAllContextData(contextName)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
resEmpty, err := testee.listContextData("test-ctx")
|
resEmpty, err := testee.listContextData(contextID)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{})
|
assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue