Skip to content

Commit

Permalink
⚡ QD-9824 add logging of git output in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avafanasiev committed Aug 31, 2024
1 parent 487d12f commit 4ba1204
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions platform/git_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package platform

import (
"encoding/json"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"os"
"os/exec"
Expand Down Expand Up @@ -174,9 +175,7 @@ func createRepo(t *testing.T, tc TestConfig) string {

// Step 2: Initialize a new Git repository
cmd := exec.Command("git", "init")
cmd.Dir = repoDir
err = cmd.Run()
assert.NoError(t, err)
runGit(t, cmd, repoDir)

// File name
fileName := "file.txt"
Expand All @@ -193,14 +192,10 @@ func createRepo(t *testing.T, tc TestConfig) string {
assert.NoError(t, err)

cmd = exec.Command("git", "add", initialFileName)
cmd.Dir = repoDir
err = cmd.Run()
assert.NoError(t, err)
runGit(t, cmd, repoDir)

cmd = exec.Command("git", "commit", "-m", "Initial commit")
cmd.Dir = repoDir
err = cmd.Run()
assert.NoError(t, err)
runGit(t, cmd, repoDir)

// Step 4: Perform the action specified
switch tc.action {
Expand All @@ -209,9 +204,7 @@ func createRepo(t *testing.T, tc TestConfig) string {
assert.NoError(t, err)
case "move":
cmd = exec.Command("git", "mv", absolutePath, absolutePath2)
cmd.Dir = repoDir
err = cmd.Run()
assert.NoError(t, err)
runGit(t, cmd, repoDir)
case "delete":
err = os.Remove(absolutePath)
assert.NoError(t, err)
Expand All @@ -222,14 +215,18 @@ func createRepo(t *testing.T, tc TestConfig) string {

// Step 5: Stage changes and commit
cmd = exec.Command("git", "add", "-A")
cmd.Dir = repoDir
err = cmd.Run()
assert.NoError(t, err)
runGit(t, cmd, repoDir)

cmd = exec.Command("git", "commit", "-m", tc.action+" file")
cmd.Dir = repoDir
err = cmd.Run()
assert.NoError(t, err)
runGit(t, cmd, repoDir)

return repoDir
}

func runGit(t *testing.T, cmd *exec.Cmd, repoDir string) {
cmd.Dir = repoDir
err := cmd.Run()
out, _ := cmd.CombinedOutput()
log.Info(string(out))
assert.NoError(t, err)
}

0 comments on commit 4ba1204

Please sign in to comment.