-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eca061e
commit ee59405
Showing
5 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package pager_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/firehydrant/signals-migrator/pager" | ||
"github.com/firehydrant/signals-migrator/store" | ||
"github.com/gosimple/slug" | ||
) | ||
|
||
func opsgenieHttpServer(t *testing.T) *httptest.Server { | ||
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
filename, err := url.JoinPath("testdata", t.Name(), slug.Make(r.URL.Path)+".json") | ||
if err != nil { | ||
t.Fatalf("error joining path for expected response: %s", err) | ||
} | ||
if _, err := os.Stat(filename); err != nil { | ||
t.Logf("file not found: %s", filename) | ||
http.NotFound(w, r) | ||
return | ||
} | ||
http.ServeFile(w, r, filename) | ||
}) | ||
return httptest.NewServer(h) | ||
} | ||
|
||
func opsgenieTestClient(t *testing.T, apiURL string) (context.Context, *pager.Opsgenie) { | ||
ctx := withTestDB(t) | ||
og := pager.NewOpsgenieWithURL("api-key-very-secret", apiURL) | ||
return ctx, og | ||
} | ||
|
||
func TestOpsgenie(t *testing.T) { | ||
ts := opsgenieHttpServer(t) | ||
ctx, og := opsgenieTestClient(t, strings.TrimPrefix(ts.URL, "http://")) | ||
|
||
t.Run("ListUsers", func(t *testing.T) { | ||
u, err := og.ListUsers(ctx) | ||
if err != nil { | ||
t.Fatalf("error loading users: %s", err) | ||
} | ||
t.Logf("found %d users", len(u)) | ||
|
||
// Verify that the first user is as expected. | ||
mika := u[0] | ||
expected := &pager.User{ | ||
Email: "[email protected]", | ||
Resource: pager.Resource{ | ||
ID: "b5b92115-bfe7-43eb-8c2a-e467f2e5ddc4", | ||
Name: "john doe", | ||
}, | ||
} | ||
assertDeepEqual(t, mika, expected) | ||
}) | ||
|
||
t.Run("LoadSchedules", func(t *testing.T) { | ||
if err := og.LoadSchedules(ctx); err != nil { | ||
t.Fatalf("error loading schedules: %s", err) | ||
} | ||
|
||
s, err := store.UseQueries(ctx).ListExtSchedules(ctx) | ||
if err != nil { | ||
t.Fatalf("error loading schedules: %s", err) | ||
} | ||
t.Logf("found %d schedules", len(s)) | ||
|
||
// Verify that the first schedule is as expected. | ||
first := s[0] | ||
expected := store.ExtSchedule{ | ||
ID: "3fee43f2-02da-49be-ab50-c88ed13aecc3-b1b5f7f6-728b-47bd-af02-c3e1c33bf219", | ||
Name: "Customer Success_schedule - Rot1", | ||
Description: "(Rot1)", | ||
Timezone: "America/Los_Angeles", | ||
Strategy: "weekly", | ||
ShiftDuration: "", | ||
StartTime: "", | ||
HandoffTime: "04:45:32", | ||
HandoffDay: "tuesday", | ||
} | ||
assertDeepEqual(t, first, expected) | ||
}) | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
pager/testdata/TestOpsgenie/v2-schedules-3fee43f2-02da-49be-ab50-c88ed13aecc3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"data": { | ||
"id": "3fee43f2-02da-49be-ab50-c88ed13aecc3", | ||
"name": "Customer Success_schedule", | ||
"description": "", | ||
"timezone": "America/Los_Angeles", | ||
"enabled": true, | ||
"ownerTeam": { | ||
"id": "b7acbc33-9853-4150-8a4b-10156d9408c8", | ||
"name": "Customer Success" | ||
}, | ||
"rotations": [ | ||
{ | ||
"id": "b1b5f7f6-728b-47bd-af02-c3e1c33bf219", | ||
"name": "Rot1", | ||
"startDate": "1970-01-20T04:45:32.4Z", | ||
"endDate": null, | ||
"type": "weekly", | ||
"length": 1, | ||
"participants": [ | ||
{ | ||
"type": "user", | ||
"id": "b5b92115-bfe7-43eb-8c2a-e467f2e5ddc4", | ||
"username": "[email protected]" | ||
} | ||
], | ||
"timeRestriction": null | ||
} | ||
] | ||
}, | ||
"took": 0.039, | ||
"requestId": "b5cf1da9-faba-4fc4-b6d9-d3b0a264b9b7" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"id": "3fee43f2-02da-49be-ab50-c88ed13aecc3", | ||
"name": "Customer Success_schedule", | ||
"description": "", | ||
"timezone": "America/Los_Angeles", | ||
"enabled": true, | ||
"ownerTeam": { | ||
"id": "b7acbc33-9853-4150-8a4b-10156d9408c8", | ||
"name": "Customer Success" | ||
}, | ||
"rotations": [] | ||
} | ||
], | ||
"expandable": [ | ||
"rotation" | ||
], | ||
"took": 0.087, | ||
"requestId": "7fc91399-2baf-4c26-a156-3e77c29507ef" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"totalCount": 2, | ||
"data": [ | ||
{ | ||
"blocked": false, | ||
"verified": true, | ||
"id": "b5b92115-bfe7-43eb-8c2a-e467f2e5ddc4", | ||
"username": "[email protected]", | ||
"fullName": "john doe", | ||
"role": { | ||
"id": "Admin", | ||
"name": "Admin" | ||
}, | ||
"timeZone": "America/New_York", | ||
"locale": "en_US", | ||
"userAddress": { | ||
"country": "", | ||
"state": "", | ||
"city": "", | ||
"line": "", | ||
"zipCode": "" | ||
}, | ||
"createdAt": "2022-07-07T20:42:29.853Z" | ||
}, | ||
{ | ||
"blocked": false, | ||
"verified": true, | ||
"id": "b5b92115-bfe7-43eb-8c2a-e467f2e5ddc5", | ||
"username": "[email protected]", | ||
"fullName": "jane doe", | ||
"role": { | ||
"id": "Admin", | ||
"name": "Admin" | ||
}, | ||
"timeZone": "America/New_York", | ||
"locale": "en_US", | ||
"userAddress": { | ||
"country": "", | ||
"state": "", | ||
"city": "", | ||
"line": "", | ||
"zipCode": "" | ||
}, | ||
"createdAt": "2022-07-07T20:42:29.853Z" | ||
} | ||
], | ||
"paging": { | ||
"first": "https://api.opsgenie.com/v2/users?limit=100&offset=0&order=ASC&sort=username", | ||
"last": "https://api.opsgenie.com/v2/users?limit=100&offset=0&order=ASC&sort=username" | ||
}, | ||
"took": 0.054, | ||
"requestId": "1a80d272-80f1-4b38-b319-f617ff8ee136" | ||
} |