Skip to content

Commit

Permalink
Fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran authored and ryanmoran committed Apr 22, 2021
1 parent ec8d5de commit aa74bc9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
37 changes: 22 additions & 15 deletions integration/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(goBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{"BP_GO_VERSION": "1.15.*"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expand All @@ -86,7 +87,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

context("using optional utility buildpacks", func() {
it.Before(func() {
Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"), []byte("web: /layers/paketo-buildpacks_go-build/targets/bin/workspace --some-arg"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"), []byte("web: /layers/paketo-buildpacks_go-build/targets/bin/workspace --some-arg"), 0600)).To(Succeed())
})

it("builds a working OCI image with start command from the Procfile and incorporating the utility buildpacks' effects", func() {
Expand All @@ -96,6 +97,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
WithBuildpacks(goBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{
"BP_GO_VERSION": "1.15.*",
"BPE_SOME_VARIABLE": "some-value",
"BP_IMAGE_LABELS": "some-label=some-value",
}).
Expand Down Expand Up @@ -131,6 +133,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(goBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{"BP_GO_VERSION": "1.15.*"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expand Down Expand Up @@ -190,7 +193,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(goBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{"BP_KEEP_FILES": "key.pem:cert.pem"}).
WithEnv(map[string]string{
"BP_GO_VERSION": "1.15.*",
"BP_KEEP_FILES": "key.pem:cert.pem",
}).
Execute(name, filepath.Join(source, "build"))
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -219,19 +225,20 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
request, err := http.NewRequest("GET", fmt.Sprintf("https://localhost:%s", container.HostPort("8080")), nil)
Expect(err).NotTo(HaveOccurred())

var response *http.Response
Eventually(func() error {
var err error
response, err = client.Do(request)
return err
}).Should(BeNil())
defer response.Body.Close()

Expect(response.StatusCode).To(Equal(http.StatusOK))

content, err := ioutil.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(ContainSubstring("Hello, World!"))
Eventually(func() string {
response, err := client.Do(request)
if err != nil {
return ""
}
defer response.Body.Close()

content, err := ioutil.ReadAll(response.Body)
if err != nil {
return ""
}

return string(content)
}).Should(ContainSubstring("Hello, World!"))
})
})
})
Expand Down
36 changes: 21 additions & 15 deletions integration/dep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func testDep(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(goBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{"BP_GO_VERSION": "1.15.*"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expand All @@ -87,7 +88,7 @@ func testDep(t *testing.T, context spec.G, it spec.S) {

context("when using utility buildpacks", func() {
it.Before(func() {
Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"), []byte("web: /layers/paketo-buildpacks_go-build/targets/bin/workspace --some-arg"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"), []byte("web: /layers/paketo-buildpacks_go-build/targets/bin/workspace --some-arg"), 0600)).To(Succeed())
})

it("builds a working OCI image with start command from the Procfile and incorporating the utility buildpacks' effects", func() {
Expand All @@ -97,6 +98,7 @@ func testDep(t *testing.T, context spec.G, it spec.S) {
WithBuildpacks(goBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{
"BP_GO_VERSION": "1.15.*",
"BPE_SOME_VARIABLE": "some-value",
"BP_IMAGE_LABELS": "some-label=some-value",
}).
Expand Down Expand Up @@ -163,7 +165,10 @@ func testDep(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(goBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{"BP_KEEP_FILES": "key.pem:cert.pem"}).
WithEnv(map[string]string{
"BP_GO_VERSION": "1.15.*",
"BP_KEEP_FILES": "key.pem:cert.pem",
}).
Execute(name, filepath.Join(source, "dep"))
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -192,19 +197,20 @@ func testDep(t *testing.T, context spec.G, it spec.S) {
request, err := http.NewRequest("GET", fmt.Sprintf("https://localhost:%s", container.HostPort("8080")), nil)
Expect(err).NotTo(HaveOccurred())

var response *http.Response
Eventually(func() error {
var err error
response, err = client.Do(request)
return err
}).Should(BeNil())
defer response.Body.Close()

Expect(response.StatusCode).To(Equal(http.StatusOK))

content, err := ioutil.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(ContainSubstring("Hello, World!"))
Eventually(func() string {
response, err := client.Do(request)
if err != nil {
return ""
}
defer response.Body.Close()

content, err := ioutil.ReadAll(response.Body)
if err != nil {
return ""
}

return string(content)
}).Should(ContainSubstring("Hello, World!"))
})
})
})
Expand Down
29 changes: 15 additions & 14 deletions integration/go_mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func testGoMod(t *testing.T, context spec.G, it spec.S) {

context("when using utility buildpacks", func() {
it.Before(func() {
Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"), []byte("web: /layers/paketo-buildpacks_go-build/targets/bin/go-online --some-arg"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"), []byte("web: /layers/paketo-buildpacks_go-build/targets/bin/go-online --some-arg"), 0600)).To(Succeed())
})

it("builds a working OCI image with start command from the Procfile and incorporating the utility buildpacks' effects", func() {
Expand Down Expand Up @@ -190,19 +190,20 @@ func testGoMod(t *testing.T, context spec.G, it spec.S) {
request, err := http.NewRequest("GET", fmt.Sprintf("https://localhost:%s", container.HostPort("8080")), nil)
Expect(err).NotTo(HaveOccurred())

var response *http.Response
Eventually(func() error {
var err error
response, err = client.Do(request)
return err
}).Should(BeNil())
defer response.Body.Close()

Expect(response.StatusCode).To(Equal(http.StatusOK))

content, err := ioutil.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(ContainSubstring("Hello, World!"))
Eventually(func() string {
response, err := client.Do(request)
if err != nil {
return ""
}
defer response.Body.Close()

content, err := ioutil.ReadAll(response.Body)
if err != nil {
return ""
}

return string(content)
}).Should(ContainSubstring("Hello, World!"))
})
})
})
Expand Down

0 comments on commit aa74bc9

Please sign in to comment.