Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmokijew committed Jan 26, 2024
1 parent 0c5da58 commit 4a8078c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions server/events/pending_plan_finder_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package events_test

import (
"fmt"
"os"
"os/exec"
"path/filepath"
Expand All @@ -18,6 +19,28 @@ func TestPendingPlanFinder_FindNoDir(t *testing.T) {
ErrEquals(t, "open /doesntexist: no such file or directory", err)
}

// If one of the dir in PR dir is not git dir then it should throw an error.
func TestPendingPlanFinder_FindIncludingNotGitDir(t *testing.T) {
gitDirName := ".default"
notGitDirName := ".terragrunt-cache"
tmpDir := DirStructure(t, map[string]interface{}{
gitDirName: map[string]interface{}{
"default.tfplan": nil,
},
notGitDirName: map[string]interface{}{
"some_file.tfplan": nil,
},
})
// Initialize git in 'default' directory
gitDir := filepath.Join(tmpDir, gitDirName)
runCmd(t, gitDir, "git", "init")
pf := &events.DefaultPendingPlanFinder{}

_, err := pf.Find(tmpDir)
ErrEquals(t, fmt.Sprintf("Error running 'git ls-files . --others' in '%s/%s' directory: fatal: "+
"not a git repository (or any of the parent directories): .git\n: exit status 128", tmpDir, notGitDirName), err)
}

// Test different directory structures.
func TestPendingPlanFinder_Find(t *testing.T) {
cases := []struct {
Expand Down

0 comments on commit 4a8078c

Please sign in to comment.