Skip to content

Commit

Permalink
fix: Preventing log enrichment for bare mode (#3916)
Browse files Browse the repository at this point in the history
* feat: Adding failing test

* fix: flag destination

* fix: unit tests

---------

Co-authored-by: Levko Burburas <levko.himins@biptec.com>
  • Loading branch information
yhakbar and levkohimins authored Feb 21, 2025
1 parent fb4b493 commit 237f07a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/cli/bool_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (flag *BoolFlag) Apply(set *libflag.FlagSet) error {
return ApplyFlag(flag, set)
}

if flag.Destination == nil {
flag.Destination = new(bool)
}

valueType := newBoolVar(flag.Destination, flag.Negative)
value := newGenericValue(valueType, flag.Setter)

Expand Down
6 changes: 4 additions & 2 deletions internal/cli/bool_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ func testBoolFlagApply(t *testing.T, flag *cli.BoolFlag, args []string, envs map
expectedDefaultValue string
)

if val := flag.Destination; val != nil {
expectedDefaultValue = strconv.FormatBool(*val)
if flag.Destination == nil {
flag.Destination = new(bool)
}

expectedDefaultValue = strconv.FormatBool(*flag.Destination)

flag.LookupEnvFunc = func(key string) []string {
if envs == nil {
return nil
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/generic_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (flag *GenericFlag[T]) Apply(set *libflag.FlagSet) error {
return ApplyFlag(flag, set)
}

if flag.Destination == nil {
flag.Destination = new(T)
}

valueType := &genericVar[T]{dest: flag.Destination}
value := newGenericValue(valueType, flag.Setter)

Expand Down
6 changes: 4 additions & 2 deletions internal/cli/generic_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@ func testGenericFlagApply[T cli.GenericType](t *testing.T, flag *cli.GenericFlag
expectedDefaultValue string
)

if val := flag.Destination; val != nil {
expectedDefaultValue = fmt.Sprintf("%v", *val)
if flag.Destination == nil {
flag.Destination = new(T)
}

expectedDefaultValue = fmt.Sprintf("%v", *flag.Destination)

flag.LookupEnvFunc = func(key string) []string {
if envs == nil {
return nil
Expand Down
14 changes: 14 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4112,3 +4112,17 @@ func TestLogStreaming(t *testing.T) {
require.GreaterOrEqualf(t, secondTimestamp.Sub(firstTimestamp), 1*time.Second, "Second log entry for unit %s is not at least 1 second after the first log entry", unit)
}
}

func TestLogFormatBare(t *testing.T) {
t.Parallel()

tmpEnvPath := helpers.CopyEnvironment(t, testFixtureEmptyState)
helpers.CleanupTerraformFolder(t, tmpEnvPath)
testPath := util.JoinPath(tmpEnvPath, testFixtureEmptyState)

stdout, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt init --log-format=bare --no-color --non-interactive --working-dir "+testPath)
require.NoError(t, err)

assert.Contains(t, stdout, "Initializing the backend...")
assert.NotContains(t, stdout, "STDO[0000] Initializing the backend...")
}

0 comments on commit 237f07a

Please # to comment.