Skip to content

Commit 333af23

Browse files
authored
INTMDB-648: Add CollectionType support (#432)
1 parent a970ab2 commit 333af23

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

mongodbatlas/online_archives.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ type OnlineArchive struct {
191191
ID string `json:"_id,omitempty"`
192192
ClusterName string `json:"clusterName,omitempty"`
193193
CollName string `json:"collName,omitempty"`
194+
CollectionType string `json:"collectionType,omitempty"`
194195
Criteria *OnlineArchiveCriteria `json:"criteria,omitempty"`
195196
DBName string `json:"dbName,omitempty"`
196197
GroupID string `json:"groupId,omitempty"`

mongodbatlas/online_archives_test.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,106 @@ func TestOnlineArchiveServiceOp_Create(t *testing.T) {
348348
}
349349
}
350350

351+
func TestOnlineArchiveServiceOp_CreateTimeSeries(t *testing.T) {
352+
client, mux, teardown := setup()
353+
defer teardown()
354+
355+
groupID := "5e2211c17a3e5a48f5497de3"
356+
clusterName := "myTestClstr"
357+
358+
createRequest := &OnlineArchive{
359+
CollName: "employees",
360+
CollectionType: "TIMESERIES",
361+
Criteria: &OnlineArchiveCriteria{
362+
Type: "DATE",
363+
DateFormat: "ISODATE",
364+
DateField: "created",
365+
ExpireAfterDays: pointer(5.0),
366+
},
367+
DBName: "people",
368+
PartitionFields: []*PartitionFields{
369+
{
370+
FieldName: "created",
371+
FieldType: "date",
372+
Order: pointer(0.0),
373+
},
374+
},
375+
}
376+
377+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/onlineArchives", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
378+
expected := map[string]interface{}{
379+
"collName": "employees",
380+
"collectionType": "TIMESERIES",
381+
"criteria": map[string]interface{}{
382+
"type": "DATE",
383+
"dateFormat": "ISODATE",
384+
"dateField": "created",
385+
"expireAfterDays": float64(5),
386+
},
387+
"dbName": "people",
388+
"partitionFields": []interface{}{
389+
map[string]interface{}{
390+
"fieldName": "created",
391+
"fieldType": "date",
392+
"order": float64(0),
393+
},
394+
},
395+
}
396+
397+
var v map[string]interface{}
398+
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
399+
t.Fatalf("decode json: %v", err)
400+
}
401+
if diff := deep.Equal(v, expected); diff != nil {
402+
t.Errorf("Clusters.Create Request Body = %v", diff)
403+
}
404+
405+
jsonBlob := `{
406+
"_id": "1",
407+
"clusterName": "myTestClstr",
408+
"collName":"employees",
409+
"collectionType": "TIMESERIES",
410+
"criteria": {
411+
"dateField": "created",
412+
"expireAfterDays": 5
413+
},
414+
"dbName": "people",
415+
"groupId": "5e2211c17a3e5a48f5497de3",
416+
"partitionFields": [{
417+
"fieldName": "created",
418+
"fieldType": "date",
419+
"order": 0
420+
}],
421+
"paused": false
422+
}`
423+
fmt.Fprint(w, jsonBlob)
424+
})
425+
426+
archive, _, err := client.OnlineArchives.Create(ctx, groupID, clusterName, createRequest)
427+
if err != nil {
428+
t.Fatalf("OnlineArchives.Create returned error: %v", err)
429+
}
430+
431+
const expectedDBName = "people"
432+
if archive.DBName != expectedDBName {
433+
t.Errorf("expected name '%s', received '%s'", expectedDBName, archive.DBName)
434+
}
435+
436+
const expectedColName = "employees"
437+
if archive.CollName != expectedColName {
438+
t.Errorf("expected name '%s', received '%s'", expectedColName, archive.CollName)
439+
}
440+
441+
const expectedCollectionType = "TIMESERIES"
442+
if archive.CollectionType != expectedCollectionType {
443+
t.Errorf("expected name '%s', received '%s'", expectedCollectionType, archive.CollectionType)
444+
}
445+
446+
if id := archive.GroupID; id != groupID {
447+
t.Errorf("expected groupId '%s', received '%s'", groupID, id)
448+
}
449+
}
450+
351451
func TestOnlineArchiveServiceOp_Update(t *testing.T) {
352452
client, mux, teardown := setup()
353453
defer teardown()

0 commit comments

Comments
 (0)