|
| 1 | +package integration_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/paketo-buildpacks/occam" |
| 10 | + "github.com/sclevine/spec" |
| 11 | + |
| 12 | + . "github.com/onsi/gomega" |
| 13 | + . "github.com/paketo-buildpacks/occam/matchers" |
| 14 | +) |
| 15 | + |
| 16 | +func testVersions(t *testing.T, context spec.G, it spec.S) { |
| 17 | + var ( |
| 18 | + Expect = NewWithT(t).Expect |
| 19 | + Eventually = NewWithT(t).Eventually |
| 20 | + |
| 21 | + pack occam.Pack |
| 22 | + docker occam.Docker |
| 23 | + ) |
| 24 | + |
| 25 | + it.Before(func() { |
| 26 | + pack = occam.NewPack() |
| 27 | + docker = occam.NewDocker() |
| 28 | + }) |
| 29 | + |
| 30 | + context("when the buildpack is run with pack build", func() { |
| 31 | + var ( |
| 32 | + name string |
| 33 | + source string |
| 34 | + |
| 35 | + containersMap map[string]interface{} |
| 36 | + imagesMap map[string]interface{} |
| 37 | + ) |
| 38 | + |
| 39 | + it.Before(func() { |
| 40 | + var err error |
| 41 | + name, err = occam.RandomName() |
| 42 | + Expect(err).NotTo(HaveOccurred()) |
| 43 | + |
| 44 | + containersMap = map[string]interface{}{} |
| 45 | + imagesMap = map[string]interface{}{} |
| 46 | + }) |
| 47 | + |
| 48 | + it.After(func() { |
| 49 | + for containerID := range containersMap { |
| 50 | + Expect(docker.Container.Remove.Execute(containerID)).To(Succeed()) |
| 51 | + } |
| 52 | + for imageID := range imagesMap { |
| 53 | + Expect(docker.Image.Remove.Execute(imageID)).To(Succeed()) |
| 54 | + } |
| 55 | + Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) |
| 56 | + Expect(os.RemoveAll(source)).To(Succeed()) |
| 57 | + }) |
| 58 | + |
| 59 | + it("builds and runs successfully with both provided dependency versions", func() { |
| 60 | + var err error |
| 61 | + |
| 62 | + source, err = occam.Source(filepath.Join("testdata", "default_app")) |
| 63 | + Expect(err).NotTo(HaveOccurred()) |
| 64 | + |
| 65 | + firstPoetryVersion := buildpackInfo.Metadata.Dependencies[0].Version |
| 66 | + secondPoetryVersion := buildpackInfo.Metadata.Dependencies[1].Version |
| 67 | + |
| 68 | + Expect(firstPoetryVersion).NotTo(Equal(secondPoetryVersion)) |
| 69 | + |
| 70 | + firstImage, firstLogs, err := pack.WithNoColor().Build. |
| 71 | + WithPullPolicy("never"). |
| 72 | + WithBuildpacks( |
| 73 | + settings.Buildpacks.CPython.Online, |
| 74 | + settings.Buildpacks.Pip.Online, |
| 75 | + settings.Buildpacks.Poetry.Online, |
| 76 | + settings.Buildpacks.BuildPlan.Online, |
| 77 | + ). |
| 78 | + WithEnv(map[string]string{"BP_POETRY_VERSION": firstPoetryVersion}). |
| 79 | + Execute(name, source) |
| 80 | + Expect(err).ToNot(HaveOccurred(), firstLogs.String) |
| 81 | + |
| 82 | + imagesMap[firstImage.ID] = nil |
| 83 | + |
| 84 | + Expect(firstLogs).To(ContainLines( |
| 85 | + ContainSubstring(fmt.Sprintf(`Selected Poetry version (using BP_POETRY_VERSION): %s`, firstPoetryVersion)), |
| 86 | + )) |
| 87 | + |
| 88 | + firstContainer, err := docker.Container.Run. |
| 89 | + WithCommand("poetry --version"). |
| 90 | + Execute(firstImage.ID) |
| 91 | + Expect(err).ToNot(HaveOccurred()) |
| 92 | + |
| 93 | + containersMap[firstContainer.ID] = nil |
| 94 | + |
| 95 | + Eventually(func() string { |
| 96 | + cLogs, err := docker.Container.Logs.Execute(firstContainer.ID) |
| 97 | + Expect(err).NotTo(HaveOccurred()) |
| 98 | + return cLogs.String() |
| 99 | + }).Should(ContainSubstring(fmt.Sprintf(`Poetry version %s`, firstPoetryVersion))) |
| 100 | + |
| 101 | + secondImage, secondLogs, err := pack.WithNoColor().Build. |
| 102 | + WithPullPolicy("never"). |
| 103 | + WithBuildpacks( |
| 104 | + settings.Buildpacks.CPython.Online, |
| 105 | + settings.Buildpacks.Pip.Online, |
| 106 | + settings.Buildpacks.Poetry.Online, |
| 107 | + settings.Buildpacks.BuildPlan.Online, |
| 108 | + ). |
| 109 | + WithEnv(map[string]string{"BP_POETRY_VERSION": secondPoetryVersion}). |
| 110 | + Execute(name, source) |
| 111 | + Expect(err).ToNot(HaveOccurred(), secondLogs.String) |
| 112 | + |
| 113 | + imagesMap[secondImage.ID] = nil |
| 114 | + |
| 115 | + Expect(secondLogs).To(ContainLines( |
| 116 | + ContainSubstring(fmt.Sprintf(`Selected Poetry version (using BP_POETRY_VERSION): %s`, secondPoetryVersion)), |
| 117 | + )) |
| 118 | + |
| 119 | + secondContainer, err := docker.Container.Run. |
| 120 | + WithCommand("poetry --version"). |
| 121 | + Execute(secondImage.ID) |
| 122 | + Expect(err).ToNot(HaveOccurred()) |
| 123 | + |
| 124 | + containersMap[secondContainer.ID] = nil |
| 125 | + |
| 126 | + Eventually(func() string { |
| 127 | + cLogs, err := docker.Container.Logs.Execute(secondContainer.ID) |
| 128 | + Expect(err).NotTo(HaveOccurred()) |
| 129 | + return cLogs.String() |
| 130 | + }).Should(ContainSubstring(fmt.Sprintf(`Poetry version %s`, secondPoetryVersion))) |
| 131 | + }) |
| 132 | + }) |
| 133 | +} |
0 commit comments