From cb69bf3714373555c6c1db6424312b1bf19f7373 Mon Sep 17 00:00:00 2001 From: GongGuoWei <62499904+guowei-gong@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:46:14 +0800 Subject: [PATCH] test(config): add etcd config method test (#2349) Added test cases for the about etcd method - WithPath(path string) - WithPrefix(prefix bool) Update #2135 --- contrib/config/etcd/config_test.go | 61 +++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/contrib/config/etcd/config_test.go b/contrib/config/etcd/config_test.go index c106c0573..821167ec4 100644 --- a/contrib/config/etcd/config_test.go +++ b/contrib/config/etcd/config_test.go @@ -15,7 +15,8 @@ const testKey = "/kratos/test/config" func TestConfig(t *testing.T) { client, err := clientv3.New(clientv3.Config{ Endpoints: []string{"127.0.0.1:2379"}, - DialTimeout: time.Second, DialOptions: []grpc.DialOption{grpc.WithBlock()}, + DialTimeout: time.Second, + DialOptions: []grpc.DialOption{grpc.WithBlock()}, }) if err != nil { t.Fatal(err) @@ -108,3 +109,61 @@ func TestExtToFormat(t *testing.T) { t.Errorf("kvs[0].Format is %s", kvs[0].Format) } } + +func TestEtcdWithPath(t *testing.T) { + tests := []struct { + name string + fields string + want string + }{ + { + name: "default", + fields: testKey, + want: testKey, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + options := &options{ + ctx: context.Background(), + } + + got := WithPath(tt.fields) + got(options) + + if options.path != tt.want { + t.Errorf("WithPath(tt.fields) = %v, want %v", got, tt.want) + } + }) + } +} + +func TestEtcdWithPrefix(t *testing.T) { + tests := []struct { + name string + fields bool + want bool + }{ + { + name: "default", + fields: false, + want: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + options := &options{ + ctx: context.Background(), + } + + got := WithPrefix(tt.fields) + got(options) + + if options.prefix != tt.want { + t.Errorf("WithPrefix(tt.fields) = %v, want %v", got, tt.want) + } + }) + } +}