Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
Rename PACK_ to CNB_
Browse files Browse the repository at this point in the history
This change updates the code to examine CNB_ environment variables instead of
PACK_ environment variables.  Where PACK_ was previously used, it still exists
as a fallback to be removed once the lifecycle has been updated and released.

[buildpacks/spec#38]

Signed-off-by: Ben Hale <bhale@pivotal.io>
  • Loading branch information
nebhale committed Jan 29, 2019
1 parent f78102b commit 95ce7cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions services/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package services

import (
"encoding/json"
"sort"
)

// Credentials is the collection of credential keys.
Expand All @@ -38,5 +39,6 @@ func (c *Credentials) UnmarshalJSON(text []byte) error {
*c = append(*c, key)
}

sort.Strings(*c)
return nil
}
2 changes: 1 addition & 1 deletion services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestServices(t *testing.T) {
Tags: []string{"postgres", "postgresql", "relational"},
},
{
Credentials: services.Credentials{"hostname", "username", "password"},
Credentials: services.Credentials{"hostname", "password", "username"},
InstanceName: "mysendgrid",
Label: "sendgrid",
Plan: "free",
Expand Down
10 changes: 7 additions & 3 deletions stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ import (

type Stack string

// DefaultStack creates a new instance of Stack, extracting the name from the PACK_STACK_ID environment variable.
// DefaultStack creates a new instance of Stack, extracting the name from the CNB_STACK_ID environment variable.
func DefaultStack(logger logger.Logger) (Stack, error) {
s, ok := os.LookupEnv("PACK_STACK_ID")
s, ok := os.LookupEnv("CNB_STACK_ID")
if !ok {
return "", fmt.Errorf("PACK_STACK_ID not set")
s, ok = os.LookupEnv("PACK_STACK_ID") // TODO: Remove once PACK_STACK_ID removed from lifecycle
}

if !ok {
return "", fmt.Errorf("CNB_STACK_ID not set")
}

stack := Stack(s)
Expand Down
12 changes: 10 additions & 2 deletions stack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,26 @@ func TestStack(t *testing.T) {

g := NewGomegaWithT(t)

it("extracts value from CNB_STACK_ID", func() {
defer internal.ReplaceEnv(t, "CNB_STACK_ID", "test-stack-name")()

g.Expect(stack.DefaultStack(logger.Logger{})).To(Equal(stack.Stack("test-stack-name")))
})

it("extracts value from PACK_STACK_ID", func() {
defer internal.ReplaceEnv(t, "PACK_STACK_ID", "test-stack-name")()

g.Expect(stack.DefaultStack(logger.Logger{})).To(Equal(stack.Stack("test-stack-name")))
})

it("returns error when PACK_STACK_ID not set", func() {
it("returns error when CNB AND PACK_STACK_ID not set", func() {
defer internal.ProtectEnv(t, "CNB_STACK_ID")()
defer internal.ProtectEnv(t, "PACK_STACK_ID")()
g.Expect(os.Unsetenv("CNB_STACK_ID")).Should(Succeed())
g.Expect(os.Unsetenv("PACK_STACK_ID")).Should(Succeed())

_, err := stack.DefaultStack(logger.Logger{})
g.Expect(err).To(MatchError("PACK_STACK_ID not set"))
g.Expect(err).To(MatchError("CNB_STACK_ID not set"))
})
}, spec.Report(report.Terminal{}))
}

0 comments on commit 95ce7cd

Please sign in to comment.