|
| 1 | +package mongodbatlas |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/go-test/deep" |
| 9 | +) |
| 10 | + |
| 11 | +func TestProcessDatabaseMeasurements_List(t *testing.T) { |
| 12 | + setup() |
| 13 | + defer teardown() |
| 14 | + |
| 15 | + groups := "12345678" |
| 16 | + host := "shard-00-00.mongodb.net" |
| 17 | + port := 27017 |
| 18 | + database := "database" |
| 19 | + |
| 20 | + mux.HandleFunc(fmt.Sprintf("/groups/%s/processes/%s:%d/databases/%s/measurements", groups, host, port, database), func(w http.ResponseWriter, r *http.Request) { |
| 21 | + testMethod(t, r, http.MethodGet) |
| 22 | + fmt.Fprint(w, `{ |
| 23 | + "end" : "2017-08-22T20:31:14Z", |
| 24 | + "granularity" : "PT1M", |
| 25 | + "groupId" : "12345678", |
| 26 | + "hostId" : "shard-00-00.mongodb.net:27017", |
| 27 | + "links" : [ { |
| 28 | + "href" : "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/dataabses/database/measurements?granularity=PT1M&period=PT1M", |
| 29 | + "rel" : "self" |
| 30 | + }, { |
| 31 | + "href" : "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017", |
| 32 | + "rel" : "http://mms.mongodb.com/host" |
| 33 | + } ], |
| 34 | + "measurements" : [ { |
| 35 | + "dataPoints" : [ { |
| 36 | + "timestamp" : "2017-08-22T20:31:12Z", |
| 37 | + "value" : null |
| 38 | + }, { |
| 39 | + "timestamp" : "2017-08-22T20:31:14Z", |
| 40 | + "value" : null |
| 41 | + } ], |
| 42 | + "name" : "DISK_PARTITION_IOPS_READ", |
| 43 | + "units" : "SCALAR_PER_SECOND" |
| 44 | + }], |
| 45 | + "databaseName":"database", |
| 46 | + "processId" : "shard-00-00.mongodb.net:27017", |
| 47 | + "start" : "2017-08-22T20:30:45Z" |
| 48 | + }`) |
| 49 | + }) |
| 50 | + |
| 51 | + opts := &ProcessMeasurementListOptions{ |
| 52 | + Granularity: "PT1M", |
| 53 | + Period: "PT1M", |
| 54 | + } |
| 55 | + |
| 56 | + measurements, _, err := client.ProcessDatabaseMeasurements.List(ctx, groups, host, port, database, opts) |
| 57 | + if err != nil { |
| 58 | + t.Fatalf("ProcessDatabaseMeasurements.List returned error: %v", err) |
| 59 | + } |
| 60 | + |
| 61 | + expected := &ProcessDatabaseMeasurements{ |
| 62 | + ProcessMeasurements: &ProcessMeasurements{ |
| 63 | + End: "2017-08-22T20:31:14Z", |
| 64 | + Granularity: "PT1M", |
| 65 | + GroupID: "12345678", |
| 66 | + HostID: "shard-00-00.mongodb.net:27017", |
| 67 | + Links: []*Link{ |
| 68 | + { |
| 69 | + Rel: "self", |
| 70 | + Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/dataabses/database/measurements?granularity=PT1M&period=PT1M", |
| 71 | + }, |
| 72 | + { |
| 73 | + Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017", |
| 74 | + Rel: "http://mms.mongodb.com/host", |
| 75 | + }, |
| 76 | + }, |
| 77 | + Measurements: []*Measurements{ |
| 78 | + { |
| 79 | + DataPoints: []*DataPoints{ |
| 80 | + { |
| 81 | + Timestamp: "2017-08-22T20:31:12Z", |
| 82 | + Value: nil, |
| 83 | + }, |
| 84 | + { |
| 85 | + Timestamp: "2017-08-22T20:31:14Z", |
| 86 | + Value: nil, |
| 87 | + }, |
| 88 | + }, |
| 89 | + Name: "DISK_PARTITION_IOPS_READ", |
| 90 | + Units: "SCALAR_PER_SECOND", |
| 91 | + }, |
| 92 | + }, |
| 93 | + ProcessID: "shard-00-00.mongodb.net:27017", |
| 94 | + Start: "2017-08-22T20:30:45Z", |
| 95 | + }, |
| 96 | + DatabaseName: "database", |
| 97 | + } |
| 98 | + |
| 99 | + if diff := deep.Equal(measurements, expected); diff != nil { |
| 100 | + t.Error(diff) |
| 101 | + } |
| 102 | +} |
0 commit comments