Fix flaky test `TestDiff` (#59)

This commit is contained in:
shreyas-goenka 2022-09-15 15:40:47 +02:00 committed by GitHub
parent 192a790155
commit 836ab58473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"time"
"github.com/databricks/bricks/git" "github.com/databricks/bricks/git"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -16,7 +17,8 @@ func TestDiff(t *testing.T) {
f1, err := os.Create(filepath.Join(projectDir, "hello.txt")) f1, err := os.Create(filepath.Join(projectDir, "hello.txt"))
assert.NoError(t, err) assert.NoError(t, err)
defer f1.Close() defer f1.Close()
f2, err := os.Create(filepath.Join(projectDir, "world.txt")) worldFilePath := filepath.Join(projectDir, "world.txt")
f2, err := os.Create(worldFilePath)
assert.NoError(t, err) assert.NoError(t, err)
defer f2.Close() defer f2.Close()
@ -32,8 +34,16 @@ func TestDiff(t *testing.T) {
assert.Contains(t, change.put, "hello.txt") assert.Contains(t, change.put, "hello.txt")
assert.Contains(t, change.put, "world.txt") assert.Contains(t, change.put, "world.txt")
// Edited files are added to put // Edited files are added to put.
_, err = f2.WriteString("I like clis") // File system in the github actions env does not update
// mtime on writes to a file. So we are manually editting it
// instead of writing to world.txt
worldFileInfo, err := os.Stat(worldFilePath)
assert.NoError(t, err)
os.Chtimes(worldFilePath,
worldFileInfo.ModTime().Add(time.Nanosecond),
worldFileInfo.ModTime().Add(time.Nanosecond))
assert.NoError(t, err) assert.NoError(t, err)
files, err = fileSet.All() files, err = fileSet.All()
assert.NoError(t, err) assert.NoError(t, err)