Add tests for fileSet adding `databricks` to .gitignore (#325)

## Changes
<!-- Summary of your changes that are easy to understand -->

These are flows that were earlier only being tested in package
`project`. Since package `project` has been deleted in
https://github.com/databricks/bricks/pull/321, we needed to add coverage
as done here

## Tests
<!-- How is this tested? -->
This commit is contained in:
shreyas-goenka 2023-04-12 12:04:10 +02:00 committed by GitHub
parent d52fc12644
commit 42cd405eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package git
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -32,3 +34,32 @@ func TestFileSetNonCleanRoot(t *testing.T) {
require.NoError(t, err)
assert.Len(t, files, 6)
}
func TestFilesetAddsCacheDirToGitIgnore(t *testing.T) {
projectDir := t.TempDir()
fileSet, err := NewFileSet(projectDir)
require.NoError(t, err)
fileSet.EnsureValidGitIgnoreExists()
gitIgnorePath := filepath.Join(projectDir, ".gitignore")
assert.FileExists(t, gitIgnorePath)
fileBytes, err := os.ReadFile(gitIgnorePath)
assert.NoError(t, err)
assert.Contains(t, string(fileBytes), ".databricks")
}
func TestFilesetDoesNotCacheDirToGitIgnoreIfAlreadyPresent(t *testing.T) {
projectDir := t.TempDir()
gitIgnorePath := filepath.Join(projectDir, ".gitignore")
fileSet, err := NewFileSet(projectDir)
require.NoError(t, err)
err = os.WriteFile(gitIgnorePath, []byte(".databricks"), 0o644)
require.NoError(t, err)
fileSet.EnsureValidGitIgnoreExists()
b, err := os.ReadFile(gitIgnorePath)
require.NoError(t, err)
assert.Equal(t, 1, strings.Count(string(b), ".databricks"))
}