Skip to content

Commit 9753c4b

Browse files
authored
refactor:integration tests (#11)
* refactor: moved all integration tests together Keeping them split showed several issues: - Concurrent access to the cache is not working (fixed by using one cache per test suit) - Each suit would rebuild all its the dependencies which means that the cost on disk would balloon as well as the time spent to rebuild the same artifacts - Each suit being independent, in the package sense, means sharing package level variables such as settings was not possible. * chore(workflows): remove push to gcr * chore: add free-disk-space action for integration tests The tests all together generate large data. This is especially the case for the cypthon buildpack.
1 parent 48b5f28 commit 9753c4b

32 files changed

Lines changed: 226 additions & 528 deletions

.github/workflows/push-buildpackage.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ jobs:
3939
exit 1
4040
fi
4141
42-
- name: Push to GCR
43-
env:
44-
GCR_PUSH_BOT_JSON_KEY: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
45-
run: |
46-
echo "${GCR_PUSH_BOT_JSON_KEY}" | sudo skopeo login --username _json_key --password-stdin gcr.io
47-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_full }}"
48-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_minor }}"
49-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_major }}"
50-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:latest"
51-
5242
- name: Push to DockerHub
5343
id: push
5444
env:

.github/workflows/test-pull-request.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ jobs:
4646
builder: ${{ fromJSON(needs.unit.outputs.builders) }}
4747
fail-fast: false # don't cancel all test jobs when one fails
4848
steps:
49+
- name: Free Disk Space (Ubuntu)
50+
uses: jlumbroso/free-disk-space@main
51+
with:
52+
# This might remove tools that are actually needed,
53+
# if set to "true" but frees about 6 GB
54+
tool-cache: false
55+
# Default settings from documentation
56+
android: true
57+
dotnet: true
58+
haskell: true
59+
large-packages: true
60+
docker-images: true
61+
swap-storage: true
4962
- name: Setup Go
5063
uses: actions/setup-go@v3
5164
with:

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SPDX-FileCopyrightText = "Copyright (c) 2013-Present CloudFoundry.org Foundation
2424
SPDX-License-Identifier = "Apache-2.0"
2525

2626
[[annotations]]
27-
path = "integration/**/integration.json"
27+
path = "integration.json"
2828
precedence = "override"
2929
SPDX-FileCopyrightText = "Copyright (c) 2013-Present CloudFoundry.org Foundation, Inc. All Rights Reserved."
3030
SPDX-License-Identifier = "Apache-2.0"

integration.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"builders":
3+
[
4+
"index.docker.io/paketobuildpacks/builder:buildpackless-base",
5+
"index.docker.io/paketobuildpacks/builder-jammy-buildpackless-base:latest",
6+
"index.docker.io/jericop/amazonlinux-builder:base"
7+
],
8+
9+
"build-plan": "github.com/paketo-community/build-plan",
10+
"cpython": "github.com/paketo-buildpacks/cpython",
11+
"pip": "github.com/paketo-buildpacks/pip"
12+
}

integration/helpers.go

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,6 @@
55

66
package integration_helpers
77

