-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_test.go
71 lines (58 loc) · 1.53 KB
/
git_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
60
61
62
63
64
65
66
67
68
69
70
71
package gitexec
import (
"context"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRunGit(t *testing.T) {
a := assert.New(t)
r := require.New(t)
executor, err := New(&Params{})
r.NoError(err)
// Test case 1: RunGit with valid arguments
result, err := executor.RunGit("status")
r.NoError(err)
a.NotNil(result)
a.Equal(0, result.ExitCode)
a.NotEmpty(result.Stdout.String())
a.Empty(result.Stderr.String())
// Test case 2: RunGit with invalid arguments
_, err = executor.RunGit("invalid-command")
a.Error(err)
}
func TestRunGitContext(t *testing.T) {
a := assert.New(t)
r := require.New(t)
ctx := context.Background()
executor, err := New(&Params{})
r.NoError(err)
// Test case 1: RunGit with valid arguments
result, err := executor.RunGitContext(ctx, "status")
r.NoError(err)
a.NotNil(result)
a.Equal(0, result.ExitCode)
a.NotEmpty(result.Stdout.String())
a.Empty(result.Stderr.String())
// Test case 2: RunGit with invalid arguments
_, err = executor.RunGit("invalid-command")
a.Error(err)
}
func TestRunGitWithEnv(t *testing.T) {
a := assert.New(t)
r := require.New(t)
executor, err := New(&Params{
Env: []string{
"GIT_AUTHOR_NAME=John Doe",
"GIT_AUTHOR_EMAIL=johndoe@example.com",
},
})
r.NoError(err)
result, err := executor.RunGit("var", "GIT_AUTHOR_IDENT")
r.NoError(err)
a.NotNil(result)
a.Equal(0, result.ExitCode)
a.True(strings.HasPrefix(result.Stdout.String(), "John Doe <johndoe@example.com>"))
a.Empty(result.Stderr.String())
}