1202
1203
// TestListNamespaces test
1205
>
clusterActive1 := "some random active cluster name"
1206
>
clusterStandby1 := "some random standby cluster name"
1207
>
clusters1 := []string{clusterActive1, clusterStandby1}
1208
>
1209
>
clusterActive2 := "other random active cluster name"
1210
>
clusterStandby2 := "other random standby cluster name"
1211
>
clusters2 := []string{clusterActive2, clusterStandby2}
1212
>
1213
>
testBinaries1 := &namespacepb.BadBinaries{
1214
>
Binaries: map[string]*namespacepb.BadBinaryInfo{
1215
>
"abc": {
1216
>
Reason: "test-reason1",
1217
>
Operator: "test-operator1",
1218
>
CreateTime: timestamppb.New(time.Date(2020, 8, 22, 0, 0, 0, 0, time.UTC)),
1219
>
},
1220
>
},
1221
>
}
1222
>
testBinaries2 := &namespacepb.BadBinaries{
1223
>
Binaries: map[string]*namespacepb.BadBinaryInfo{
1224
>
"efg": {
1225
>
Reason: "test-reason2",
1226
>
Operator: "test-operator2",
1227
>
CreateTime: timestamppb.New(time.Date(2020, 8, 22, 0, 0, 0, 0, time.UTC)),
1228
>
},
1229
>
},
1230
>
}
1231
>
1232
>
inputNamespaces := []*p.GetNamespaceResponse{
1233
>
{
1234
>
Namespace: &persistencespb.NamespaceDetail{
1235
>
Info: &persistencespb.NamespaceInfo{
1236
>
Id: uuid.NewString(),
1237
>
Name: "list-namespace-test-name-1",
1238
>
State: enumspb.NAMESPACE_STATE_REGISTERED,
1239
>
Description: "list-namespace-test-description-1",
1240
>
Owner: "list-namespace-test-owner-1",
1241
>
Data: map[string]string{"k1": "v1"},
1242
>
},
1243
>
Config: &persistencespb.NamespaceConfig{
1244
>
Retention: timestamp.DurationFromDays(109),
1245
>
HistoryArchivalState: enumspb.ARCHIVAL_STATE_ENABLED,
1246
>
HistoryArchivalUri: "test://history/uri",
1247
>
VisibilityArchivalState: enumspb.ARCHIVAL_STATE_ENABLED,
1248
>
VisibilityArchivalUri: "test://visibility/uri",
1249
>
BadBinaries: testBinaries1,
1250
>
},
1251
>
ReplicationConfig: &persistencespb.NamespaceReplicationConfig{
1252
>
ActiveClusterName: clusterActive1,
1253
>
Clusters: clusters1,
1254
>
},
1255
>
1256
>
ConfigVersion: 133,
1257
>
FailoverVersion: 266,
1258
>
},
1259
>
IsGlobalNamespace: true,
1260
>
},
1261
>
{
1262
>
Namespace: &persistencespb.NamespaceDetail{
1263
>
Info: &persistencespb.NamespaceInfo{
1264
>
Id: uuid.NewString(),
1265
>
Name: "list-namespace-test-name-2",
1266
>
State: enumspb.NAMESPACE_STATE_REGISTERED,
1267
>
Description: "list-namespace-test-description-2",
1268
>
Owner: "list-namespace-test-owner-2",
1269
>
Data: map[string]string{"k1": "v2"},
1270
>
},
1271
>
Config: &persistencespb.NamespaceConfig{
1272
>
Retention: timestamp.DurationFromDays(326),
1273
>
HistoryArchivalState: enumspb.ARCHIVAL_STATE_DISABLED,
1274
>
HistoryArchivalUri: "",
1275
>
VisibilityArchivalState: enumspb.ARCHIVAL_STATE_DISABLED,
1276
>
VisibilityArchivalUri: "",
1277
>
BadBinaries: testBinaries2,
1278
>
},
1279
>
ReplicationConfig: &persistencespb.NamespaceReplicationConfig{
1280
>
ActiveClusterName: clusterActive2,
1281
>
Clusters: clusters2,
1282
>
},
1283
>
ConfigVersion: 400,
1284
>
FailoverVersion: 667,
1285
>
},
1286
>
IsGlobalNamespace: false,
1287
>
},
1288
>
}
1289
>
for _, namespace := range inputNamespaces {
1290
>
_, err := m.CreateNamespace(
1291
>
namespace.Namespace.Info,
1292
>
namespace.Namespace.Config,
1293
>
namespace.Namespace.ReplicationConfig,
1294
>
namespace.IsGlobalNamespace,
1295
>
namespace.Namespace.ConfigVersion,
1296
>
namespace.Namespace.FailoverVersion,
1297
>
)
1298
>
m.NoError(err)
1299
>
}
1300
1302
>
const pageSize = 1
1303
>
pageCount := 0
1304
>
outputNamespaces := make(map[string]*p.GetNamespaceResponse)
1305
>
for {
1306
>
resp, err := m.ListNamespaces(pageSize, token)
1307
>
m.NoError(err)
1308
>
token = resp.NextPageToken
1309
>
for _, namespace := range resp.Namespaces {
1310
>
outputNamespaces[namespace.Namespace.Info.Id] = namespace
1311
>
// global notification version is already tested, so here we make it 0
1312
>
// so we can test == easily
1313
>
namespace.NotificationVersion = 0
1314
>
}
1315
// Some persistence backends return an unavoidable empty final page.
1317
>
pageCount++
1318
>
}
1319
>
if len(token) == 0 {
1320
>
break
1321
}
1322
}
1323
1324
// There should be 2 non-empty pages.
1326
>
m.Equal(len(inputNamespaces), len(outputNamespaces))
1327
>
for _, namespace := range inputNamespaces {
1328
>
m.DeepEqual(namespace, outputNamespaces[namespace.Namespace.Info.Id])
1329
>
}
1330
}
1331