-
Notifications
You must be signed in to change notification settings - Fork 127
/
command_test.go
65 lines (56 loc) · 1.5 KB
/
command_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
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCommand_String(t *testing.T) {
tests := []struct {
name string
args []string
expStr string
}{
{
name: "no args",
args: nil,
expStr: "git",
},
{
name: "has one arg",
args: []string{"version"},
expStr: "git version",
},
{
name: "has more args",
args: []string{"config", "--global", "http.proxy", "http://localhost:8080"},
expStr: "git config --global http.proxy http://localhost:8080",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := NewCommand(test.args...)
assert.Equal(t, test.expStr, cmd.String())
})
}
}
func TestCommand_AddArgs(t *testing.T) {
cmd := NewCommand()
assert.Equal(t, []string(nil), cmd.args)
cmd.AddArgs("push")
cmd.AddArgs("origin", "master")
assert.Equal(t, []string{"push", "origin", "master"}, cmd.args)
}
func TestCommand_AddEnvs(t *testing.T) {
cmd := NewCommand()
assert.Equal(t, []string(nil), cmd.envs)
cmd.AddEnvs("GIT_DIR=/tmp")
cmd.AddEnvs("HOME=/Users/unknwon", "GIT_EDITOR=code")
assert.Equal(t, []string{"GIT_DIR=/tmp", "HOME=/Users/unknwon", "GIT_EDITOR=code"}, cmd.envs)
}
func TestCommand_RunWithTimeout(t *testing.T) {
_, err := NewCommand("version").WithTimeout(time.Nanosecond).Run()
assert.Equal(t, ErrExecTimeout, err)
}