/
git_cmd_test.go
59 lines (47 loc) · 1.5 KB
/
git_cmd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package true_git
import (
"context"
"os"
"path/filepath"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/werf/werf/test/pkg/utils"
)
var _ = Describe("Git command", func() {
var gitRepoPath string
BeforeEach(func() {
gitRepoPath = filepath.Join(SuiteData.TestDirPath, "repo")
utils.MkdirAll(gitRepoPath)
utils.RunSucceedCommand(
gitRepoPath,
"git",
"-c", "init.defaultBranch=main",
"init",
)
utils.RunSucceedCommand(
gitRepoPath,
"git",
"checkout", "-b", "main",
)
utils.RunSucceedCommand(
gitRepoPath,
"git",
"commit", "--allow-empty", "-m", "Initial commit",
)
Ω(Init(context.Background(), Options{})).Should(Succeed())
})
When("looking for existent ref", func() {
It("succeeds, populates stdout/err/outerr buffers correctly", func() {
ctx := context.Background()
brokenHeadPath := filepath.Join(gitRepoPath, ".git", "refs", "heads", "broken")
Expect(os.WriteFile(brokenHeadPath, []byte("invalid"), os.ModePerm)).To(Succeed())
branchCmd := NewGitCmd(ctx, &GitCmdOptions{RepoDir: gitRepoPath}, "branch", "--list", "main")
err := branchCmd.Run(ctx)
Expect(err).To(Succeed())
Expect(branchCmd.OutBuf.String()).To(Equal("* main\n"))
Expect(branchCmd.ErrBuf.String()).To(Equal("warning: ignoring broken ref refs/heads/broken\n"))
Expect(branchCmd.OutErrBuf.String()).To(ContainSubstring("warning: ignoring broken ref refs/heads/broken"))
Expect(branchCmd.OutErrBuf.String()).To(ContainSubstring("* main"))
})
})
})