|
| 1 | +package gapi |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +var ( |
| 6 | + cloudRegionResponse = `{ |
| 7 | + "id": 1, |
| 8 | + "status": "active", |
| 9 | + "slug": "us", |
| 10 | + "name": "United States", |
| 11 | + "description": "United States", |
| 12 | + "createdAt": "2021-08-20T20:00:27.000Z", |
| 13 | + "updatedAt": "2022-01-18T20:00:51.000Z", |
| 14 | + "visibility": "public", |
| 15 | + "stackStateServiceUrl": "http://apiserver.stackstate.svc.cluster.local", |
| 16 | + "syntheticMonitoringApiUrl": "https://synthetic-monitoring-api.grafana.net", |
| 17 | + "integrationsApiUrl": "https://integrations-api-us-central.grafana.net", |
| 18 | + "hostedExportersApiUrl": "https://hosted-exporters-api-us-central.grafana.net", |
| 19 | + "machineLearningApiUrl": "https://machine-learning-prod-us-central-0.grafana.net/machine-learning", |
| 20 | + "incidentApiUrl": null, |
| 21 | + "hgClusterId": 69, |
| 22 | + "hgClusterSlug": "prod-us-central-0", |
| 23 | + "hgClusterName": "prod-us-central-0", |
| 24 | + "hgClusterUrl": "https://hg-api-prod-us-central-0.grafana.net", |
| 25 | + "hmPromClusterId": 105, |
| 26 | + "hmPromClusterSlug": "prod-10-prod-us-central-0", |
| 27 | + "hmPromClusterName": "cortex-prod-10", |
| 28 | + "hmPromClusterUrl": "https://prometheus-prod-10-prod-us-central-0.grafana.net", |
| 29 | + "hmGraphiteClusterId": 105, |
| 30 | + "hmGraphiteClusterSlug": "prod-10-prod-us-central-0", |
| 31 | + "hmGraphiteClusterName": "cortex-prod-10", |
| 32 | + "hmGraphiteClusterUrl": "https://prometheus-prod-10-prod-us-central-0.grafana.net", |
| 33 | + "hlClusterId": 84, |
| 34 | + "hlClusterSlug": "loki-prod-us-central-0", |
| 35 | + "hlClusterName": "Hosted Logs Cluster (prod-us-central-0)", |
| 36 | + "hlClusterUrl": "https://logs-prod3.grafana.net", |
| 37 | + "amClusterId": 68, |
| 38 | + "amClusterSlug": "alertmanager-us-central1", |
| 39 | + "amClusterName": "alertmanager-us-central1", |
| 40 | + "amClusterUrl": "https://alertmanager-us-central1.grafana.net", |
| 41 | + "htClusterId": 78, |
| 42 | + "htClusterSlug": "tempo-prod-us-central1", |
| 43 | + "htClusterName": "tempo-prod-us-central1", |
| 44 | + "htClusterUrl": "https://tempo-us-central1.grafana.net" |
| 45 | +} |
| 46 | +` |
| 47 | + cloudRegionsResponse = `{ |
| 48 | + "items": [ |
| 49 | + ` + cloudRegionResponse + ` |
| 50 | + ] |
| 51 | +} |
| 52 | +` |
| 53 | + expectedRegion = CloudRegion{ID: 1, |
| 54 | + Status: "active", |
| 55 | + Slug: "us", |
| 56 | + Name: "United States", |
| 57 | + Description: "United States", |
| 58 | + CreatedAt: "2021-08-20T20:00:27.000Z", |
| 59 | + UpdatedAt: "2022-01-18T20:00:51.000Z", |
| 60 | + Visibility: "public", |
| 61 | + StackStateServiceURL: "http://apiserver.stackstate.svc.cluster.local", |
| 62 | + SyntheticMonitoringAPIURL: "https://synthetic-monitoring-api.grafana.net", |
| 63 | + IntegrationsAPIURL: "https://integrations-api-us-central.grafana.net", |
| 64 | + HostedExportersAPIURL: "https://hosted-exporters-api-us-central.grafana.net", |
| 65 | + MachineLearningAPIURL: "https://machine-learning-prod-us-central-0.grafana.net/machine-learning", |
| 66 | + IncidentsAPIURL: "", |
| 67 | + HGClusterID: 69, |
| 68 | + HGClusterSlug: "prod-us-central-0", |
| 69 | + HGClusterName: "prod-us-central-0", |
| 70 | + HGClusterURL: "https://hg-api-prod-us-central-0.grafana.net", |
| 71 | + HMPromClusterID: 105, |
| 72 | + HMPromClusterSlug: "prod-10-prod-us-central-0", |
| 73 | + HMPromClusterName: "cortex-prod-10", |
| 74 | + HMPromClusterURL: "https://prometheus-prod-10-prod-us-central-0.grafana.net", |
| 75 | + HMGraphiteClusterID: 105, |
| 76 | + HMGraphiteClusterSlug: "prod-10-prod-us-central-0", |
| 77 | + HMGraphiteClusterName: "cortex-prod-10", |
| 78 | + HMGraphiteClusterURL: "https://prometheus-prod-10-prod-us-central-0.grafana.net", |
| 79 | + HLClusterID: 84, |
| 80 | + HLClusterSlug: "loki-prod-us-central-0", |
| 81 | + HLClusterName: "Hosted Logs Cluster (prod-us-central-0)", |
| 82 | + HLClusterURL: "https://logs-prod3.grafana.net", |
| 83 | + AMClusterID: 68, |
| 84 | + AMClusterSlug: "alertmanager-us-central1", |
| 85 | + AMClusterName: "alertmanager-us-central1", |
| 86 | + AMClusterURL: "https://alertmanager-us-central1.grafana.net", |
| 87 | + HTClusterID: 78, |
| 88 | + HTClusterSlug: "tempo-prod-us-central1", |
| 89 | + HTClusterName: "tempo-prod-us-central1", |
| 90 | + HTClusterURL: "https://tempo-us-central1.grafana.net"} |
| 91 | +) |
| 92 | + |
| 93 | +func TestCloudRegions(t *testing.T) { |
| 94 | + server, client := gapiTestTools(t, 200, cloudRegionsResponse) |
| 95 | + defer server.Close() |
| 96 | + |
| 97 | + regions, err := client.GetCloudRegions() |
| 98 | + |
| 99 | + if err != nil { |
| 100 | + t.Fatalf("expected error to be nil; got: %s", err.Error()) |
| 101 | + } |
| 102 | + |
| 103 | + // check that the number of items is the same |
| 104 | + if got := len(regions.Items); got != 1 { |
| 105 | + t.Errorf("Length of returned regions - Actual regions count: %d, Expected regions count: %d", got, 1) |
| 106 | + } |
| 107 | + |
| 108 | + if got := regions.Items[0]; got != expectedRegion { |
| 109 | + t.Errorf("Unexpected Region - Got:\n%#v\n, Expected:\n%#v\n", got, expectedRegion) |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +func TestCloudRegionBySlug(t *testing.T) { |
| 114 | + server, client := gapiTestTools(t, 200, cloudRegionResponse) |
| 115 | + defer server.Close() |
| 116 | + |
| 117 | + resp, err := client.GetCloudRegionBySlug("us") |
| 118 | + if err != nil { |
| 119 | + t.Fatal(err) |
| 120 | + } |
| 121 | + |
| 122 | + if resp != expectedRegion { |
| 123 | + t.Errorf("Unexpected Region - Got:\n%#v\n, Expected:\n%#v\n", resp, expectedRegion) |
| 124 | + } |
| 125 | +} |
0 commit comments