Skip to content

Commit

Permalink
set bool env var correctly on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fanjul committed Feb 17, 2025
1 parent 36c69f1 commit f101751
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
11 changes: 2 additions & 9 deletions test/extended/crc/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,14 @@ func (c Command) Execute() error {
func (c Command) env() []string {
var env []string
if !c.updateCheck {
env = append(env, envVariable("CRC_DISABLE_UPDATE_CHECK", "true"))
env = append(env, util.EnvVariable("CRC_DISABLE_UPDATE_CHECK", "true"))
}
if c.disableNTP {
env = append(env, envVariable("CRC_DEBUG_ENABLE_STOP_NTP", "true"))
env = append(env, util.EnvVariable("CRC_DEBUG_ENABLE_STOP_NTP", "true"))
}
return env
}

func envVariable(key, value string) string {
if runtime.GOOS == "windows" {
return fmt.Sprintf("$env:%s=%s;", key, value)
}
return fmt.Sprintf("%s=%s", key, value)
}

func (c Command) validate() error {
cmdline := strings.Fields(c.command)
if len(cmdline) < 1 {
Expand Down
19 changes: 19 additions & 0 deletions test/extended/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ var (
CRCHome string
)

func EnvVariable(key, value string) string {
var prefix = ""
var suffix = ""
if runtime.GOOS == "windows" {
prefix = "$env:"
suffix = ";"
switch value {
case "true":
value = "$true"
break

Check failure on line 34 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 34 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (macOS-13, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 34 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (macOS-14, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 34 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 34 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 1.22)

S1023: redundant break statement (gosimple)
case "false":
value = "$false"
break

Check failure on line 37 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 37 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (macOS-13, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 37 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (macOS-14, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 37 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22)

S1023: redundant break statement (gosimple)

Check failure on line 37 in test/extended/util/util.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 1.22)

S1023: redundant break statement (gosimple)
default:
}
}
return fmt.Sprintf("%s%s=%s%s", prefix, key, value, suffix)
}

func CopyFilesToTestDir() error {
cwd, err := os.Getwd()
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions test/integration/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/crc-org/crc/v2/test/extended/crc/cmd"
"github.com/crc-org/crc/v2/test/extended/util"
. "github.com/onsi/gomega"
)

Expand All @@ -21,8 +22,8 @@ type CRCBuilder struct {
// NewCRCCommand returns a CRCBuilder for running CRC.
func NewCRCCommand(args ...string) *CRCBuilder {
cmd := exec.Command("crc", args...)
cmd.Env = append(os.Environ(), "CRC_DISABLE_UPDATE_CHECK=true")
cmd.Env = append(os.Environ(), "CRC_LOG_LEVEL=debug")
cmd.Env = append(os.Environ(), util.EnvVariable("CRC_DISABLE_UPDATE_CHECK", "true"))
cmd.Env = append(cmd.Env, util.EnvVariable("CRC_LOG_LEVEL", "debug"))
return &CRCBuilder{
cmd: cmd,
}
Expand Down

0 comments on commit f101751

Please sign in to comment.