本文整理匯總了Golang中github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-check.Not函數的典型用法代碼示例。如果您正苦於以下問題:Golang Not函數的具體用法?Golang Not怎麽用?Golang Not使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Not函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testApp
func testApp(s *CLISuite, t *c.C, remote string) {
app := s.newGitRepo(t, "")
name := random.String(30)
flynnRemote := fmt.Sprintf("%s\tssh://[email protected]%s/%s.git (push)", remote, s.clusterConf(t).GitHost, name)
if remote == "flynn" {
t.Assert(app.flynn("create", "-y", name), Outputs, fmt.Sprintf("Created %s\n", name))
} else {
t.Assert(app.flynn("create", "-r", remote, "-y", name), Outputs, fmt.Sprintf("Created %s\n", name))
}
t.Assert(app.flynn("apps"), SuccessfulOutputContains, name)
t.Assert(app.flynn("-c", "default", "apps"), SuccessfulOutputContains, name)
if remote == "" {
t.Assert(app.git("remote", "-v"), c.Not(SuccessfulOutputContains), flynnRemote)
} else {
t.Assert(app.git("remote", "-v"), SuccessfulOutputContains, flynnRemote)
}
// make sure flynn components are listed
t.Assert(app.flynn("apps"), SuccessfulOutputContains, "router")
t.Assert(app.flynn("-c", "default", "apps"), SuccessfulOutputContains, "router")
// flynn delete
if remote == "flynn" {
t.Assert(app.flynn("delete", "--yes"), Succeeds)
} else {
if remote == "" {
t.Assert(app.flynn("-a", name, "delete", "--yes", "-r", remote), Succeeds)
} else {
t.Assert(app.flynn("delete", "--yes", "-r", remote), Succeeds)
}
}
t.Assert(app.git("remote", "-v"), c.Not(SuccessfulOutputContains), flynnRemote)
}
示例2: TestKey
func (s *CLISuite) TestKey(t *c.C) {
app := s.newGitRepo(t, "empty")
t.Assert(app.flynn("create"), Succeeds)
t.Assert(app.flynn("key", "add", s.sshKeys(t).Pub), Succeeds)
// calculate fingerprint
data, err := ioutil.ReadFile(s.sshKeys(t).Pub)
t.Assert(err, c.IsNil)
pubKey, _, _, _, err := ssh.ParseAuthorizedKey(data)
t.Assert(err, c.IsNil)
digest := md5.Sum(pubKey.Marshal())
fingerprint := formatKeyID(hex.EncodeToString(digest[:]))
t.Assert(app.flynn("key"), SuccessfulOutputContains, fingerprint)
t.Assert(app.git("commit", "--allow-empty", "-m", "should succeed"), Succeeds)
t.Assert(app.git("push", "flynn", "master"), Succeeds)
t.Assert(app.flynn("key", "remove", fingerprint), Succeeds)
t.Assert(app.flynn("key"), c.Not(SuccessfulOutputContains), fingerprint)
t.Assert(app.git("commit", "--allow-empty", "-m", "should fail"), Succeeds)
t.Assert(app.git("push", "flynn", "master"), c.Not(Succeeds))
t.Assert(app.flynn("delete", "--yes"), Succeeds)
}
示例3: TestMeta
func (s *CLISuite) TestMeta(t *c.C) {
app := s.newCliTestApp(t)
t.Assert(app.flynn("meta", "set", "META_TEST=var", "SECOND_VAL=2"), Succeeds)
t.Assert(app.flynn("meta").Output, Matches, `META_TEST *var`)
t.Assert(app.flynn("meta").Output, Matches, `SECOND_VAL *2`)
// test that unset can remove all meta tags
t.Assert(app.flynn("meta", "unset", "META_TEST", "SECOND_VAL"), Succeeds)
t.Assert(app.flynn("meta").Output, c.Not(Matches), `META_TEST *var`)
t.Assert(app.flynn("meta").Output, c.Not(Matches), `SECOND_VAL *2`)
}
示例4: TestCluster
func (s *CLISuite) TestCluster(t *c.C) {
// use a custom flynnrc to avoid disrupting other tests
file, err := ioutil.TempFile("", "")
t.Assert(err, c.IsNil)
flynn := func(cmdArgs ...string) *CmdResult {
cmd := exec.Command(args.CLI, cmdArgs...)
cmd.Env = flynnEnv(file.Name())
return run(t, cmd)
}
// cluster add
t.Assert(flynn("cluster", "add", "--no-git", "foo", "https://controller.foo.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds)
t.Assert(flynn("cluster"), SuccessfulOutputContains, "foo")
t.Assert(flynn("cluster", "add", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds)
t.Assert(flynn("cluster"), SuccessfulOutputContains, "test")
t.Assert(flynn("cluster", "add", "-f", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds)
t.Assert(flynn("cluster"), SuccessfulOutputContains, "test")
t.Assert(flynn("cluster", "add", "-f", "-d", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds)
t.Assert(flynn("cluster"), SuccessfulOutputContains, "test")
// make sure the cluster is present in the config
cfg, err := config.ReadFile(file.Name())
t.Assert(err, c.IsNil)
t.Assert(cfg.Default, c.Equals, "test")
t.Assert(cfg.Clusters, c.HasLen, 2)
t.Assert(cfg.Clusters[0].Name, c.Equals, "foo")
t.Assert(cfg.Clusters[1].Name, c.Equals, "test")
// overwriting with a conflicting name and a different conflicting url should error
conflict := flynn("cluster", "add", "-f", "--no-git", "foo", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600")
t.Assert(conflict, c.Not(Succeeds))
t.Assert(conflict, OutputContains, "conflict with")
// overwriting (without --force) should not work
t.Assert(flynn("cluster", "add", "test", "foo", "bar"), c.Not(Succeeds))
t.Assert(flynn("cluster"), SuccessfulOutputContains, "test")
t.Assert(flynn("cluster"), SuccessfulOutputContains, "(default)")
// change default cluster
t.Assert(flynn("cluster", "default", "test"), SuccessfulOutputContains, "\"test\" is now the default cluster.")
t.Assert(flynn("cluster", "default", "missing"), OutputContains, "Cluster \"missing\" does not exist and cannot be set as default.")
t.Assert(flynn("cluster", "default"), SuccessfulOutputContains, "test")
cfg, err = config.ReadFile(file.Name())
t.Assert(err, c.IsNil)
t.Assert(cfg.Default, c.Equals, "test")
// cluster remove
t.Assert(flynn("cluster", "remove", "test"), Succeeds)
t.Assert(flynn("cluster"), c.Not(SuccessfulOutputContains), "test")
cfg, err = config.ReadFile(file.Name())
t.Assert(err, c.IsNil)
t.Assert(cfg.Clusters, c.HasLen, 1)
t.Assert(flynn("cluster", "remove", "foo"), Succeeds)
// cluster remove default and set next available
t.Assert(flynn("cluster", "add", "-d", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds)
t.Assert(flynn("cluster", "add", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "next", "https://controller.next.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds)
t.Assert(flynn("cluster", "remove", "test"), SuccessfulOutputContains, "Cluster \"test\" removed and \"next\" is now the default cluster.")
t.Assert(flynn("cluster", "default"), SuccessfulOutputContains, "next")
}
示例5: TestRelease
func (s *CLISuite) TestRelease(t *c.C) {
releaseJSON := []byte(`{
"env": {"GLOBAL": "FOO"},
"processes": {
"echoer": {
"cmd": ["/bin/echoer"],
"env": {"ECHOER_ONLY": "BAR"}
},
"env": {
"cmd": ["sh", "-c", "env; while true; do sleep 60; done"],
"env": {"ENV_ONLY": "BAZ"}
}
}
}`)
release := &ct.Release{}
t.Assert(json.Unmarshal(releaseJSON, &release), c.IsNil)
for typ, proc := range release.Processes {
resource.SetDefaults(&proc.Resources)
release.Processes[typ] = proc
}
file, err := ioutil.TempFile("", "")
t.Assert(err, c.IsNil)
file.Write(releaseJSON)
file.Close()
app := s.newCliTestApp(t)
defer app.cleanup()
t.Assert(app.flynn("release", "add", "-f", file.Name(), imageURIs["test-apps"]), Succeeds)
r, err := s.controller.GetAppRelease(app.name)
t.Assert(err, c.IsNil)
t.Assert(r.Env, c.DeepEquals, release.Env)
t.Assert(r.Processes, c.DeepEquals, release.Processes)
scaleCmd := app.flynn("scale", "--no-wait", "env=1", "foo=1")
t.Assert(scaleCmd, c.Not(Succeeds))
t.Assert(scaleCmd, OutputContains, "ERROR: unknown process types: \"foo\"")
// create a job watcher for the new release
watcher, err := s.controllerClient(t).WatchJobEvents(app.name, r.ID)
t.Assert(err, c.IsNil)
defer watcher.Close()
scaleCmd = app.flynn("scale", "--no-wait", "env=1")
t.Assert(watcher.WaitFor(ct.JobEvents{"env": {ct.JobStateUp: 1}}, scaleTimeout, nil), c.IsNil)
envLog := app.flynn("log")
t.Assert(envLog, Succeeds)
t.Assert(envLog, SuccessfulOutputContains, "GLOBAL=FOO")
t.Assert(envLog, SuccessfulOutputContains, "ENV_ONLY=BAZ")
t.Assert(envLog, c.Not(SuccessfulOutputContains), "ECHOER_ONLY=BAR")
}
示例6: TestControllerRestart
func (s *SchedulerSuite) TestControllerRestart(t *c.C) {
// get the current controller details
app, err := s.controllerClient(t).GetApp("controller")
t.Assert(err, c.IsNil)
release, err := s.controllerClient(t).GetAppRelease("controller")
t.Assert(err, c.IsNil)
formation, err := s.controllerClient(t).GetFormation(app.ID, release.ID)
t.Assert(err, c.IsNil)
list, err := s.controllerClient(t).JobList("controller")
t.Assert(err, c.IsNil)
var jobs []*ct.Job
for _, job := range list {
if job.Type == "web" && job.State == "up" {
jobs = append(jobs, job)
}
}
t.Assert(jobs, c.HasLen, 2)
hostID, jobID, _ := cluster.ParseJobID(jobs[0].ID)
t.Assert(hostID, c.Not(c.Equals), "")
t.Assert(jobID, c.Not(c.Equals), "")
debugf(t, "current controller app[%s] host[%s] job[%s]", app.ID, hostID, jobID)
// start another controller and wait for it to come up
watcher, err := s.controllerClient(t).WatchJobEvents("controller", release.ID)
t.Assert(err, c.IsNil)
defer watcher.Close()
debug(t, "scaling the controller up")
formation.Processes["web"]++
t.Assert(s.controllerClient(t).PutFormation(formation), c.IsNil)
err = watcher.WaitFor(ct.JobEvents{"web": {"up": 1}}, scaleTimeout, nil)
t.Assert(err, c.IsNil)
// kill the first controller and check the scheduler brings it back online
cc := cluster.NewClientWithServices(s.discoverdClient(t).Service)
hc, err := cc.Host(hostID)
t.Assert(err, c.IsNil)
debug(t, "stopping job ", jobID)
t.Assert(hc.StopJob(jobID), c.IsNil)
err = watcher.WaitFor(ct.JobEvents{"web": {"down": 1, "up": 1}}, scaleTimeout, nil)
t.Assert(err, c.IsNil)
// scale back down
debug(t, "scaling the controller down")
formation.Processes["web"]--
t.Assert(s.controllerClient(t).PutFormation(formation), c.IsNil)
err = watcher.WaitFor(ct.JobEvents{"web": {"down": 1}}, scaleTimeout, nil)
t.Assert(err, c.IsNil)
// unset the suite's client so other tests use a new client
s.controller = nil
}
示例7: TestRun
func (s *CLISuite) TestRun(t *c.C) {
app := s.newCliTestApp(t)
defer app.cleanup()
// this shouldn't be logged
t.Assert(app.sh("echo foo"), Outputs, "foo\n")
// drain the events
app.waitFor(ct.JobEvents{"": {ct.JobStateUp: 1, ct.JobStateDown: 1}})
// this should be logged due to the --enable-log flag
t.Assert(app.flynn("run", "--enable-log", "echo", "hello"), Outputs, "hello\n")
app.waitFor(ct.JobEvents{"": {ct.JobStateUp: 1, ct.JobStateDown: 1}})
detached := app.flynn("run", "-d", "echo", "world")
t.Assert(detached, Succeeds)
t.Assert(detached, c.Not(Outputs), "world\n")
id := strings.TrimSpace(detached.Output)
jobID := app.waitFor(ct.JobEvents{"": {ct.JobStateUp: 1, ct.JobStateDown: 1}})
t.Assert(jobID, c.Equals, id)
t.Assert(app.flynn("log", "--raw-output"), Outputs, "hello\nworld\n")
// test stdin and stderr
streams := app.flynnCmd("run", "sh", "-c", "cat 1>&2")
stdin, err := streams.StdinPipe()
t.Assert(err, c.IsNil)
go func() {
stdin.Write([]byte("goto stderr"))
stdin.Close()
}()
var stderr bytes.Buffer
var stdout bytes.Buffer
streams.Stderr = &stderr
streams.Stdout = &stdout
t.Assert(streams.Run(), c.IsNil)
t.Assert(stderr.String(), c.Equals, "goto stderr")
t.Assert(stdout.String(), c.Equals, "")
// test exit code
exit := app.sh("exit 42")
t.Assert(exit, c.Not(Succeeds))
if msg, ok := exit.Err.(*exec.ExitError); ok { // there is error code
code := msg.Sys().(syscall.WaitStatus).ExitStatus()
t.Assert(code, c.Equals, 42)
} else {
t.Fatal("There was no error code!")
}
}
示例8: runBuildpackTestWithResponsePattern
func (s *GitDeploySuite) runBuildpackTestWithResponsePattern(t *c.C, name string, resources []string, pat string) {
r := s.newGitRepo(t, "https://github.com/flynn-examples/"+name)
t.Assert(r.flynn("create", name), Outputs, fmt.Sprintf("Created %s\n", name))
for _, resource := range resources {
t.Assert(r.flynn("resource", "add", resource), Succeeds)
}
watcher, err := s.controllerClient(t).WatchJobEvents(name, "")
t.Assert(err, c.IsNil)
defer watcher.Close()
push := r.git("push", "flynn", "master")
t.Assert(push, SuccessfulOutputContains, "Creating release")
t.Assert(push, SuccessfulOutputContains, "Application deployed")
t.Assert(push, SuccessfulOutputContains, "Waiting for web job to start...")
t.Assert(push, SuccessfulOutputContains, "* [new branch] master -> master")
t.Assert(push, c.Not(OutputContains), "timed out waiting for scale")
t.Assert(push, SuccessfulOutputContains, "=====> Default web formation scaled to 1")
watcher.WaitFor(ct.JobEvents{"web": {ct.JobStateUp: 1}}, scaleTimeout, nil)
route := name + ".dev"
newRoute := r.flynn("route", "add", "http", route)
t.Assert(newRoute, Succeeds)
err = Attempts.Run(func() error {
// Make HTTP requests
client := &http.Client{}
req, err := http.NewRequest("GET", "http://"+routerIP, nil)
if err != nil {
return err
}
req.Host = route
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
contents, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
if res.StatusCode != 200 {
return fmt.Errorf("Expected status 200, got %v", res.StatusCode)
}
m, err := regexp.MatchString(pat, string(contents))
if err != nil {
return err
}
if !m {
return fmt.Errorf("Expected `%s`, got `%v`", pat, string(contents))
}
return nil
})
t.Assert(err, c.IsNil)
t.Assert(r.flynn("scale", "web=0"), Succeeds)
}
示例9: TestRoute
func (s *CLISuite) TestRoute(t *c.C) {
app := s.newCliTestApp(t)
defer app.cleanup()
// The router API does not currently give us a "read your own writes"
// guarantee, so we must retry a few times if we don't get the expected
// result.
assertRouteContains := func(str string, contained bool) {
var res *CmdResult
attempt.Strategy{
Total: 10 * time.Second,
Delay: 500 * time.Millisecond,
}.Run(func() error {
res = app.flynn("route")
if contained == strings.Contains(res.Output, str) {
return nil
}
return errors.New("unexpected output")
})
if contained {
t.Assert(res, SuccessfulOutputContains, str)
} else {
t.Assert(res, c.Not(SuccessfulOutputContains), str)
}
}
// flynn route add http
route := random.String(32) + ".dev"
newRoute := app.flynn("route", "add", "http", "--sticky", route)
t.Assert(newRoute, Succeeds)
routeID := strings.TrimSpace(newRoute.Output)
assertRouteContains(routeID, true)
// ensure sticky flag is set
routes, err := s.controllerClient(t).RouteList(app.name)
t.Assert(err, c.IsNil)
var found bool
for _, r := range routes {
if fmt.Sprintf("%s/%s", r.Type, r.ID) != routeID {
continue
}
t.Assert(r.Sticky, c.Equals, true)
found = true
}
t.Assert(found, c.Equals, true, c.Commentf("didn't find route"))
// flynn route remove
t.Assert(app.flynn("route", "remove", routeID), Succeeds)
assertRouteContains(routeID, false)
// flynn route add tcp
tcpRoute := app.flynn("route", "add", "tcp")
t.Assert(tcpRoute, Succeeds)
routeID = strings.Split(tcpRoute.Output, " ")[0]
assertRouteContains(routeID, true)
// flynn route remove
t.Assert(app.flynn("route", "remove", routeID), Succeeds)
assertRouteContains(routeID, false)
}
示例10: newSlugrunnerArtifact
func (h *Helper) newSlugrunnerArtifact(t *c.C) *ct.Artifact {
r, err := h.controllerClient(t).GetAppRelease("gitreceive")
t.Assert(err, c.IsNil)
slugrunnerURI := r.Processes["app"].Env["SLUGRUNNER_IMAGE_URI"]
t.Assert(slugrunnerURI, c.Not(c.Equals), "")
return &ct.Artifact{Type: "docker", URI: slugrunnerURI}
}
示例11: TestVolumeCreation
func (s *HostSuite) TestVolumeCreation(t *c.C) {
h := s.anyHostClient(t)
vol, err := h.CreateVolume("default")
t.Assert(err, c.IsNil)
t.Assert(vol.ID, c.Not(c.Equals), "")
t.Assert(h.DestroyVolume(vol.ID), c.IsNil)
}
示例12: TestScaleAll
func (s *CLISuite) TestScaleAll(t *c.C) {
client := s.controllerClient(t)
app := s.newCliTestApp(t)
release := app.release
defer app.cleanup()
scale := app.flynn("scale", "echoer=1", "printer=2")
t.Assert(scale, Succeeds)
scale = app.flynn("scale", "--all")
t.Assert(scale, Succeeds)
t.Assert(scale, SuccessfulOutputContains, fmt.Sprintf("%s (current)\n", release.ID))
t.Assert(scale, SuccessfulOutputContains, "echoer=1")
t.Assert(scale, SuccessfulOutputContains, "printer=2")
prevRelease := release
release = &ct.Release{
ArtifactID: release.ArtifactID,
Env: release.Env,
Meta: release.Meta,
Processes: release.Processes,
}
t.Assert(client.CreateRelease(release), c.IsNil)
t.Assert(client.SetAppRelease(app.id, release.ID), c.IsNil)
scale = app.flynn("scale", "echoer=2", "printer=1")
t.Assert(scale, Succeeds)
scale = app.flynn("scale", "--all")
t.Assert(scale, Succeeds)
t.Assert(scale, SuccessfulOutputContains, fmt.Sprintf("%s (current)\n", release.ID))
t.Assert(scale, SuccessfulOutputContains, "echoer=2")
t.Assert(scale, SuccessfulOutputContains, "printer=1")
t.Assert(scale, SuccessfulOutputContains, fmt.Sprintf("%s\n", prevRelease.ID))
t.Assert(scale, SuccessfulOutputContains, "echoer=1")
t.Assert(scale, SuccessfulOutputContains, "printer=2")
scale = app.flynn("scale", "--all", "--release", release.ID)
t.Assert(scale, c.Not(Succeeds))
scale = app.flynn("scale", "--all", "echoer=3", "printer=3")
t.Assert(scale, c.Not(Succeeds))
}
示例13: TestDeploys
// This test emulates deploys in the dashboard app
func (s *TaffyDeploySuite) TestDeploys(t *c.C) {
client := s.controllerClient(t)
github := map[string]string{
"user_login": "flynn-examples",
"repo_name": "go-flynn-example",
"ref": "master",
"sha": "a2ac6b059e1359d0e974636935fda8995de02b16",
"clone_url": "https://github.com/flynn-examples/go-flynn-example.git",
}
// initial deploy
app := &ct.App{
Meta: map[string]string{
"type": "github",
"user_login": github["user_login"],
"repo_name": github["repo_name"],
"ref": github["ref"],
"sha": github["sha"],
"clone_url": github["clone_url"],
},
}
t.Assert(client.CreateApp(app), c.IsNil)
debugf(t, "created app %s (%s)", app.Name, app.ID)
s.deployWithTaffy(t, app, github)
_, err := client.GetAppRelease(app.ID)
t.Assert(err, c.IsNil)
// second deploy
github["sha"] = "2bc7e016b1b4aae89396c898583763c5781e031a"
release, err := client.GetAppRelease(app.ID)
t.Assert(err, c.IsNil)
release = &ct.Release{
Env: release.Env,
Processes: release.Processes,
}
t.Assert(client.CreateRelease(release), c.IsNil)
t.Assert(client.SetAppRelease(app.ID, release.ID), c.IsNil)
s.deployWithTaffy(t, app, github)
newRelease, err := client.GetAppRelease(app.ID)
t.Assert(err, c.IsNil)
t.Assert(newRelease.ID, c.Not(c.Equals), release.ID)
release.Env["SLUG_URL"] = newRelease.Env["SLUG_URL"] // SLUG_URL will be different
t.Assert(release.Env, c.DeepEquals, newRelease.Env)
t.Assert(release.Processes, c.DeepEquals, newRelease.Processes)
}
示例14: TestResourceRemove
func (s *CLISuite) TestResourceRemove(t *c.C) {
app := s.newCliTestApp(t)
defer app.cleanup()
add := app.flynn("resource", "add", "postgres")
t.Assert(add, Succeeds)
t.Assert(app.flynn("resource").Output, Matches, "postgres")
t.Assert(app.flynn("env").Output, Matches, "FLYNN_POSTGRES")
id := strings.Split(add.Output, " ")[2]
// change one of the env vars provided by the resource
t.Assert(app.flynn("env", "set", "PGUSER=testuser"), Succeeds)
remove := app.flynn("resource", "remove", "postgres", id)
t.Assert(remove, Succeeds)
t.Assert(app.flynn("resource").Output, c.Not(Matches), "postgres")
// test that unmodified vars are removed
t.Assert(app.flynn("env").Output, c.Not(Matches), "FLYNN_POSTGRES")
// but that modifed ones are retained
t.Assert(app.flynn("env", "get", "PGUSER").Output, Matches, "testuser")
}
示例15: TestReleaseDelete
func (s *CLISuite) TestReleaseDelete(t *c.C) {
// create an app and release it twice
r := s.newGitRepo(t, "http")
app := "release-delete-" + random.String(8)
t.Assert(r.flynn("create", app), Succeeds)
t.Assert(r.git("push", "flynn", "master"), Succeeds)
t.Assert(r.git("commit", "--allow-empty", "--message", "empty commit"), Succeeds)
t.Assert(r.git("push", "flynn", "master"), Succeeds)
// get the releases
client := s.controllerClient(t)
releases, err := client.AppReleaseList(app)
t.Assert(err, c.IsNil)
t.Assert(releases, c.HasLen, 2)
// check the current release cannot be deleted
res := r.flynn("release", "delete", "--yes", releases[0].ID)
t.Assert(res, c.Not(Succeeds))
t.Assert(res.Output, c.Equals, "validation_error: cannot delete current app release\n")
// associate the initial release with another app
otherApp := &ct.App{Name: "release-delete-" + random.String(8)}
t.Assert(client.CreateApp(otherApp), c.IsNil)
t.Assert(client.PutFormation(&ct.Formation{AppID: otherApp.ID, ReleaseID: releases[1].ID}), c.IsNil)
// check deleting the initial release just deletes the formation
res = r.flynn("release", "delete", "--yes", releases[1].ID)
t.Assert(res, Succeeds)
t.Assert(res.Output, c.Equals, "Release scaled down for app but not fully deleted (still associated with 1 other apps)\n")
// check the slug artifact still exists
slugArtifact, err := client.GetArtifact(releases[1].FileArtifactIDs()[0])
t.Assert(err, c.IsNil)
s.assertURI(t, slugArtifact.URI, http.StatusOK)
// check the inital release can now be deleted
res = r.flynn("-a", otherApp.ID, "release", "delete", "--yes", releases[1].ID)
t.Assert(res, Succeeds)
t.Assert(res.Output, c.Equals, fmt.Sprintf("Deleted release %s (deleted 1 files)\n", releases[1].ID))
// check the slug artifact was deleted
_, err = client.GetArtifact(slugArtifact.ID)
t.Assert(err, c.Equals, controller.ErrNotFound)
s.assertURI(t, slugArtifact.URI, http.StatusNotFound)
// check the image artifact was not deleted (since it is shared between both releases)
_, err = client.GetArtifact(releases[1].ImageArtifactID())
t.Assert(err, c.IsNil)
}