Skip to content

Commit

Permalink
Dockerfiles phase 1: update experimental mode env var (#881)
Browse files Browse the repository at this point in the history
* Update experimental mode env var

Signed-off-by: Natalie Arellano <[email protected]>

* When CNB_EXPERIMENTAL_MODE is unset, default to `error`

Signed-off-by: Natalie Arellano <[email protected]>

Signed-off-by: Natalie Arellano <[email protected]>
  • Loading branch information
natalieparellano authored Sep 19, 2022
1 parent cdc31cf commit f1398ce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions acceptance/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
"--user", userID,
"--volume", orderPath+":/layers/order.toml",
"--env", "CNB_PLATFORM_API="+latestPlatformAPI,
"--env", "CNB_EXPERIMENTAL_MODE=warn", // required as the default is `error` if unset
),
h.WithArgs(
"-analyzed=/layers/analyzed.toml",
Expand Down
4 changes: 2 additions & 2 deletions platform/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
EnvCacheDir = "CNB_CACHE_DIR"
EnvCacheImage = "CNB_CACHE_IMAGE"
EnvDeprecationMode = "CNB_DEPRECATION_MODE"
EnvExperimentalMode = "CNB_PLATFORM_EXPERIMENTAL_FEATURES"
EnvExperimentalMode = "CNB_EXPERIMENTAL_MODE"
EnvExtensionsDir = "CNB_EXTENSIONS_DIR"
EnvGID = "CNB_GROUP_ID"
EnvGeneratedDir = "CNB_GENERATED_DIR"
Expand All @@ -38,7 +38,7 @@ const (
EnvUID = "CNB_USER_ID"
EnvUseDaemon = "CNB_USE_DAEMON" // defaults to false

DefaultExperimentalMode = ModeWarn
DefaultExperimentalMode = ModeError
DefaultLogLevel = "info"
DefaultPlatformAPI = "0.3"

Expand Down
6 changes: 3 additions & 3 deletions platform/experimental_features.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package platform

import (
"errors"
"fmt"
"os"

"github.com/buildpacks/lifecycle/log"
Expand All @@ -19,11 +19,11 @@ func GuardExperimental(requested string, logger log.Logger) error {
break
case ModeError:
logger.Errorf("Platform requested experimental feature '%s'", requested)
logger.Errorf("Experimental features are disabled by %s=%s", EnvExperimentalMode, ModeError)
return errors.New("experimental feature")
return fmt.Errorf("experimental features are disabled by %s=%s", EnvExperimentalMode, ModeError)
case ModeWarn:
logger.Warnf("Platform requested experimental feature '%s'", requested)
default:
// This shouldn't be reached, as ExperimentalMode is always set.
logger.Warnf("Platform requested experimental feature '%s'", requested)
}
return nil
Expand Down
11 changes: 5 additions & 6 deletions platform/experimental_features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func testExperimentalFeatures(t *testing.T, when spec.G, it spec.S) {
})

when("GuardExperimental", func() {
when("CNB_PLATFORM_EXPERIMENTAL_FEATURES=warn", func() {
when("CNB_EXPERIMENTAL_MODE=warn", func() {
it("warns", func() {
platform.ExperimentalMode = platform.ModeWarn
err := platform.GuardExperimental("some-feature", logger)
Expand All @@ -41,7 +41,7 @@ func testExperimentalFeatures(t *testing.T, when spec.G, it spec.S) {
})
})

when("CNB_PLATFORM_EXPERIMENTAL_FEATURES=quiet", func() {
when("CNB_EXPERIMENTAL_MODE=quiet", func() {
it("succeeds silently", func() {
platform.ExperimentalMode = platform.ModeQuiet
err := platform.GuardExperimental("some-feature", logger)
Expand All @@ -50,16 +50,15 @@ func testExperimentalFeatures(t *testing.T, when spec.G, it spec.S) {
})
})

when("CNB_PLATFORM_EXPERIMENTAL_FEATURES=error", func() {
when("CNB_EXPERIMENTAL_MODE=error", func() {
it("error with exit code 11", func() {
platform.ExperimentalMode = platform.ModeError
err := platform.GuardExperimental("some-feature", logger)
h.AssertNotNil(t, err)
h.AssertEq(t, len(logHandler.Entries), 2)
h.AssertEq(t, err.Error(), "experimental features are disabled by CNB_EXPERIMENTAL_MODE=error")
h.AssertEq(t, len(logHandler.Entries), 1)
h.AssertEq(t, logHandler.Entries[0].Level, log.ErrorLevel)
h.AssertEq(t, logHandler.Entries[0].Message, "Platform requested experimental feature 'some-feature'")
h.AssertEq(t, logHandler.Entries[1].Level, log.ErrorLevel)
h.AssertEq(t, logHandler.Entries[1].Message, "Experimental features are disabled by CNB_PLATFORM_EXPERIMENTAL_FEATURES=error")
})
})
})
Expand Down

0 comments on commit f1398ce

Please sign in to comment.