Skip to content

Commit

Permalink
Merge branch 'main' into becca/env-naiferror
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Feb 23, 2024
2 parents f30ded4 + 2a1e2a9 commit eaf9099
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions ee/agent/timemachine/timemachine_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package timemachine

import (
"context"
"fmt"
"os"
"os/user"
"path/filepath"
Expand All @@ -15,13 +14,16 @@ import (

"github.com/kolide/launcher/ee/agent/types/mocks"
"github.com/kolide/launcher/ee/allowedcmd"
"github.com/kolide/launcher/pkg/backoff"
"github.com/stretchr/testify/require"
)

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

if os.Getenv("GITHUB_ACTIONS") == "true" {
t.Skip("Skipping test on GitHub Actions because it's flaky there")
}

u, err := user.Current()
require.NoError(t, err)

Expand Down Expand Up @@ -91,30 +93,18 @@ func TestAddExclusions(t *testing.T) {

// ensure the files are included / excluded as expected
for fileName, shouldBeExcluded := range shouldBeExcluded {
// Allow for a couple retries for the file to show up as excluded appropriately --
// we've seen this be a little flaky in CI
err := backoff.WaitFor(func() error {
cmd, err := allowedcmd.Tmutil(context.TODO(), "isexcluded", filepath.Join(testDir, fileName))
if err != nil {
return fmt.Errorf("creating tmutil command: %w", err)
}

out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("running tmutil isexcluded: %w", err)
}

if shouldBeExcluded && !strings.Contains(string(out), "[Excluded]") {
return fmt.Errorf("output `%s` does not contain [Excluded], but file should be excluded", string(out))
}

if !shouldBeExcluded && !strings.Contains(string(out), "[Included]") {
return fmt.Errorf("output `%s` does not contain [Included], but file should be included", string(out))
}

return nil
}, 1*time.Second, 200*time.Millisecond)

require.NoError(t, err, "file not handled as expected")
cmd, err := allowedcmd.Tmutil(context.TODO(), "isexcluded", filepath.Join(testDir, fileName))
require.NoError(t, err)

out, err := cmd.CombinedOutput()
require.NoError(t, err)

if shouldBeExcluded {
require.Contains(t, string(out), "[Excluded]")
continue
}

// should be included
require.Contains(t, string(out), "[Included]")
}
}

0 comments on commit eaf9099

Please sign in to comment.