Skip to content

Commit

Permalink
Run integration tests with unstable commands turned on
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed May 6, 2022
1 parent f44c834 commit 82246e6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions internal/captain/command.go
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ActiveState/cli/internal/analytics"
anaConsts "github.com/ActiveState/cli/internal/analytics/constants"
"github.com/ActiveState/cli/internal/assets"
"github.com/ActiveState/cli/internal/condition"
"github.com/ActiveState/cli/internal/config"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/errs"
Expand Down Expand Up @@ -354,7 +355,7 @@ func (c *Command) interceptFunc() InterceptFunc {
// and add a warning banner for those who have.
func (c *Command) SetUnstable(unstable bool) *Command {
c.unstable = unstable
if !c.cfg.GetBool(constants.UnstableConfig) {
if !condition.OptInUnstable(c.cfg) {
c.cobra.Hidden = unstable
}
return c
Expand Down Expand Up @@ -526,7 +527,7 @@ func (c *Command) runner(cobraCmd *cobra.Command, args []string) error {
defer profile.Measure("captain:runner", time.Now())

if c.unstable && c.out.Type() != output.EditorV0FormatName {
if !c.cfg.GetBool(constants.UnstableConfig) {
if !condition.OptInUnstable(c.cfg) {
c.out.Print(locale.Tr("unstable_command_warning", c.Name()))
return nil
}
Expand Down
11 changes: 11 additions & 0 deletions internal/condition/condition.go
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/thoas/go-funk"
)

type Configurable interface {
GetBool(s string) bool
}

var inTest = strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test") ||
strings.Contains(os.Args[0], "/_test/") || funk.Contains(os.Args, "-test.v")

Expand All @@ -31,3 +35,10 @@ func IsLTS() bool {
func BuiltViaCI() bool {
return constants.OnCI == "true"
}

func OptInUnstable(cfg Configurable) bool {
if v := os.Getenv(constants.OptinUnstableEnvVarName); v != "" {
return v == "true"
}
return cfg.GetBool(constants.UnstableConfig)
}
3 changes: 3 additions & 0 deletions internal/constants/constants.go
Expand Up @@ -126,6 +126,9 @@ const AnalyticsLogEnvVarName = "ACTIVESTATE_ANALYTICS_LOG"
// DisableAnalyticsEnvVarName is used to instruct State Tool to not send data to Google Analytics.
const DisableAnalyticsEnvVarName = "ACTIVESTATE_CLI_DISABLE_ANALYTICS"

// OptinUnstableEnvVarName is used to instruct State Tool to opt-in to unstable features
const OptinUnstableEnvVarName = "ACTIVESTATE_OPTIN_UNSTABLE"

// APIUpdateInfoURL is the URL for our update info server
const APIUpdateInfoURL = "https://platform.activestate.com/sv/state-update/api/v1"

Expand Down
1 change: 1 addition & 0 deletions internal/testhelpers/e2e/session.go
Expand Up @@ -180,6 +180,7 @@ func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session
constants.ProjectEnvVarName + "=",
constants.E2ETestEnvVarName + "=true",
constants.DisableUpdates + "=true",
constants.OptinUnstableEnvVarName + "=true",
}...)

if updatePath {
Expand Down
6 changes: 3 additions & 3 deletions pkg/project/secrets.go
Expand Up @@ -4,10 +4,10 @@ import (
"errors"
"strings"

"github.com/ActiveState/cli/internal/condition"
"github.com/ActiveState/cli/pkg/platform/authentication"

"github.com/ActiveState/cli/internal/access"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/keypairs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/prompt"
Expand Down Expand Up @@ -245,7 +245,7 @@ var ErrSecretNotFound = errors.New("secret not found")

// Expand will expand a variable to a secret value, if no secret exists it will return an empty string
func (e *SecretExpander) Expand(_ string, category string, name string, isFunction bool, project *Project) (string, error) {
if !e.cfg.GetBool(constants.UnstableConfig) {
if !condition.OptInUnstable(e.cfg) {
return "", locale.NewError("secrets_unstable_warning")
}

Expand Down Expand Up @@ -288,7 +288,7 @@ func (e *SecretExpander) Expand(_ string, category string, name string, isFuncti

// ExpandWithPrompt will expand a variable to a secret value, if no secret exists the user will be prompted
func (e *SecretExpander) ExpandWithPrompt(_ string, category string, name string, isFunction bool, project *Project) (string, error) {
if !e.cfg.GetBool(constants.UnstableConfig) {
if !condition.OptInUnstable(e.cfg) {
return "", locale.NewError("secrets_unstable_warning")
}

Expand Down

0 comments on commit 82246e6

Please sign in to comment.