Ryk*_*yke 5 typechecking go golangci-lint
我是 golang 新手,我正在尝试测试我的代理函数,测试正确通过,但是在运行 golangci 时,它给了我错误:
未声明的名称:(getProxyURL
类型检查) if got := getProxyURL(tt.args.campaignCode, urls); 得到!= tt.想要 { ^
func getProxyURL(campaignCode string, urls map[string]string) string {
if campaignURL, ok := urls[campaignCode]; ok {
return campaignURL
}
return "https://facebook.com"
}
Run Code Online (Sandbox Code Playgroud)
_测试
package main
import "testing"
func Test_getProxyURL(t *testing.T) {
type args struct {
campaignCode string
}
urls := make(map[string]string, 0)
urls["82383b80-056b-42e8-b192-9b0f33c4f46e"] = "https://google.com"
urls["negativeTest"] = "https://facebook.com"
tests := []struct {
name string
args args
want string
}{
{
name: "Given an invalid campaign code, we receive facebook url as result",
args: args{campaignCode: "negativeTest"},
want: "https://facebook.com",
}, {
name: "Given an valid campaign code, we receive google url as result",
args: args{campaignCode: "82383b80-056b-42e8-b192-9b0f33c4f46e"},
want: "https://google.com",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getProxyURL(tt.args.campaignCode, urls); got != tt.want {
t.Errorf("getProxyURL() = %v, want %v", got, tt.want)
}
})
}
}
Run Code Online (Sandbox Code Playgroud)
我找不到问题