Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
controller: Move app deletion tests into integration suite
Browse files Browse the repository at this point in the history
This is because app deletion now happens in a background worker, which
does not run in the unit tests.

Signed-off-by: Lewis Marshall <lewis@lmars.net>
  • Loading branch information
lmars committed May 26, 2015
1 parent 05520d4 commit a8c4f85
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 67 deletions.
65 changes: 0 additions & 65 deletions controller/controller_test.go
Expand Up @@ -157,71 +157,6 @@ func (s *S) TestUpdateApp(c *C) {
c.Assert(app.Meta, DeepEquals, meta)
}

func (s *S) TestDeleteApp(c *C) {
for i, useName := range []bool{false, true} {
app := s.createTestApp(c, &ct.App{Name: fmt.Sprintf("delete-app-%d", i)})

var appID string
if useName {
appID = app.Name
} else {
appID = app.ID
}
_, err := s.c.DeleteApp(appID)
c.Assert(err, IsNil)

_, err = s.c.GetApp(appID)
c.Assert(err, Equals, controller.ErrNotFound)
}
}

func (s *S) TestDeleteAppUUIDName(c *C) {
for _, useName := range []bool{false, true} {
app := s.createTestApp(c, &ct.App{Name: random.UUID()})

var appID string
if useName {
appID = app.Name
} else {
appID = app.ID
}
_, err := s.c.DeleteApp(appID)
c.Assert(err, IsNil)

_, err = s.c.GetApp(appID)
c.Assert(err, Equals, controller.ErrNotFound)
}
}

func (s *S) TestDeleteNonExistentApp(c *C) {
for _, useUUID := range []bool{false, true} {
var appID string

if useUUID {
appID = "foobar"
} else {
appID = random.UUID()
}
_, err := s.c.DeleteApp(appID)
c.Assert(err, Equals, controller.ErrNotFound)
}
}

func (s *S) TestRecreateApp(c *C) {
app := s.createTestApp(c, &ct.App{Name: "recreate-app"})

// Post a duplicate
c.Assert(s.c.CreateApp(&ct.App{Name: "recreate-app"}), Not(IsNil)) // TODO: This should probably be a 4xx error

// Delete the original
_, err := s.c.DeleteApp(app.ID)
c.Assert(err, IsNil)

// Create the same key
app = s.createTestApp(c, &ct.App{Name: "recreate-app"})
c.Assert(app.Name, Equals, "recreate-app")
}

func (s *S) createTestArtifact(c *C, in *ct.Artifact) *ct.Artifact {
if in.Type == "" {
in.Type = "docker"
Expand Down
88 changes: 86 additions & 2 deletions test/test_controller.go
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/cupcake/jsonschema"
c "github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-check"
"github.com/flynn/flynn/cli/config"
"github.com/flynn/flynn/controller/client"
ct "github.com/flynn/flynn/controller/types"
"github.com/flynn/flynn/pkg/cluster"
"github.com/flynn/flynn/pkg/exec"
Expand Down Expand Up @@ -237,8 +238,85 @@ func (s *ControllerSuite) TestResourceLimitsReleaseJob(t *c.C) {
assertResourceLimits(t, log.Output)
}

func (s *ControllerSuite) TestAppDeletion(t *c.C) {
app := "app-deletion-" + random.String(8)
func (s *ControllerSuite) TestAppDelete(t *c.C) {
client := s.controllerClient(t)

type test struct {
desc string
name string
create bool
useName bool
delErr error
}

for _, s := range []test{
{
desc: "delete existing app by name",
name: "app-delete-" + random.String(8),
create: true,
useName: true,
delErr: nil,
},
{
desc: "delete existing app by id",
name: "app-delete-" + random.String(8),
create: true,
useName: false,
delErr: nil,
},
{
desc: "delete existing UUID app by name",
name: random.UUID(),
create: true,
useName: true,
delErr: nil,
},
{
desc: "delete existing UUID app by id",
name: random.UUID(),
create: true,
useName: false,
delErr: nil,
},
{
desc: "delete non-existent app",
name: "i-dont-exist",
create: false,
useName: true,
delErr: controller.ErrNotFound,
},
{
desc: "delete non-existent UUID app",
name: random.UUID(),
create: false,
useName: true,
delErr: controller.ErrNotFound,
},
} {
debugf(t, "TestAppDelete: %s", s.desc)

app := &ct.App{Name: s.name}
if s.create {
t.Assert(client.CreateApp(app), c.IsNil)
}

appID := app.ID
if s.useName {
appID = app.Name
}

_, err := client.DeleteApp(appID)
t.Assert(err, c.Equals, s.delErr)

if s.delErr == nil {
_, err = client.GetApp(appID)
t.Assert(err, c.Equals, controller.ErrNotFound)
}
}
}

func (s *ControllerSuite) TestAppDeleteCleanup(t *c.C) {
app := "app-delete-cleanup-" + random.String(8)
client := s.controllerClient(t)

// create and push app
Expand Down Expand Up @@ -293,4 +371,10 @@ func (s *ControllerSuite) TestAppDeletion(t *c.C) {

// check resource cleanup
t.Assert(cmd, OutputContains, fmt.Sprintf("deprovisioned %d resources", numResources))

// check creating and pushing same app name succeeds
t.Assert(os.RemoveAll(r.dir), c.IsNil)
r = s.newGitRepo(t, "http")
t.Assert(r.flynn("create", app), Succeeds)
t.Assert(r.git("push", "flynn", "master"), Succeeds)
}

0 comments on commit a8c4f85

Please sign in to comment.