mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 18:19:36 +00:00
matchbox/storage: Add Ignition deletes to the Store
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user