Skip to content

Commit ada8b78

Browse files
author
Aaron Schlesinger
committed
fix(pkg/gitreceive): move the build hook construction to a separate func
and add tests for the func. this commit also uses SlugBuilderInfo’s AbsoluteSlugURL func to pass the slug’s full URL to the controller
1 parent 5a069b0 commit ada8b78

3 files changed

Lines changed: 70 additions & 14 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,7 @@ func build(conf *Config, s3Client *storage.Client, kubeClient *client.Client, fs
239239
log.Info("Launching app.")
240240
log.Info("Launching...")
241241

242-
buildHook := &pkg.BuildHook{
243-
Sha: gitSha.Short(),
244-
ReceiveUser: conf.Username,
245-
ReceiveRepo: appName,
246-
Image: appName,
247-
Procfile: procType,
248-
}
249-
if !usingDockerfile {
250-
buildHook.Dockerfile = ""
251-
// need this to tell the controller what URL to give the slug runner
252-
buildHook.Image = slugBuilderInfo.PushURL() + "/slug.tgz"
253-
} else {
254-
buildHook.Dockerfile = "true"
255-
}
242+
buildHook := createBuildHook(slugBuilderInfo, gitSha, conf.Username, appName, procType, usingDockerfile)
256243
buildHookResp, err := publishRelease(conf, builderKey, buildHook)
257244
if err != nil {
258245
return fmt.Errorf("publishing release (%s)", err)

pkg/gitreceive/controller.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010

1111
"github.com/deis/builder/pkg"
12+
"github.com/deis/builder/pkg/gitreceive/git"
13+
"github.com/deis/builder/pkg/gitreceive/storage"
1214
"github.com/deis/pkg/log"
1315
)
1416

@@ -148,3 +150,28 @@ func receive(conf *Config, builderKey, gitSha string) error {
148150
}
149151
return nil
150152
}
153+
154+
func createBuildHook(
155+
slugBuilderInfo *storage.SlugBuilderInfo,
156+
gitSha *git.SHA,
157+
username,
158+
appName string,
159+
procType pkg.ProcessType,
160+
usingDockerfile bool,
161+
) *pkg.BuildHook {
162+
ret := &pkg.BuildHook{
163+
Sha: gitSha.Short(),
164+
ReceiveUser: username,
165+
ReceiveRepo: appName,
166+
Image: appName,
167+
Procfile: procType,
168+
}
169+
if !usingDockerfile {
170+
ret.Dockerfile = ""
171+
// need this to tell the controller what URL to give the slug runner
172+
ret.Image = slugBuilderInfo.AbsoluteSlugURL()
173+
} else {
174+
ret.Dockerfile = "true"
175+
}
176+
return ret
177+
}

pkg/gitreceive/controller_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package gitreceive
2+
3+
import (
4+
"testing"
5+
6+
"github.com/arschles/assert"
7+
"github.com/deis/builder/pkg"
8+
"github.com/deis/builder/pkg/gitreceive/git"
9+
"github.com/deis/builder/pkg/gitreceive/storage"
10+
)
11+
12+
const (
13+
rawSha = "c3b4e4ba8b7267226ff02ad07a3a2cca9c9237de"
14+
bucket = "git"
15+
appName = "myapp"
16+
slugName = "myslug"
17+
username = "myuser"
18+
)
19+
20+
func TestCreateBuildHook(t *testing.T) {
21+
procType := pkg.ProcessType(make(map[string]string))
22+
sha, err := git.NewSha(rawSha)
23+
assert.NoErr(t, err)
24+
endpoint := &storage.Endpoint{URLStr: "s3.amazonaws.com", Secure: false}
25+
slugBuilderInfo := storage.NewSlugBuilderInfo(endpoint, bucket, appName, slugName, sha)
26+
hookUsingDockerfile := createBuildHook(slugBuilderInfo, sha, username, appName, procType, true)
27+
assert.Equal(t, hookUsingDockerfile.Sha, sha.Short(), "git sha")
28+
assert.Equal(t, hookUsingDockerfile.ReceiveUser, username, "username")
29+
assert.Equal(t, hookUsingDockerfile.ReceiveRepo, appName, "username")
30+
assert.Equal(t, hookUsingDockerfile.Image, appName, "image")
31+
assert.Equal(t, hookUsingDockerfile.Procfile, procType, "procfile")
32+
assert.Equal(t, hookUsingDockerfile.Dockerfile, "true", "dockerfile field")
33+
34+
hookNoDockerfile := createBuildHook(slugBuilderInfo, sha, username, appName, procType, false)
35+
assert.Equal(t, hookNoDockerfile.Sha, sha.Short(), "git sha")
36+
assert.Equal(t, hookNoDockerfile.ReceiveUser, username, "username")
37+
assert.Equal(t, hookNoDockerfile.ReceiveRepo, appName, "username")
38+
assert.Equal(t, hookNoDockerfile.Image, slugBuilderInfo.AbsoluteSlugURL(), "image")
39+
assert.Equal(t, hookNoDockerfile.Procfile, procType, "procfile")
40+
assert.Equal(t, hookNoDockerfile.Dockerfile, "", "dockerfile field")
41+
42+
}

0 commit comments

Comments
 (0)