Skip to content

Commit 180d27d

Browse files
committed
Merge pull request flynn#946 from flynn/taffy-integration-test
test: Add taffy integration test
2 parents 58a5a97 + 7b16dbe commit 180d27d

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

test/test_taffy_deploy.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
6+
c "github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-check"
7+
ct "github.com/flynn/flynn/controller/types"
8+
"github.com/flynn/flynn/pkg/cluster"
9+
)
10+
11+
type TaffyDeploySuite struct {
12+
Helper
13+
}
14+
15+
var _ = c.ConcurrentSuite(&TaffyDeploySuite{})
16+
17+
func (s *TaffyDeploySuite) deployWithTaffy(t *c.C, app *ct.App, github map[string]string) {
18+
client := s.controllerClient(t)
19+
20+
taffyRelease, err := client.GetAppRelease("taffy")
21+
t.Assert(err, c.IsNil)
22+
23+
rwc, err := client.RunJobAttached("taffy", &ct.NewJob{
24+
ReleaseID: taffyRelease.ID,
25+
Cmd: []string{
26+
app.Name,
27+
github["clone_url"],
28+
github["ref"],
29+
github["sha"],
30+
},
31+
Meta: map[string]string{
32+
"type": "github",
33+
"user_login": github["user_login"],
34+
"repo_name": github["repo_name"],
35+
"ref": github["ref"],
36+
"sha": github["sha"],
37+
"clone_url": github["clone_url"],
38+
"app": app.ID,
39+
},
40+
})
41+
t.Assert(err, c.IsNil)
42+
attachClient := cluster.NewAttachClient(rwc)
43+
var outBuf bytes.Buffer
44+
exit, err := attachClient.Receive(&outBuf, &outBuf)
45+
t.Log(outBuf.String())
46+
t.Assert(exit, c.Equals, 0)
47+
t.Assert(err, c.IsNil)
48+
}
49+
50+
// This test emulates deploys in the dashboard app
51+
func (s *TaffyDeploySuite) TestDeploys(t *c.C) {
52+
client := s.controllerClient(t)
53+
54+
github := map[string]string{
55+
"user_login": "flynn-examples",
56+
"repo_name": "go-flynn-example",
57+
"ref": "master",
58+
"sha": "a2ac6b059e1359d0e974636935fda8995de02b16",
59+
"clone_url": "https://github.com/flynn-examples/go-flynn-example.git",
60+
}
61+
62+
// initial deploy
63+
64+
app := &ct.App{
65+
Meta: map[string]string{
66+
"type": "github",
67+
"user_login": github["user_login"],
68+
"repo_name": github["repo_name"],
69+
"ref": github["ref"],
70+
"sha": github["sha"],
71+
"clone_url": github["clone_url"],
72+
},
73+
}
74+
t.Assert(client.CreateApp(app), c.IsNil)
75+
debugf(t, "created app %s (%s)", app.Name, app.ID)
76+
77+
s.deployWithTaffy(t, app, github)
78+
79+
_, err := client.GetAppRelease(app.ID)
80+
t.Assert(err, c.IsNil)
81+
82+
// second deploy
83+
84+
github["sha"] = "2bc7e016b1b4aae89396c898583763c5781e031a"
85+
86+
release, err := client.GetAppRelease(app.ID)
87+
t.Assert(err, c.IsNil)
88+
89+
release = &ct.Release{
90+
Env: release.Env,
91+
Processes: release.Processes,
92+
}
93+
t.Assert(client.CreateRelease(release), c.IsNil)
94+
t.Assert(client.SetAppRelease(app.ID, release.ID), c.IsNil)
95+
96+
s.deployWithTaffy(t, app, github)
97+
98+
newRelease, err := client.GetAppRelease(app.ID)
99+
t.Assert(err, c.IsNil)
100+
t.Assert(newRelease.ID, c.Not(c.Equals), release.ID)
101+
release.Env["SLUG_URL"] = newRelease.Env["SLUG_URL"] // SLUG_URL will be different
102+
t.Assert(release.Env, c.DeepEquals, newRelease.Env)
103+
t.Assert(release.Processes, c.DeepEquals, newRelease.Processes)
104+
}

0 commit comments

Comments
 (0)