Skip to content

Commit

Permalink
refactor: changing the structure of settings to similar what other bu…
Browse files Browse the repository at this point in the history
…ildpacks have
  • Loading branch information
pacostas committed Oct 27, 2023
1 parent ecf7b8d commit 47e558e
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,77 @@ import (
. "github.com/onsi/gomega"
)

var (
buildpack string
buildPlanBuildpack string
offlineBuildpack string
root string

buildpackInfo struct {
Buildpack struct {
ID string
Name string
var settings struct {
Buildpacks struct {
BuildPlan struct {
Online string
}
Yarn struct {
Online string
Offline string
}
}
)
Extensions struct {
UbiNodejsExtension struct {
Online string
}
}
Config struct {
BuildPlan string `json:"buildplan"`
UbiNodejsExtension string `json:"ubi-nodejs-extension"`
}
Buildpack struct {
ID string
Name string
}
}

func TestIntegration(t *testing.T) {
var err error

Expect := NewWithT(t).Expect

var config struct {
BuildPlan string `json:"buildplan"`
}

file, err := os.Open("../integration.json")
Expect(err).NotTo(HaveOccurred())
defer file.Close()

Expect(json.NewDecoder(file).Decode(&config)).To(Succeed())
Expect(json.NewDecoder(file).Decode(&settings.Config)).To(Succeed())

file, err = os.Open("../buildpack.toml")
Expect(err).NotTo(HaveOccurred())

_, err = toml.NewDecoder(file).Decode(&buildpackInfo)
_, err = toml.NewDecoder(file).Decode(&settings)
Expect(err).NotTo(HaveOccurred())

root, err = filepath.Abs("./..")
root, err := filepath.Abs("./..")
Expect(err).ToNot(HaveOccurred())

buildpackStore := occam.NewBuildpackStore()

buildpack, err = buildpackStore.Get.
pack := occam.NewPack()

builder, err := pack.Builder.Inspect.Execute()
Expect(err).NotTo(HaveOccurred())

if builder.BuilderName == "index.docker.io/paketocommunity/builder-ubi-buildpackless-base:latest" {
settings.Extensions.UbiNodejsExtension.Online, err = buildpackStore.Get.
Execute(settings.Config.UbiNodejsExtension)
Expect(err).ToNot(HaveOccurred())
}

settings.Buildpacks.Yarn.Online, err = buildpackStore.Get.
WithVersion("1.2.3").
Execute(root)
Expect(err).NotTo(HaveOccurred())

offlineBuildpack, err = buildpackStore.Get.
settings.Buildpacks.Yarn.Offline, err = buildpackStore.Get.
WithOfflineDependencies().
WithVersion("1.2.3").
Execute(root)
Expect(err).NotTo(HaveOccurred())

buildPlanBuildpack, err = buildpackStore.Get.
Execute(config.BuildPlan)
settings.Buildpacks.BuildPlan.Online, err = buildpackStore.Get.
Execute(settings.Config.BuildPlan)
Expect(err).NotTo(HaveOccurred())

SetDefaultEventuallyTimeout(10 * time.Second)
Expand Down

0 comments on commit 47e558e

Please sign in to comment.