Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfiles phase 1: update experimental mode env var #881

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
EnvGroupPath = "CNB_GROUP_PATH"
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