1 Star 0 Fork 0

ClickVisual/casbin-redis-watcher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
options_test.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
MEX7 提交于 2022-08-10 18:02 . init
package rediswatcher
import "testing"
func TestOptions(t *testing.T) {
o := WatcherOptions{
Channel: "ch1",
Password: "pa1",
Protocol: "pr1",
Username: "user1",
}
// test single option
o.optionBuilder(Channel("ch2"))
if o.Channel != "ch2" {
t.Errorf("Channel should be 'ch2', received '%s' instead", o.Channel)
}
if o.Username != "user1" {
t.Errorf("Username should be 'user1', received '%s' instead", o.Username)
}
if o.Password != "pa1" {
t.Errorf("Password should be 'pa1', received '%s' instead", o.Password)
}
// test multiple options
o.optionBuilder(Channel("ch3"), Password("pa3"), Protocol("pr3"), Username("user3"))
if o.Channel != "ch3" {
t.Errorf("Channel should be 'ch3', received '%s' instead", o.Channel)
}
if o.Password != "pa3" {
t.Errorf("Password should be 'pa3', received '%s' instead", o.Password)
}
if o.Protocol != "pr3" {
t.Errorf("Protocol should be 'pr3', received '%s' instead", o.Password)
}
if o.Username != "user3" {
t.Errorf("Username should be 'user3', received '%s' instead", o.Username)
}
}
func (o *WatcherOptions) optionBuilder(setters ...WatcherOption) {
for _, setter := range setters {
setter(o)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/clickvisual/casbin-redis-watcher.git
git@gitee.com:clickvisual/casbin-redis-watcher.git
clickvisual
casbin-redis-watcher
casbin-redis-watcher
main

搜索帮助