github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/extend/etcd/test/etcd_test.go (about) 1 package test 2 3 import ( 4 "context" 5 "fmt" 6 "github.com/isyscore/isc-gobase/config" 7 "github.com/isyscore/isc-gobase/extend/etcd" 8 "github.com/isyscore/isc-gobase/isc" 9 "github.com/isyscore/isc-gobase/time" 10 clientv3 "go.etcd.io/etcd/client/v3" 11 "testing" 12 ) 13 14 func Test1(t *testing.T) { 15 config.LoadYamlFile("./application-test1.yaml") 16 if config.GetValueBoolDefault("base.etcd.enable", false) { 17 err := config.GetValueObject("base.etcd", &config.EtcdCfg) 18 if err != nil { 19 return 20 } 21 } 22 23 etcdClient, _ := etcd.NewEtcdClient() 24 25 ctx := context.Background() 26 etcdClient.Put(ctx, "test", time.TimeToStringYmdHms(time.Now())) 27 rsp, _ := etcdClient.Get(ctx, "test") 28 etcdClient.Get(ctx, "test", func(pOp *clientv3.Op) { 29 fmt.Println("信息") 30 fmt.Println(isc.ToJsonString(&pOp)) 31 }) 32 fmt.Println(rsp) 33 } 34 35 func TestRetry(t *testing.T) { 36 config.LoadYamlFile("./application-retry.yaml") 37 if config.GetValueBoolDefault("base.etcd.enable", false) { 38 err := config.GetValueObject("base.etcd", &config.EtcdCfg) 39 if err != nil { 40 return 41 } 42 } 43 44 _, err := etcd.NewEtcdClient() 45 if err != nil { 46 fmt.Println("") 47 } else { 48 fmt.Println("链接etcd 成功") 49 } 50 }