@@ -35,7 +35,9 @@ import (
35
35
"go.etcd.io/etcd/client/pkg/v3/srv"
36
36
"go.etcd.io/etcd/client/pkg/v3/transport"
37
37
"go.etcd.io/etcd/client/pkg/v3/types"
38
+ clientv3 "go.etcd.io/etcd/client/v3"
38
39
"go.etcd.io/etcd/pkg/v3/featuregate"
40
+ "go.etcd.io/etcd/server/v3/etcdserver/api/v3discovery"
39
41
"go.etcd.io/etcd/server/v3/features"
40
42
)
41
43
@@ -1070,3 +1072,51 @@ func TestMatchNewConfigAddFlags(t *testing.T) {
1070
1072
t .Errorf ("Diff: %s" , diff )
1071
1073
}
1072
1074
}
1075
+
1076
+ func TestDiscoveryCfg (t * testing.T ) {
1077
+ testCases := []struct {
1078
+ name string
1079
+ discoveryCfg v3discovery.DiscoveryConfig
1080
+ wantErr bool
1081
+ }{
1082
+ {
1083
+ name : "Valid discovery config" ,
1084
+ discoveryCfg : v3discovery.DiscoveryConfig {
1085
+ ConfigSpec : clientv3.ConfigSpec {
1086
+ Endpoints : []string {"http://10.0.0.100:2379" , "http://10.0.0.101:2379" },
1087
+ },
1088
+ },
1089
+ wantErr : false ,
1090
+ },
1091
+ {
1092
+ name : "Partial empty discovery endpoints" ,
1093
+ discoveryCfg : v3discovery.DiscoveryConfig {
1094
+ ConfigSpec : clientv3.ConfigSpec {
1095
+ Endpoints : []string {"http://10.0.0.100:2379" , "" },
1096
+ },
1097
+ },
1098
+ wantErr : true ,
1099
+ },
1100
+ {
1101
+ name : "Empty discovery endpoint" ,
1102
+ discoveryCfg : v3discovery.DiscoveryConfig {
1103
+ ConfigSpec : clientv3.ConfigSpec {
1104
+ Endpoints : []string {"" , "" },
1105
+ },
1106
+ },
1107
+ wantErr : true ,
1108
+ },
1109
+ }
1110
+
1111
+ for _ , tc := range testCases {
1112
+ t .Run (tc .name , func (t * testing.T ) {
1113
+ cfg := NewConfig ()
1114
+ cfg .InitialCluster = ""
1115
+ cfg .DiscoveryCfg = tc .discoveryCfg
1116
+ cfg .DiscoveryCfg .Token = "foo"
1117
+ err := cfg .Validate ()
1118
+
1119
+ require .Equal (t , tc .wantErr , err != nil )
1120
+ })
1121
+ }
1122
+ }
0 commit comments