From 6bbf4a30a646e608ca504ef894946781dcedfd1a Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Tue, 11 Apr 2017 12:00:28 -0700 Subject: [PATCH] matchbox/storage: Add Ignition deletes to the Store --- matchbox/storage/filestore.go | 5 +++++ matchbox/storage/filestore_test.go | 15 ++++++++++++--- matchbox/storage/storage.go | 2 ++ matchbox/storage/testfakes/broken_store.go | 5 +++++ matchbox/storage/testfakes/empty_store.go | 5 +++++ matchbox/storage/testfakes/fixed_store.go | 6 ++++++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/matchbox/storage/filestore.go b/matchbox/storage/filestore.go index 3caa633f..4656f6ef 100644 --- a/matchbox/storage/filestore.go +++ b/matchbox/storage/filestore.go @@ -141,6 +141,11 @@ func (s *fileStore) IgnitionGet(name string) (string, error) { return string(data), err } +// IgnitionDelete deletes an Ignition template by name. +func (s *fileStore) IgnitionDelete(name string) error { + return Dir(s.root).deleteFile(filepath.Join("ignition", name)) +} + // CloudGet gets a Cloud-Config template by name. func (s *fileStore) CloudGet(name string) (string, error) { data, err := Dir(s.root).readFile(filepath.Join("cloud", name)) diff --git a/matchbox/storage/filestore_test.go b/matchbox/storage/filestore_test.go index b6aa8919..6f46494d 100644 --- a/matchbox/storage/filestore_test.go +++ b/matchbox/storage/filestore_test.go @@ -13,7 +13,7 @@ import ( fake "github.com/coreos/matchbox/matchbox/storage/testfakes" ) -func TestGroupPutAndDelete(t *testing.T) { +func TestGroupCRUD(t *testing.T) { dir, err := setup(&fake.FixedStore{}) assert.Nil(t, err) defer os.RemoveAll(dir) @@ -91,7 +91,7 @@ func TestGroupList(t *testing.T) { } } -func TestProfilePutAndDelete(t *testing.T) { +func TestProfileCRUD(t *testing.T) { dir, err := setup(&fake.FixedStore{}) assert.Nil(t, err) defer os.RemoveAll(dir) @@ -148,7 +148,7 @@ func TestProfileList(t *testing.T) { } } -func TestIgnitionPut(t *testing.T) { +func TestIgnitionCRUD(t *testing.T) { dir, err := setup(&fake.FixedStore{}) assert.Nil(t, err) defer os.RemoveAll(dir) @@ -157,11 +157,20 @@ func TestIgnitionPut(t *testing.T) { // assert that: // - Ignition template creation was successful // - Ignition template can be retrieved by name + // - Ignition template can be deleted by name err = store.IgnitionPut(fake.IgnitionYAMLName, []byte(fake.IgnitionYAML)) assert.Nil(t, err) + template, err := store.IgnitionGet(fake.IgnitionYAMLName) assert.Nil(t, err) assert.Equal(t, fake.IgnitionYAML, template) + + err = store.IgnitionDelete(fake.IgnitionYAMLName) + assert.Nil(t, err) + _, err = store.IgnitionGet(fake.IgnitionYAMLName) + if assert.Error(t, err) { + assert.IsType(t, err, &os.PathError{}) + } } func TestIgnitionGet(t *testing.T) { diff --git a/matchbox/storage/storage.go b/matchbox/storage/storage.go index 1343a95a..b77ab05b 100644 --- a/matchbox/storage/storage.go +++ b/matchbox/storage/storage.go @@ -36,6 +36,8 @@ type Store interface { IgnitionPut(name string, config []byte) error // IgnitionGet gets an Ignition template by name. IgnitionGet(name string) (string, error) + // IgnitionDelete deletes an Ignition template by name. + IgnitionDelete(name string) error // CloudGet gets a Cloud-Config template by name. CloudGet(name string) (string, error) diff --git a/matchbox/storage/testfakes/broken_store.go b/matchbox/storage/testfakes/broken_store.go index 32cf7073..798488a4 100644 --- a/matchbox/storage/testfakes/broken_store.go +++ b/matchbox/storage/testfakes/broken_store.go @@ -63,6 +63,11 @@ func (s *BrokenStore) IgnitionGet(name string) (string, error) { return "", errIntentional } +// IgnitionDelete returns an error. +func (s *BrokenStore) IgnitionDelete(name string) error { + return errIntentional +} + // CloudGet returns an error. func (s *BrokenStore) CloudGet(name string) (string, error) { return "", errIntentional diff --git a/matchbox/storage/testfakes/empty_store.go b/matchbox/storage/testfakes/empty_store.go index 64daaba1..392bc944 100644 --- a/matchbox/storage/testfakes/empty_store.go +++ b/matchbox/storage/testfakes/empty_store.go @@ -59,6 +59,11 @@ func (s *EmptyStore) IgnitionGet(name string) (string, error) { return "", fmt.Errorf("no Ignition template %s", name) } +// IgnitionDelete returns a nil error (successful deletion). +func (s *EmptyStore) IgnitionDelete(name string) error { + return nil +} + // CloudGet returns a Cloud-config template not found error. func (s *EmptyStore) CloudGet(name string) (string, error) { return "", fmt.Errorf("no Cloud-Config template %s", name) diff --git a/matchbox/storage/testfakes/fixed_store.go b/matchbox/storage/testfakes/fixed_store.go index 49800365..c36dd565 100644 --- a/matchbox/storage/testfakes/fixed_store.go +++ b/matchbox/storage/testfakes/fixed_store.go @@ -102,6 +102,12 @@ func (s *FixedStore) IgnitionGet(name string) (string, error) { return "", fmt.Errorf("no Ignition template %s", name) } +// IgnitionDelete deletes an Ignition template by name. +func (s *FixedStore) IgnitionDelete(name string) error { + delete(s.IgnitionConfigs, name) + return nil +} + // CloudGet returns a Cloud-config template by name. func (s *FixedStore) CloudGet(name string) (string, error) { if config, present := s.CloudConfigs[name]; present {