6 Star 0 Fork 21

openEuler/sync-bot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main_test.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"flag"
"reflect"
"testing"
)
func Test_gatherOptions(t *testing.T) {
cases := []struct {
name string
args map[string]string
expected func(*options)
err bool
}{
{
name: "minimal flags work",
},
{
name: "explicitly set --gitee-token",
args: map[string]string{
"--gitee-token": "/random/value",
},
expected: func(o *options) {
o.giteeToken = "/random/value"
},
},
{
name: "explicitly set --webhook-secret",
args: map[string]string{
"--webhook-secret": "/random/value",
},
expected: func(o *options) {
o.webhookSecret = "/random/value"
},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
expected := &options{
port: 8765,
giteeToken: "token.conf",
webhookSecret: "secret.conf",
}
if tc.expected != nil {
tc.expected(expected)
}
argMap := map[string]string{}
for k, v := range tc.args {
argMap[k] = v
}
var args []string
for k, v := range argMap {
args = append(args, k+"="+v)
}
fs := flag.NewFlagSet("fake-flags", flag.PanicOnError)
actual := gatherOptions(fs, args...)
switch err := actual.Validate(); {
case err != nil:
if !tc.err {
t.Errorf("unexpected error: %v", err)
}
case tc.err:
t.Errorf("failed to receive expected error")
case !reflect.DeepEqual(*expected, actual):
t.Errorf("%#v != expected %#v", actual, *expected)
}
})
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/sync-bot.git
git@gitee.com:openeuler/sync-bot.git
openeuler
sync-bot
sync-bot
master

搜索帮助