Skip to content

Commit 5d373b3

Browse files
committed
test(git): add testcase of function git.InstallSubCmd
before: only failure testcase afeter: add testdata/testcmd file to test normal testcase
1 parent fe57f79 commit 5d373b3

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ commit:
2929
@go run main.go
3030

3131
build: clean
32+
@echo "========> Building binary"
3233
go build ${GO_BUILD_FLAGS} -o ${BIN}
3334

3435
dryRun: build

git/install_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/*
22
* @Author: robert zhang <robertzhangwenjie@gmail.com>
33
* @Date: 2022-08-06 16:52:22
4-
* @LastEditTime: 2022-08-07 10:55:53
4+
* @LastEditTime: 2022-09-03 17:24:07
55
* @LastEditors: robert zhang
66
* @Description:
77
*/
88
package git
99

1010
import (
11+
"os"
12+
"path/filepath"
1113
"testing"
1214
)
1315

@@ -20,7 +22,6 @@ func TestInstallSubCmd(t *testing.T) {
2022
testcases := []struct {
2123
name string
2224
args args
23-
want string
2425
wantErr bool
2526
}{
2627
{
@@ -29,18 +30,28 @@ func TestInstallSubCmd(t *testing.T) {
2930
filePath: "/123/456",
3031
subCmdName: "123",
3132
},
32-
want: "",
3333
wantErr: true,
3434
},
35+
{
36+
name: "normalFile",
37+
args: args{
38+
filePath: filepath.Join("testdata", "testcmd"),
39+
subCmdName: "testcmd",
40+
},
41+
wantErr: false,
42+
},
3543
}
3644

3745
for _, tc := range testcases {
3846
t.Run(tc.name, func(t *testing.T) {
3947
dstFilePath, err := InstallSubCmd(tc.args.filePath, tc.args.subCmdName)
40-
if (err != nil) != tc.wantErr && dstFilePath != tc.want {
41-
t.Errorf("InstallSubCmd() error = %v,wantErr %v", err, tc.wantErr)
48+
if err == nil {
49+
os.Remove(dstFilePath)
4250
}
51+
if (err != nil) != tc.wantErr {
52+
t.Errorf("InstallSubCmd() error = %v,wantErr %v ", err, tc.wantErr)
53+
}
54+
4355
})
4456
}
45-
4657
}

git/testdata/testcmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
###
2+
# @Author: robert zhang <robertzhangwenjie@gmail.com>
3+
# @Date: 2022-09-03 16:50:19
4+
# @LastEditTime: 2022-09-03 17:26:03
5+
# @LastEditors: robert zhang
6+
# @Description: testfile for testing installCmd
7+
###

0 commit comments

Comments
 (0)