-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Makes a seperate and more complicated integration test to more thoroughly test the functionality
- Loading branch information
1 parent
be1dbba
commit d8207ad
Showing
10 changed files
with
121 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package integration_test | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/paketo-buildpacks/occam" | ||
"github.com/sclevine/spec" | ||
|
||
. "github.com/onsi/gomega" | ||
. "github.com/paketo-buildpacks/occam/matchers" | ||
) | ||
|
||
func testKeepFiles(t *testing.T, context spec.G, it spec.S) { | ||
var ( | ||
Expect = NewWithT(t).Expect | ||
Eventually = NewWithT(t).Eventually | ||
|
||
pack occam.Pack | ||
docker occam.Docker | ||
) | ||
|
||
it.Before(func() { | ||
pack = occam.NewPack().WithVerbose().WithNoColor() | ||
docker = occam.NewDocker() | ||
}) | ||
|
||
context("when building a simple app with no dependencies but perserving files in the workspace", func() { | ||
var ( | ||
image occam.Image | ||
container occam.Container | ||
|
||
name string | ||
source string | ||
) | ||
|
||
it.Before(func() { | ||
var err error | ||
name, err = occam.RandomName() | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed()) | ||
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
Expect(os.RemoveAll(source)).To(Succeed()) | ||
}) | ||
|
||
it("builds successfully", func() { | ||
var err error | ||
source, err = occam.Source(filepath.Join("testdata", "keep_files")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
var logs fmt.Stringer | ||
image, logs, err = pack.Build. | ||
WithPullPolicy("never"). | ||
WithBuildpacks( | ||
settings.Buildpacks.GoDist.Online, | ||
settings.Buildpacks.GoBuild.Online, | ||
). | ||
WithEnv(map[string]string{"BP_KEEP_FILES": "./static-file:assets/*"}). | ||
Execute(name, source) | ||
Expect(err).ToNot(HaveOccurred(), logs.String) | ||
|
||
container, err = docker.Container.Run.Execute(image.ID) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Eventually(container).Should(BeAvailable()) | ||
|
||
response, err := http.Get(fmt.Sprintf("http://localhost:%s", container.HostPort())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(response.StatusCode).To(Equal(http.StatusOK)) | ||
|
||
content, err := ioutil.ReadAll(response.Body) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(content)).To(ContainSubstring("go1.15")) | ||
Expect(string(content)).To(ContainSubstring("/workspace contents: [/workspace/assets /workspace/static-file]")) | ||
Expect(string(content)).To(ContainSubstring("file contents: Hello world!")) | ||
}) | ||
}) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello world! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintln(w, runtime.Version()) | ||
|
||
paths, _ := filepath.Glob("/workspace/*") | ||
fmt.Fprintf(w, "/workspace contents: %v\n", paths) | ||
|
||
contents, _ := ioutil.ReadFile("./assets/some-file") | ||
fmt.Fprintf(w, "file contents: %s\n", string(contents)) | ||
}) | ||
|
||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", os.Getenv("PORT")), nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters