Skip to content

Commit

Permalink
add more test utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hoß authored and sebhoss committed Sep 9, 2022
1 parent 92bfe5a commit c94c346
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/testutils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func TemporaryDirectory(t *testing.T) string {
}

func WriteFile(t *testing.T, name string) {
err := os.WriteFile(name, []byte("hello world!"), 0644)
WriteFileContent(t, name, "hello world!")
}

func WriteFileContent(t *testing.T, name string, content string) {
err := os.WriteFile(name, []byte(content), 0644)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/testutils/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ func GetRepositoryHead(t *testing.T, repository *git.Repository) *plumbing.Refer
}

func WriteFileInWorktree(t *testing.T, worktree *git.Worktree, name string) {
filename := filepath.Join(worktree.Filesystem.Root(), name)
filename := FileInWorktree(worktree, name)
WriteFile(t, filename)
}

func FileInWorktree(worktree *git.Worktree, name string) string {
return filepath.Join(worktree.Filesystem.Root(), name)
}

func AddAndCommitNewFile(t *testing.T, worktree *git.Worktree, name string) {
WriteFileInWorktree(t, worktree, name)
GitAdd(t, worktree, name)
Expand Down

0 comments on commit c94c346

Please sign in to comment.