store: Return an error from DeleteBlueprint and DeleteBlueprintFromWorkspace

If an unknown blueprint or workspace is deleted it will now return an
error.

Also fixes the blueprints DELETE handlers to return the correct error to
the client. Includes a new test.
This commit is contained in:
Brian C. Lane 2020-03-10 17:01:04 -07:00 committed by Tom Gundersen
parent 2675eff4eb
commit b4710b52f1
3 changed files with 32 additions and 8 deletions

View file

@ -431,18 +431,27 @@ func (s *Store) PushBlueprintToWorkspace(bp blueprint.Blueprint) error {
})
}
func (s *Store) DeleteBlueprint(name string) {
// FIXME: handle or comment this possible error
_ = s.change(func() error {
// DeleteBlueprint will remove the named blueprint from the store
// if the blueprint does not exist it will return an error
// The workspace copy is deleted unconditionally, it will not return an error if it does not exist.
func (s *Store) DeleteBlueprint(name string) error {
return s.change(func() error {
delete(s.Workspace, name)
if _, ok := s.Blueprints[name]; !ok {
return fmt.Errorf("Unknown blueprint: %s", name)
}
delete(s.Blueprints, name)
return nil
})
}
func (s *Store) DeleteBlueprintFromWorkspace(name string) {
// FIXME: handle or comment this possible error
_ = s.change(func() error {
// DeleteBlueprintFromWorkspace deletes the workspace copy of a blueprint
// if the blueprint doesn't exist in the workspace it returns an error
func (s *Store) DeleteBlueprintFromWorkspace(name string) error {
return s.change(func() error {
if _, ok := s.Workspace[name]; !ok {
return fmt.Errorf("Unknown blueprint: %s", name)
}
delete(s.Workspace, name)
return nil
})