添加 projects 测试

This commit is contained in:
徐晓伟 2023-10-04 22:29:47 +08:00
parent 3a248d6ec9
commit c1ae962193
1 changed files with 30 additions and 0 deletions

View File

@ -1,11 +1,41 @@
package main
import (
"bytes"
"fmt"
"github.com/xuxiaowei-com-cn/git-go/buildinfo"
"os"
"strings"
"testing"
)
func Test_CommitSha(t *testing.T) {
fmt.Println(buildinfo.CommitSha())
}
func Test_Projects(t *testing.T) {
var buf bytes.Buffer
// 不带参数的测试输出
os.Args = []string{"cmd"}
main()
if got := buf.String(); !strings.Contains(got, "") {
t.Errorf("异常信息:\n%s", got)
}
buf.Reset()
// 使用版本参数测试输出
os.Args = []string{"cmd", "projects"}
main()
if got := buf.String(); !strings.Contains(got, "") {
t.Errorf("异常信息:\n%s", got)
}
// 使用版本参数测试输出
os.Args = []string{"cmd", "p"}
main()
if got := buf.String(); !strings.Contains(got, "") {
t.Errorf("异常信息:\n%s", got)
}
}