Skip to content

Commit

Permalink
Merge pull request #229 from paketo-buildpacks/add-static
Browse files Browse the repository at this point in the history
Add static stack as well as convenience methods for matching stacks
  • Loading branch information
dmikusa authored Apr 24, 2023
2 parents ca29947 + 8e9eb09 commit 4323db8
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ func TestUnit(t *testing.T) {
suite("Formatter", testFormatter)
suite("Layer", testLayer)
suite("Main", testMain)
suite("Stack", testStack)
suite.Run(t)
}
28 changes: 28 additions & 0 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,32 @@ const (

// JammyTinyStackID is the ID for the Cloud Native Buildpacks jammy tiny stack.
JammyTinyStackID = "io.buildpacks.stacks.jammy.tiny"

// JammyStaticStackID is the ID for the Cloud Native Buildpacks jammy static stack.
JammyStaticStackID = "io.buildpacks.stacks.jammy.static"
)

// IsBionicStack returns true if the stack is one of the bionic variants
func IsBionicStack(stack string) bool {
return BionicStackID == stack || BionicTinyStackID == stack || TinyStackID == stack
}

// IsJammyStack returns true if the stack is one of the jammy variants
func IsJammyStack(stack string) bool {
return JammyStackID == stack || JammyTinyStackID == stack || JammyStaticStackID == stack
}

// IsTinyStack returns true if the stack is one of the tiny variants
func IsTinyStack(stack string) bool {
return BionicTinyStackID == stack || JammyTinyStackID == stack || TinyStackID == stack
}

// IsStaticStack returns true if the stack is one of the static variants
func IsStaticStack(stack string) bool {
return JammyStaticStackID == stack
}

// IsShellPresentOnStack returns true if the stack is known to have a shell
func IsShellPresentOnStack(stack string) bool {
return BionicStackID == stack || JammyStackID == stack
}
77 changes: 77 additions & 0 deletions stack_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package libpak_test

import (
"testing"

. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/libpak"
"github.com/sclevine/spec"
)

func testStack(t *testing.T, context spec.G, it spec.S) {
context("bionic stacks", func() {
it("matches standard bionic stack", func() {
Expect(libpak.IsBionicStack("io.buildpacks.stacks.bionic")).To(BeTrue())
})

it("matches tiny bionic stack", func() {
Expect(libpak.IsBionicStack("io.paketo.stacks.tiny")).To(BeTrue())
})

it("does not match non-bionic stack", func() {
Expect(libpak.IsBionicStack("io.buildpacks.stacks.jammy")).To(BeFalse())
})
})

context("jammy stacks", func() {
it("matches standard jammy stack", func() {
Expect(libpak.IsJammyStack("io.buildpacks.stacks.jammy")).To(BeTrue())
})

it("matches tiny jammy stack", func() {
Expect(libpak.IsJammyStack("io.buildpacks.stacks.jammy.tiny")).To(BeTrue())
})

it("matches static jammy stack", func() {
Expect(libpak.IsJammyStack("io.buildpacks.stacks.jammy.static")).To(BeTrue())
})

it("does not match non-jammy stack", func() {
Expect(libpak.IsJammyStack("io.buildpacks.stacks.bionic")).To(BeFalse())
})
})

context("tiny stacks", func() {
it("matches tiny bionic stack", func() {
Expect(libpak.IsTinyStack("io.paketo.stacks.tiny")).To(BeTrue())
})

it("matches tiny jammy stack", func() {
Expect(libpak.IsTinyStack("io.buildpacks.stacks.jammy.tiny")).To(BeTrue())
})

it("does not match full stack", func() {
Expect(libpak.IsTinyStack("io.buildpacks.stacks.bionic")).To(BeFalse())
})
})

context("static stack", func() {
it("matches static jammy stack", func() {
Expect(libpak.IsStaticStack("io.buildpacks.stacks.jammy.static")).To(BeTrue())
})

it("does not match full stack", func() {
Expect(libpak.IsTinyStack("io.buildpacks.stacks.bionic")).To(BeFalse())
})
})

context("shell", func() {
it("matches a full stack", func() {
Expect(libpak.IsShellPresentOnStack("io.buildpacks.stacks.bionic")).To(BeTrue())
})

it("does not match static jammy stack", func() {
Expect(libpak.IsShellPresentOnStack("io.buildpacks.stacks.jammy.static")).To(BeFalse())
})
})
}

0 comments on commit 4323db8

Please sign in to comment.