-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schedule strategy for PagerDuty #8
Changes from all commits
35660f2
9d2f680
bfd300c
bd1f4f5
c491b69
3bf1a6f
e00fe7f
6b98410
42a8043
d721669
c47b2ff
57dcef7
9c643ee
072a999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ import ( | |
"net/http/httptest" | ||
"net/url" | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/firehydrant/signals-migrator/pager" | ||
"github.com/firehydrant/signals-migrator/store" | ||
"github.com/gosimple/slug" | ||
) | ||
|
||
|
@@ -34,6 +36,13 @@ func pagerDutyTestClient(t *testing.T, apiURL string) (context.Context, *pager.P | |
return ctx, pd | ||
} | ||
|
||
func assertDeepEqual[T any](t *testing.T, got, want T) { | ||
t.Helper() | ||
if !reflect.DeepEqual(got, want) { | ||
t.Fatalf("[FAIL]\n got: %+v\nwant: %+v", got, want) | ||
} | ||
} | ||
|
||
func TestPagerDuty(t *testing.T) { | ||
ts := pagerDutyHttpServer(t) | ||
ctx, pd := pagerDutyTestClient(t, ts.URL) | ||
|
@@ -44,17 +53,47 @@ func TestPagerDuty(t *testing.T) { | |
t.Fatalf("error loading schedules: %s", err) | ||
} | ||
t.Logf("found %d users", len(u)) | ||
// The only assertion so far from this test is that method will not error. | ||
// We need stronger checks for this test to be more useful. | ||
// TODO: verify that the users are accurate. | ||
|
||
// Verify that the first user is as expected. | ||
mika := u[0] | ||
expected := &pager.User{ | ||
Email: "[email protected]", | ||
Resource: pager.Resource{ | ||
ID: "P5A1XH2", | ||
Name: "Mika", | ||
}, | ||
} | ||
assertDeepEqual(t, mika, expected) | ||
}) | ||
|
||
t.Run("LoadSchedules", func(t *testing.T) { | ||
if err := pd.LoadSchedules(ctx); err != nil { | ||
t.Fatalf("error loading schedules: %s", err) | ||
} | ||
// The only assertion so far from this test is that method will not error. | ||
// We need stronger checks for this test to be more useful. | ||
// TODO: verify that the schedules were saved to the database. | ||
|
||
// At the moment, this will show "Team ... not found" warning in logs because | ||
// we didn't seed the database with that information. After we refactor the methods | ||
// ListTeams and ListUsers to use database, as LoadTeams and LoadUsers respectively, | ||
// we should expect the warning to go away. | ||
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: "P3D7DLW-PC1DX4O", | ||
Name: "Jen - primary - Layer 2", | ||
Description: "(Layer 2)", | ||
Timezone: "America/Los_Angeles", | ||
Strategy: "weekly", | ||
ShiftDuration: "", | ||
StartTime: "", | ||
HandoffTime: "16:00:00", | ||
HandoffDay: "monday", | ||
} | ||
assertDeepEqual(t, first, expected) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,9 +54,10 @@ | |
"rendered_schedule_entries": [], | ||
"restrictions": [ | ||
{ | ||
"duration_seconds": 28800, | ||
"type": "weekly_restriction", | ||
"start_time_of_day": "09:00:00", | ||
"type": "daily_restriction" | ||
"duration_seconds": 374400, | ||
"start_day_of_week": 1 | ||
Comment on lines
+57
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some variation to spice things up |
||
} | ||
], | ||
"rotation_turn_length_seconds": 604800, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/PT54U20", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/PT54U20", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😬 |
||
"id": "PT54U20", | ||
"name": "Jen", | ||
"parent": null, | ||
|
@@ -17,7 +17,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/PO206TE", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/PO206TE", | ||
"id": "PO206TE", | ||
"name": "canary-team", | ||
"parent": null, | ||
|
@@ -28,7 +28,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/PO34CI9", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/PO34CI9", | ||
"id": "PO34CI9", | ||
"name": "CS-Team-Test", | ||
"parent": null, | ||
|
@@ -39,7 +39,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/PEGBTKE", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/PEGBTKE", | ||
"id": "PEGBTKE", | ||
"name": "CS-Test-Alerting", | ||
"parent": null, | ||
|
@@ -50,7 +50,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/P7E9UET", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/P7E9UET", | ||
"id": "P7E9UET", | ||
"name": "caroline-team-test", | ||
"parent": null, | ||
|
@@ -61,7 +61,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/P7A9Q6H", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/P7A9Q6H", | ||
"id": "P7A9Q6H", | ||
"name": "operational-team-test", | ||
"parent": null, | ||
|
@@ -72,7 +72,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/P5PH8KY", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/P5PH8KY", | ||
"id": "P5PH8KY", | ||
"name": "Page Responder Team", | ||
"parent": null, | ||
|
@@ -83,7 +83,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/PV9JOXL", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/PV9JOXL", | ||
"id": "PV9JOXL", | ||
"name": "Service Catalog Team", | ||
"parent": null, | ||
|
@@ -94,7 +94,7 @@ | |
{ | ||
"default_role": "manager", | ||
"description": null, | ||
"html_url": "https://firehydrant-eng.pagerduty.com/teams/PD2F80U", | ||
"html_url": "https://acme-inc.pagerduty.com/teams/PD2F80U", | ||
"id": "PD2F80U", | ||
"name": "Jack Team", | ||
"parent": null, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, have you encountered this? i'm guessing they might have a "custom" restriction type that can wrap around day boundaries? in which case, we should be able to support those
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
their API only says
daily_restriction
andweekly_restriction
, nothing else. i added the line just to "fail loudly" so we can learn any unknown behavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry that didn't answer your question — no i havent 😅