8-
import (
9-
"os"
10-
"path/filepath"
11-
12-
"github.com/ForestEckhardt/freezer"
13-
"github.com/ForestEckhardt/freezer/github"
14-
"github.com/paketo-buildpacks/occam"
15-
"github.com/paketo-buildpacks/occam/packagers"
16-
)
17-
18-
func NewBuildpackStore(suffix string) occam.BuildpackStore {
19-
gitToken := os.Getenv("GIT_TOKEN")
20-
cacheManager := freezer.NewCacheManager(filepath.Join(os.Getenv("HOME"), ".freezer-cache", suffix))
21-
releaseService := github.NewReleaseService(github.NewConfig("https://api.github.com", gitToken))
22-
packager := packagers.NewJam()
23-
namer := freezer.NewNameGenerator()
24-
25-
return occam.NewBuildpackStore().WithLocalFetcher(
26-
freezer.NewLocalFetcher(
27-
&cacheManager,
28-
packager,
29-
namer,
30-
)).WithRemoteFetcher(
31-
freezer.NewRemoteFetcher(
32-
&cacheManager,
33-
releaseService, packager,
34-
)).WithCacheManager(
35-
&cacheManager,
36-
)
37-
}
38-
398
type Buildpack struct {
409
ID string
4110
Name string
@@ -55,6 +24,34 @@ type BuildpackInfo struct {
5524
Metadata Metadata
5625
}
5726

27+
type TestSettings struct {
28+
Buildpacks struct {
29+
// Dependency buildpacks
30+
CPython struct {
31+
Online string
32+
Offline string
33+
}
34+
Pip struct {
35+
Online string
36+
Offline string
37+
}
38+
BuildPlan struct {
39+
Online string
40+
}
41+
// This buildpack
42+
PythonInstallers struct {
43+
Online string
44+
Offline string
45+
}
46+
}
47+
48+
Config struct {
49+
CPython string `json:"cpython"`
50+
Pip string `json:"pip"`
51+
BuildPlan string `json:"build-plan"`
52+
}
53+
}
54+
5855
func DependenciesForId(dependencies []Dependency, id string) []Dependency {
5956
output := []Dependency{}
6057

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,77 +28,66 @@ var (
2828

2929
buildpackInfo integration_helpers.BuildpackInfo
3030

31-
settings struct {
32-
Buildpacks struct {
33-
CPython struct {
34-
Online string
35-
Offline string
36-
}
37-
Pip struct {
38-
Online string
39-
Offline string
40-
}
41-
BuildPlan struct {
42-
Online string
43-
}
44-
}
45-
46-
Config struct {
47-
CPython string `json:"cpython"`
48-
BuildPlan string `json:"build-plan"`
49-
}
50-
}
31+
settings integration_helpers.TestSettings
5132
)
5233

53-
func TestPipIntegration(t *testing.T) {
34+
func TestIntegration(t *testing.T) {
5435
// Do not truncate Gomega matcher output
5536
// The buildpack output text can be large and we often want to see all of it.
5637
format.MaxLength = 0
5738

5839
Expect := NewWithT(t).Expect
5940

60-
file, err := os.Open("integration.json")
41+
root, err := filepath.Abs("./../../")
42+
Expect(err).NotTo(HaveOccurred())
43+
44+
file, err := os.Open(filepath.Join(root, "/integration.json"))
6145
Expect(err).NotTo(HaveOccurred())
6246

63-
Expect(json.NewDecoder(file).Decode(&settings.Config)).To(Succeed())
47+
err = json.NewDecoder(file).Decode(&settings.Config)
48+
Expect(err).NotTo(HaveOccurred())
6449
Expect(file.Close()).To(Succeed())
6550

66-
file, err = os.Open("./../../../buildpack.toml")
51+
file, err = os.Open(filepath.Join(root, "buildpack.toml"))
6752
Expect(err).NotTo(HaveOccurred())
6853

6954
_, err = toml.NewDecoder(file).Decode(&buildpackInfo)
7055
Expect(err).NotTo(HaveOccurred())
7156
Expect(file.Close()).To(Succeed())
7257

73-
buildpackInfo.Metadata.Dependencies = integration_helpers.DependenciesForId(buildpackInfo.Metadata.Dependencies, "pip")
58+
buildpackStore := occam.NewBuildpackStore()
7459

75-
root, err := filepath.Abs("./../../..")
76-
Expect(err).ToNot(HaveOccurred())
60+
settings.Buildpacks.BuildPlan.Online, err = buildpackStore.Get.
61+
Execute(settings.Config.BuildPlan)
62+
Expect(err).NotTo(HaveOccurred())
63+
64+
settings.Buildpacks.CPython.Online, err = buildpackStore.Get.
65+
Execute(settings.Config.CPython)
66+
Expect(err).NotTo(HaveOccurred())
7767

78-
buildpackStore := integration_helpers.NewBuildpackStore("pip")
68+
settings.Buildpacks.CPython.Offline, err = buildpackStore.Get.
69+
WithOfflineDependencies().
70+
Execute(settings.Config.CPython)
71+
Expect(err).NotTo(HaveOccurred())
7972

8073
settings.Buildpacks.Pip.Online, err = buildpackStore.Get.
81-
WithVersion("1.2.3").
82-
Execute(root)
74+
Execute(settings.Config.Pip)
8375
Expect(err).NotTo(HaveOccurred())
8476

8577
settings.Buildpacks.Pip.Offline, err = buildpackStore.Get.
86-
WithVersion("1.2.3").
8778
WithOfflineDependencies().
88-
Execute(root)
79+
Execute(settings.Config.Pip)
8980
Expect(err).NotTo(HaveOccurred())
9081

91-
settings.Buildpacks.CPython.Online, err = buildpackStore.Get.
92-
Execute(settings.Config.CPython)
82+
settings.Buildpacks.PythonInstallers.Online, err = buildpackStore.Get.
83+
WithVersion("1.2.3").
84+
Execute(root)
9385
Expect(err).NotTo(HaveOccurred())
9486

95-
settings.Buildpacks.CPython.Offline, err = buildpackStore.Get.
87+
settings.Buildpacks.PythonInstallers.Offline, err = buildpackStore.Get.
88+
WithVersion("1.2.3").
9689
WithOfflineDependencies().
97-
Execute(settings.Config.CPython)
98-
Expect(err).NotTo(HaveOccurred())
99-
100-
settings.Buildpacks.BuildPlan.Online, err = buildpackStore.Get.
101-
Execute(settings.Config.BuildPlan)
90+
Execute(root)
10291
Expect(err).NotTo(HaveOccurred())
10392

10493
pack := occam.NewPack().WithVerbose()
@@ -107,11 +96,30 @@ func TestPipIntegration(t *testing.T) {
10796

10897
SetDefaultEventuallyTimeout(30 * time.Second)
10998

110-
suite := spec.New("Integration", spec.Report(report.Terminal{}))
111-
suite("Default", testDefault, spec.Parallel())
112-
suite("LayerReuse", testLayerReuse, spec.Parallel())
99+
suite := spec.New("Integration", spec.Report(report.Terminal{}), spec.Parallel())
100+
101+
// miniconda
102+
suite("Miniconda Default", minicondaTestDefault)
103+
suite("Miniconda Logging", minicondaTestLogging)
104+
suite("Miniconda LayerReuse", minicondaTestReusingLayerRebuild)
105+
suite("Miniconda TestOffline", minicondaTestOffline)
106+
107+
// pip
108+
suite("Pip Default", pipTestDefault, spec.Parallel())
109+
suite("Pip LayerReuse", pipTestLayerReuse, spec.Parallel())
113110
if strings.Contains(builder.LocalInfo.Stack.ID, "jammy") || strings.Contains(builder.LocalInfo.Stack.ID, "bionic") {
114-
suite("Offline", testOffline, spec.Parallel())
111+
suite("Pip Offline", pipTestOffline, spec.Parallel())
115112
}
113+
114+
// pipenv
115+
suite("Pipenv Default", pipenvTestDefault, spec.Parallel())
116+
suite("Pipenv LayerReuse", pipenvTestLayerReuse, spec.Parallel())
117+
suite("Pipenv Version", pipenvTestVersions, spec.Parallel())
118+
119+
// poetry
120+
suite("Poetry Default", poetryTestDefault, spec.Parallel())
121+
suite("Poetry LayerReuse", poetryTestLayerReuse, spec.Parallel())
122+
suite("Poetry Versions", poetryTestVersions, spec.Parallel())
123+
116124
suite.Run(t)
117125
}

integration/installers/miniconda/init_test.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

integration/installers/miniconda/integration.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)