Skip to content

Commit

Permalink
deleting the default stack should error
Browse files Browse the repository at this point in the history
  • Loading branch information
dgodd committed Oct 4, 2018
1 parent 1da8be1 commit f44f008
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (c *Config) Add(stack Stack) error {
}

func (c *Config) Delete(stackName string) error {
if c.DefaultStackID == stackName {
return fmt.Errorf(`%s cannot be deleted when it is the default stack. You can change your default stack by running "pack set-default-stack".`, stackName)
}
for i, s := range c.Stacks {
if s.ID == stackName {
c.Stacks = append(c.Stacks[:i], c.Stacks[i+1:]...)
Expand Down
9 changes: 9 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ default-stack-id = "my.stack"
var subject *config.Config
it.Before(func() {
assertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "config.toml"), []byte(`
default-stack-id = "stack-1"
[[stacks]]
id = "stack-1"
[[stacks]]
Expand Down Expand Up @@ -308,6 +309,14 @@ default-stack-id = "my.stack"
assertEq(t, err.Error(), `stack "other.stack" does not exist`)
})
})

when("stack to be deleted is the default-stack-id", func() {
it("errors and leaves file unchanged", func() {
err := subject.Delete("stack-1")
assertNotNil(t, err)
assertEq(t, err.Error(), `stack-1 cannot be deleted when it is the default stack. You can change your default stack by running "pack set-default-stack".`)
})
})
})

when("ImageByRegistry", func() {
Expand Down

0 comments on commit f44f008

Please sign in to comment.