diff --git a/github/actions_hosted_runners_test.go b/github/actions_hosted_runners_test.go index 4a98f800c71..b4cc96a61ba 100644 --- a/github/actions_hosted_runners_test.go +++ b/github/actions_hosted_runners_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -48,7 +47,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }, { "id": 7, @@ -69,7 +68,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { "maximum_runners": 20, "public_ip_enabled": false, "public_ips": [], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` } ] }`) @@ -81,8 +80,6 @@ func TestActionsService_ListHostedRunners(t *testing.T) { t.Errorf("Actions.ListHostedRunners returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} - want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -111,7 +108,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, }, { ID: Ptr(int64(7)), @@ -132,7 +129,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, }, }, } @@ -186,7 +183,7 @@ func TestActionsService_CreateHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -210,7 +207,6 @@ func TestActionsService_CreateHostedRunner(t *testing.T) { t.Errorf("Actions.CreateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -236,7 +232,7 @@ func TestActionsService_CreateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -616,7 +612,7 @@ func TestActionsService_GetHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -626,7 +622,6 @@ func TestActionsService_GetHostedRunner(t *testing.T) { t.Errorf("Actions.GetHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -652,7 +647,7 @@ func TestActionsService_GetHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -705,7 +700,7 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -722,7 +717,6 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) { t.Errorf("Actions.UpdateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -748,7 +742,7 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -801,7 +795,7 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -811,7 +805,6 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) { t.Errorf("Actions.DeleteHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -837,7 +830,7 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -1036,14 +1029,14 @@ func TestActionsService_ListHostedRunnerCustomImageVersions(t *testing.T) { "size_gb": 75, "state": "Ready", "state_details": "None", - "created_on": "2024-11-09T23:39:01Z" + "created_on": `+referenceTimeStr+` }, { "version": "1.0.0", "size_gb": 75, "state": "Ready", "state_details": "None", - "created_on": "2024-11-08T20:39:01Z" + "created_on": `+referenceTimeStr+` } ] }`) @@ -1063,14 +1056,14 @@ func TestActionsService_ListHostedRunnerCustomImageVersions(t *testing.T) { SizeGB: 75, State: "Ready", StateDetails: "None", - CreatedOn: Timestamp{time.Date(2024, 11, 9, 23, 39, 1, 0, time.UTC)}, + CreatedOn: referenceTimestamp, }, { Version: "1.0.0", SizeGB: 75, State: "Ready", StateDetails: "None", - CreatedOn: Timestamp{time.Date(2024, 11, 8, 20, 39, 1, 0, time.UTC)}, + CreatedOn: referenceTimestamp, }, }, } @@ -1105,7 +1098,7 @@ func TestActionsService_GetHostedRunnerCustomImageVersion(t *testing.T) { "size_gb": 75, "state": "Ready", "state_details": "None", - "created_on": "2024-11-08T20:39:01Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -1120,7 +1113,7 @@ func TestActionsService_GetHostedRunnerCustomImageVersion(t *testing.T) { SizeGB: 75, State: "Ready", StateDetails: "None", - CreatedOn: Timestamp{time.Date(2024, 11, 8, 20, 39, 1, 0, time.UTC)}, + CreatedOn: referenceTimestamp, } if !cmp.Equal(version, want) { diff --git a/github/actions_runner_groups_test.go b/github/actions_runner_groups_test.go index 21cedd6d759..51578b1ee20 100644 --- a/github/actions_runner_groups_test.go +++ b/github/actions_runner_groups_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -449,7 +448,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }, { "id": 7, @@ -470,7 +469,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { "maximum_runners": 20, "public_ip_enabled": false, "public_ips": [], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` } ] }`) @@ -483,8 +482,6 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { t.Errorf("Actions.ListRunnerGroupHostedRunners returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} - want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -513,7 +510,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, }, { ID: Ptr(int64(7)), @@ -534,7 +531,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, }, }, } diff --git a/github/actions_runners_test.go b/github/actions_runners_test.go index ec487410038..1c8e085f58d 100644 --- a/github/actions_runners_test.go +++ b/github/actions_runners_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -137,7 +136,7 @@ func TestActionsService_CreateRegistrationToken(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`) + fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":`+referenceTimeStr+`}`) }) ctx := t.Context() @@ -147,9 +146,8 @@ func TestActionsService_CreateRegistrationToken(t *testing.T) { } want := &RegistrationToken{ - Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), - ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35, - 123000000, time.UTC)}, + Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), + ExpiresAt: &referenceTimestamp, } if !cmp.Equal(token, want) { t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want) @@ -261,7 +259,7 @@ func TestActionsService_CreateRemoveToken(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`) + fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":`+referenceTimeStr+`}`) }) ctx := t.Context() @@ -270,7 +268,7 @@ func TestActionsService_CreateRemoveToken(t *testing.T) { t.Errorf("Actions.CreateRemoveToken returned error: %v", err) } - want := &RemoveToken{Token: Ptr("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}} + want := &RemoveToken{Token: Ptr("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &referenceTimestamp} if !cmp.Equal(token, want) { t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want) } @@ -362,7 +360,7 @@ func TestActionsService_CreateOrganizationRegistrationToken(t *testing.T) { mux.HandleFunc("/orgs/o/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`) + fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":`+referenceTimeStr+`}`) }) ctx := t.Context() @@ -372,9 +370,8 @@ func TestActionsService_CreateOrganizationRegistrationToken(t *testing.T) { } want := &RegistrationToken{ - Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), - ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35, - 123000000, time.UTC)}, + Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), + ExpiresAt: &referenceTimestamp, } if !cmp.Equal(token, want) { t.Errorf("Actions.CreateOrganizationRegistrationToken returned %+v, want %+v", token, want) @@ -486,7 +483,7 @@ func TestActionsService_CreateOrganizationRemoveToken(t *testing.T) { mux.HandleFunc("/orgs/o/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`) + fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":`+referenceTimeStr+`}`) }) ctx := t.Context() @@ -495,7 +492,7 @@ func TestActionsService_CreateOrganizationRemoveToken(t *testing.T) { t.Errorf("Actions.CreateOrganizationRemoveToken returned error: %v", err) } - want := &RemoveToken{Token: Ptr("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}} + want := &RemoveToken{Token: Ptr("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &referenceTimestamp} if !cmp.Equal(token, want) { t.Errorf("Actions.CreateOrganizationRemoveToken returned %+v, want %+v", token, want) } diff --git a/github/actions_secrets_test.go b/github/actions_secrets_test.go index 25411902e4c..776e1b301fb 100644 --- a/github/actions_secrets_test.go +++ b/github/actions_secrets_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -169,7 +168,7 @@ func TestActionsService_ListRepoSecrets(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -182,8 +181,8 @@ func TestActionsService_ListRepoSecrets(t *testing.T) { want := &Secrets{ TotalCount: 4, Secrets: []*Secret{ - {Name: "A", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001)}, + {Name: "B", CreatedAt: *refTimestamp(1136178002), UpdatedAt: *refTimestamp(1136178003)}, }, } if !cmp.Equal(secrets, want) { @@ -212,7 +211,7 @@ func TestActionsService_ListRepoOrgSecrets(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/organization-secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -225,8 +224,8 @@ func TestActionsService_ListRepoOrgSecrets(t *testing.T) { want := &Secrets{ TotalCount: 4, Secrets: []*Secret{ - {Name: "A", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001)}, + {Name: "B", CreatedAt: *refTimestamp(1136178002), UpdatedAt: *refTimestamp(1136178003)}, }, } if !cmp.Equal(secrets, want) { @@ -254,7 +253,7 @@ func TestActionsService_GetRepoSecret(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/secrets/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"NAME","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"NAME","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -265,8 +264,8 @@ func TestActionsService_GetRepoSecret(t *testing.T) { want := &Secret{ Name: "NAME", - CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: *refTimestamp(1136178000), + UpdatedAt: *refTimestamp(1136178001), } if !cmp.Equal(secret, want) { t.Errorf("Actions.GetRepoSecret returned %+v, want %+v", secret, want) @@ -396,7 +395,7 @@ func TestActionsService_ListOrgSecrets(t *testing.T) { mux.HandleFunc("/orgs/o/actions/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":3,"secrets":[{"name":"GIST_ID","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"private"},{"name":"DEPLOY_TOKEN","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"all"},{"name":"GH_TOKEN","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"}]}`) + fmt.Fprint(w, `{"total_count":3,"secrets":[{"name":"GIST_ID","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`,"visibility":"private"},{"name":"DEPLOY_TOKEN","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`,"visibility":"all"},{"name":"GH_TOKEN","created_at":`+refTimeStr(1136178004)+`,"updated_at":`+refTimeStr(1136178005)+`,"visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -409,9 +408,9 @@ func TestActionsService_ListOrgSecrets(t *testing.T) { want := &Secrets{ TotalCount: 3, Secrets: []*Secret{ - {Name: "GIST_ID", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "private"}, - {Name: "DEPLOY_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "all"}, - {Name: "GH_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"}, + {Name: "GIST_ID", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001), Visibility: "private"}, + {Name: "DEPLOY_TOKEN", CreatedAt: *refTimestamp(1136178002), UpdatedAt: *refTimestamp(1136178003), Visibility: "all"}, + {Name: "GH_TOKEN", CreatedAt: *refTimestamp(1136178004), UpdatedAt: *refTimestamp(1136178005), Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"}, }, } if !cmp.Equal(secrets, want) { @@ -439,7 +438,7 @@ func TestActionsService_GetOrgSecret(t *testing.T) { mux.HandleFunc("/orgs/o/actions/secrets/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"NAME","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z","visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"}`) + fmt.Fprint(w, `{"name":"NAME","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`,"visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"}`) }) ctx := t.Context() @@ -450,8 +449,8 @@ func TestActionsService_GetOrgSecret(t *testing.T) { want := &Secret{ Name: "NAME", - CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: *refTimestamp(1136178000), + UpdatedAt: *refTimestamp(1136178001), Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories", } @@ -756,7 +755,7 @@ func TestActionsService_ListEnvSecrets(t *testing.T) { mux.HandleFunc("/repositories/1/environments/e/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -769,8 +768,8 @@ func TestActionsService_ListEnvSecrets(t *testing.T) { want := &Secrets{ TotalCount: 4, Secrets: []*Secret{ - {Name: "A", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001)}, + {Name: "B", CreatedAt: *refTimestamp(1136178002), UpdatedAt: *refTimestamp(1136178003)}, }, } if !cmp.Equal(secrets, want) { @@ -798,7 +797,7 @@ func TestActionsService_GetEnvSecret(t *testing.T) { mux.HandleFunc("/repositories/1/environments/e/secrets/secret", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"secret","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"secret","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -809,8 +808,8 @@ func TestActionsService_GetEnvSecret(t *testing.T) { want := &Secret{ Name: "secret", - CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: *refTimestamp(1136178000), + UpdatedAt: *refTimestamp(1136178001), } if !cmp.Equal(secret, want) { t.Errorf("Actions.GetEnvSecret returned %+v, want %+v", secret, want) diff --git a/github/actions_variables_test.go b/github/actions_variables_test.go index 07a51bccfef..782494b3833 100644 --- a/github/actions_variables_test.go +++ b/github/actions_variables_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -21,7 +20,7 @@ func TestActionsService_ListRepoVariables(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/variables", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"variables":[{"name":"A","value":"AA","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","value":"BB","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"variables":[{"name":"A","value":"AA","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","value":"BB","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -34,8 +33,8 @@ func TestActionsService_ListRepoVariables(t *testing.T) { want := &ActionsVariables{ TotalCount: 4, Variables: []*ActionsVariable{ - {Name: "A", Value: "AA", CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", Value: "BB", CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", Value: "AA", CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001)}, + {Name: "B", Value: "BB", CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(variables, want) { @@ -64,7 +63,7 @@ func TestActionsService_ListRepoOrgVariables(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/organization-variables", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"variables":[{"name":"A","value":"AA","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","value":"BB","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"variables":[{"name":"A","value":"AA","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","value":"BB","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -77,8 +76,8 @@ func TestActionsService_ListRepoOrgVariables(t *testing.T) { want := &ActionsVariables{ TotalCount: 4, Variables: []*ActionsVariable{ - {Name: "A", Value: "AA", CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", Value: "BB", CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", Value: "AA", CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001)}, + {Name: "B", Value: "BB", CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(variables, want) { @@ -106,7 +105,7 @@ func TestActionsService_GetRepoVariable(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/variables/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"NAME","value":"VALUE","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"NAME","value":"VALUE","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -118,8 +117,8 @@ func TestActionsService_GetRepoVariable(t *testing.T) { want := &ActionsVariable{ Name: "NAME", Value: "VALUE", - CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(variable, want) { t.Errorf("Actions.GetRepoVariable returned %+v, want %+v", variable, want) @@ -242,7 +241,7 @@ func TestActionsService_ListOrgVariables(t *testing.T) { mux.HandleFunc("/orgs/o/actions/variables", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":3,"variables":[{"name":"A","value":"AA","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"private"},{"name":"B","value":"BB","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"all"},{"name":"C","value":"CC","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/variables/VAR/repositories"}]}`) + fmt.Fprint(w, `{"total_count":3,"variables":[{"name":"A","value":"AA","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`,"visibility":"private"},{"name":"B","value":"BB","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`,"visibility":"all"},{"name":"C","value":"CC","created_at":`+refTimeStr(1136178004)+`,"updated_at":`+refTimeStr(1136178005)+`,"visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/variables/VAR/repositories"}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -255,9 +254,9 @@ func TestActionsService_ListOrgVariables(t *testing.T) { want := &ActionsVariables{ TotalCount: 3, Variables: []*ActionsVariable{ - {Name: "A", Value: "AA", CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: Ptr("private")}, - {Name: "B", Value: "BB", CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: Ptr("all")}, - {Name: "C", Value: "CC", CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: Ptr("selected"), SelectedRepositoriesURL: Ptr("https://api.github.com/orgs/octo-org/actions/variables/VAR/repositories")}, + {Name: "A", Value: "AA", CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001), Visibility: Ptr("private")}, + {Name: "B", Value: "BB", CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003), Visibility: Ptr("all")}, + {Name: "C", Value: "CC", CreatedAt: refTimestamp(1136178004), UpdatedAt: refTimestamp(1136178005), Visibility: Ptr("selected"), SelectedRepositoriesURL: Ptr("https://api.github.com/orgs/octo-org/actions/variables/VAR/repositories")}, }, } if !cmp.Equal(variables, want) { @@ -285,7 +284,7 @@ func TestActionsService_GetOrgVariable(t *testing.T) { mux.HandleFunc("/orgs/o/actions/variables/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"NAME","value":"VALUE","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z","visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/variables/VAR/repositories"}`) + fmt.Fprint(w, `{"name":"NAME","value":"VALUE","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`,"visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/variables/VAR/repositories"}`) }) ctx := t.Context() @@ -297,8 +296,8 @@ func TestActionsService_GetOrgVariable(t *testing.T) { want := &ActionsVariable{ Name: "NAME", Value: "VALUE", - CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Visibility: Ptr("selected"), SelectedRepositoriesURL: Ptr("https://api.github.com/orgs/octo-org/actions/variables/VAR/repositories"), } @@ -569,7 +568,7 @@ func TestActionsService_ListEnvVariables(t *testing.T) { mux.HandleFunc("/repos/usr/1/environments/e/variables", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"variables":[{"name":"A","value":"AA","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","value":"BB","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"variables":[{"name":"A","value":"AA","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","value":"BB","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -582,8 +581,8 @@ func TestActionsService_ListEnvVariables(t *testing.T) { want := &ActionsVariables{ TotalCount: 4, Variables: []*ActionsVariable{ - {Name: "A", Value: "AA", CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", Value: "BB", CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", Value: "AA", CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001)}, + {Name: "B", Value: "BB", CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(variables, want) { @@ -611,7 +610,7 @@ func TestActionsService_GetEnvVariable(t *testing.T) { mux.HandleFunc("/repos/usr/1/environments/e/variables/variable", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"variable","value":"VAR","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"variable","value":"VAR","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -623,8 +622,8 @@ func TestActionsService_GetEnvVariable(t *testing.T) { want := &ActionsVariable{ Name: "variable", Value: "VAR", - CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(variable, want) { t.Errorf("Actions.GetEnvVariable returned %+v, want %+v", variable, want) diff --git a/github/actions_workflow_jobs_test.go b/github/actions_workflow_jobs_test.go index 83c969310b1..519fbd4ff55 100644 --- a/github/actions_workflow_jobs_test.go +++ b/github/actions_workflow_jobs_test.go @@ -12,7 +12,6 @@ import ( "net/url" "strings" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -24,7 +23,7 @@ func TestActionsService_ListWorkflowJobs(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runs/29679449/jobs", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":`+refTimeStr(1136178000)+`,"completed_at":`+refTimeStr(1136178001)+`},{"id":399444497,"run_id":29679449,"started_at":`+refTimeStr(1136178002)+`,"completed_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListWorkflowJobsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}} @@ -37,8 +36,8 @@ func TestActionsService_ListWorkflowJobs(t *testing.T) { want := &Jobs{ TotalCount: Ptr(4), Jobs: []*WorkflowJob{ - {ID: Ptr(int64(399444496)), RunID: Ptr(int64(29679449)), StartedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {ID: Ptr(int64(399444497)), RunID: Ptr(int64(29679449)), StartedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {ID: Ptr(int64(399444496)), RunID: Ptr(int64(29679449)), StartedAt: refTimestamp(1136178000), CompletedAt: refTimestamp(1136178001)}, + {ID: Ptr(int64(399444497)), RunID: Ptr(int64(29679449)), StartedAt: refTimestamp(1136178002), CompletedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(jobs, want) { @@ -67,7 +66,7 @@ func TestActionsService_ListWorkflowJobs_Filter(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runs/29679449/jobs", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"filter": "all", "per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":`+refTimeStr(1136178000)+`,"completed_at":`+refTimeStr(1136178001)+`},{"id":399444497,"run_id":29679449,"started_at":`+refTimeStr(1136178002)+`,"completed_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListWorkflowJobsOptions{Filter: "all", ListOptions: ListOptions{Page: 2, PerPage: 2}} @@ -80,8 +79,8 @@ func TestActionsService_ListWorkflowJobs_Filter(t *testing.T) { want := &Jobs{ TotalCount: Ptr(4), Jobs: []*WorkflowJob{ - {ID: Ptr(int64(399444496)), RunID: Ptr(int64(29679449)), StartedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {ID: Ptr(int64(399444497)), RunID: Ptr(int64(29679449)), StartedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {ID: Ptr(int64(399444496)), RunID: Ptr(int64(29679449)), StartedAt: refTimestamp(1136178000), CompletedAt: refTimestamp(1136178001)}, + {ID: Ptr(int64(399444497)), RunID: Ptr(int64(29679449)), StartedAt: refTimestamp(1136178002), CompletedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(jobs, want) { @@ -96,7 +95,7 @@ func TestActionsService_ListWorkflowJobsAttempt(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runs/29679449/attempts/1/jobs", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z","run_attempt":2},{"id":399444497,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z","run_attempt":2}]}`) + fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":`+refTimeStr(1136178000)+`,"completed_at":`+refTimeStr(1136178001)+`,"run_attempt":2},{"id":399444497,"run_id":29679449,"started_at":`+refTimeStr(1136178002)+`,"completed_at":`+refTimeStr(1136178003)+`,"run_attempt":2}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} ctx := t.Context() @@ -111,15 +110,15 @@ func TestActionsService_ListWorkflowJobsAttempt(t *testing.T) { { ID: Ptr(int64(399444496)), RunID: Ptr(int64(29679449)), - StartedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - CompletedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + StartedAt: refTimestamp(1136178000), + CompletedAt: refTimestamp(1136178001), RunAttempt: Ptr(int64(2)), }, { ID: Ptr(int64(399444497)), RunID: Ptr(int64(29679449)), - StartedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - CompletedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + StartedAt: refTimestamp(1136178002), + CompletedAt: refTimestamp(1136178003), RunAttempt: Ptr(int64(2)), }, }, @@ -149,7 +148,7 @@ func TestActionsService_GetWorkflowJobByID(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/jobs/399444496", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":399444496,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"id":399444496,"started_at":`+refTimeStr(1136178000)+`,"completed_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -160,8 +159,8 @@ func TestActionsService_GetWorkflowJobByID(t *testing.T) { want := &WorkflowJob{ ID: Ptr(int64(399444496)), - StartedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - CompletedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + StartedAt: refTimestamp(1136178000), + CompletedAt: refTimestamp(1136178001), } if !cmp.Equal(job, want) { t.Errorf("Actions.GetWorkflowJobByID returned %+v, want %+v", job, want) diff --git a/github/actions_workflow_runs_test.go b/github/actions_workflow_runs_test.go index d60bfe32a24..1731bd21b6c 100644 --- a/github/actions_workflow_runs_test.go +++ b/github/actions_workflow_runs_test.go @@ -12,7 +12,6 @@ import ( "net/url" "strings" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -24,7 +23,7 @@ func TestActionsService_ListWorkflowRunsByID(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/workflows/29679449/runs", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"id":399444497,"run_number":296,"created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}} @@ -37,8 +36,8 @@ func TestActionsService_ListWorkflowRunsByID(t *testing.T) { want := &WorkflowRuns{ TotalCount: Ptr(4), WorkflowRuns: []*WorkflowRun{ - {ID: Ptr(int64(399444496)), RunNumber: Ptr(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {ID: Ptr(int64(399444497)), RunNumber: Ptr(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {ID: Ptr(int64(399444496)), RunNumber: Ptr(296), CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001)}, + {ID: Ptr(int64(399444497)), RunNumber: Ptr(296), CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(runs, want) { @@ -67,7 +66,7 @@ func TestActionsService_ListWorkflowRunsFileName(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/workflows/29679449/runs", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"id":399444497,"run_number":296,"created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}} @@ -80,8 +79,8 @@ func TestActionsService_ListWorkflowRunsFileName(t *testing.T) { want := &WorkflowRuns{ TotalCount: Ptr(4), WorkflowRuns: []*WorkflowRun{ - {ID: Ptr(int64(399444496)), RunNumber: Ptr(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {ID: Ptr(int64(399444497)), RunNumber: Ptr(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {ID: Ptr(int64(399444496)), RunNumber: Ptr(296), CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001)}, + {ID: Ptr(int64(399444497)), RunNumber: Ptr(296), CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(runs, want) { @@ -109,7 +108,7 @@ func TestActionsService_GetWorkflowRunByID(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runs/29679449", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"id":399444496,"run_number":296,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -121,8 +120,8 @@ func TestActionsService_GetWorkflowRunByID(t *testing.T) { want := &WorkflowRun{ ID: Ptr(int64(399444496)), RunNumber: Ptr(296), - CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(runs, want) { @@ -151,7 +150,7 @@ func TestActionsService_GetWorkflowRunAttempt(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runs/29679449/attempts/3", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"exclude_pull_requests": "true"}) - fmt.Fprint(w, `{"id":399444496,"run_number":296,"run_attempt":3,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"id":399444496,"run_number":296,"run_attempt":3,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) opts := &WorkflowRunAttemptOptions{ExcludePullRequests: Ptr(true)} @@ -165,8 +164,8 @@ func TestActionsService_GetWorkflowRunAttempt(t *testing.T) { ID: Ptr(int64(399444496)), RunNumber: Ptr(296), RunAttempt: Ptr(3), - CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(runs, want) { @@ -703,8 +702,8 @@ func TestActionsService_ListRepositoryWorkflowRuns(t *testing.T) { testFormValues(t, r, values{"per_page": "2", "page": "2"}) fmt.Fprint(w, `{"total_count":2, "workflow_runs":[ - {"id":298499444,"run_number":301,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"}, - {"id":298499445,"run_number":302,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"}]}`) + {"id":298499444,"run_number":301,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}, + {"id":298499445,"run_number":302,"created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}} @@ -717,8 +716,8 @@ func TestActionsService_ListRepositoryWorkflowRuns(t *testing.T) { expected := &WorkflowRuns{ TotalCount: Ptr(2), WorkflowRuns: []*WorkflowRun{ - {ID: Ptr(int64(298499444)), RunNumber: Ptr(301), CreatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}}, - {ID: Ptr(int64(298499445)), RunNumber: Ptr(302), CreatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}}, + {ID: Ptr(int64(298499444)), RunNumber: Ptr(301), CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001)}, + {ID: Ptr(int64(298499445)), RunNumber: Ptr(302), CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003)}, }, } @@ -949,7 +948,7 @@ func TestActionsService_GetPendingDeployments(t *testing.T) { "html_url": "hu" }, "wait_timer": 0, - "wait_timer_started_at": `+referenceTimeStr+`, + "wait_timer_started_at": `+refTimeStr(1136178000)+`, "current_user_can_approve": false, "reviewers": [] }, @@ -962,7 +961,7 @@ func TestActionsService_GetPendingDeployments(t *testing.T) { "html_url": "hu" }, "wait_timer": 13, - "wait_timer_started_at": `+referenceTimeStr+`, + "wait_timer_started_at": `+refTimeStr(1136178001)+`, "current_user_can_approve": true, "reviewers": [ { @@ -999,7 +998,7 @@ func TestActionsService_GetPendingDeployments(t *testing.T) { HTMLURL: Ptr("hu"), }, WaitTimer: Ptr(int64(0)), - WaitTimerStartedAt: &Timestamp{referenceTime}, + WaitTimerStartedAt: refTimestamp(1136178000), CurrentUserCanApprove: Ptr(false), Reviewers: []*RequiredReviewer{}, }, @@ -1012,7 +1011,7 @@ func TestActionsService_GetPendingDeployments(t *testing.T) { HTMLURL: Ptr("hu"), }, WaitTimer: Ptr(int64(13)), - WaitTimerStartedAt: &Timestamp{referenceTime}, + WaitTimerStartedAt: refTimestamp(1136178001), CurrentUserCanApprove: Ptr(true), Reviewers: []*RequiredReviewer{ { diff --git a/github/actions_workflows_test.go b/github/actions_workflows_test.go index c69c78f7274..a1c9ca728b1 100644 --- a/github/actions_workflows_test.go +++ b/github/actions_workflows_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -21,7 +20,7 @@ func TestActionsService_ListWorkflows(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/workflows", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"workflows":[{"id":72844,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"id":72845,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"workflows":[{"id":72844,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"id":72845,"created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -34,8 +33,8 @@ func TestActionsService_ListWorkflows(t *testing.T) { want := &Workflows{ TotalCount: Ptr(4), Workflows: []*Workflow{ - {ID: Ptr(int64(72844)), CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {ID: Ptr(int64(72845)), CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {ID: Ptr(int64(72844)), CreatedAt: refTimestamp(1136178000), UpdatedAt: refTimestamp(1136178001)}, + {ID: Ptr(int64(72845)), CreatedAt: refTimestamp(1136178002), UpdatedAt: refTimestamp(1136178003)}, }, } if !cmp.Equal(workflows, want) { @@ -63,7 +62,7 @@ func TestActionsService_GetWorkflowByID(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/workflows/72844", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":72844,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"id":72844,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -74,8 +73,8 @@ func TestActionsService_GetWorkflowByID(t *testing.T) { want := &Workflow{ ID: Ptr(int64(72844)), - CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(workflow, want) { t.Errorf("Actions.GetWorkflowByID returned %+v, want %+v", workflow, want) @@ -102,7 +101,7 @@ func TestActionsService_GetWorkflowByFileName(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/workflows/main.yml", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":72844,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"id":72844,"created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -113,8 +112,8 @@ func TestActionsService_GetWorkflowByFileName(t *testing.T) { want := &Workflow{ ID: Ptr(int64(72844)), - CreatedAt: &Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(workflow, want) { t.Errorf("Actions.GetWorkflowByFileName returned %+v, want %+v", workflow, want) diff --git a/github/activity_notifications_test.go b/github/activity_notifications_test.go index af7c6c38b1d..ef91f0b4303 100644 --- a/github/activity_notifications_test.go +++ b/github/activity_notifications_test.go @@ -23,7 +23,7 @@ func TestActivityService_ListNotification(t *testing.T) { testFormValues(t, r, values{ "all": "true", "participating": "true", - "since": "2006-01-02T15:04:05Z", + "since": referenceTimeRaw, "before": "2007-03-04T15:04:05Z", }) @@ -33,7 +33,7 @@ func TestActivityService_ListNotification(t *testing.T) { opt := &NotificationListOptions{ All: true, Participating: true, - Since: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC), + Since: referenceTime, Before: time.Date(2007, time.March, 4, 15, 4, 5, 0, time.UTC), } ctx := t.Context() @@ -96,13 +96,11 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := Timestamp{time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)} - mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Content-Type", "application/json") want := markReadOptions{ - LastReadAt: input, + LastReadAt: referenceTimestamp, } testJSONBody(t, r, want) @@ -110,14 +108,14 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) { }) ctx := t.Context() - _, err := client.Activity.MarkNotificationsRead(ctx, input) + _, err := client.Activity.MarkNotificationsRead(ctx, referenceTimestamp) if err != nil { t.Errorf("Activity.MarkNotificationsRead returned error: %v", err) } const methodName = "MarkNotificationsRead" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Activity.MarkNotificationsRead(ctx, input) + return client.Activity.MarkNotificationsRead(ctx, referenceTimestamp) }) } @@ -125,13 +123,11 @@ func TestActivityService_MarkNotificationsRead_EmptyLastReadAt(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := Timestamp{} - mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Content-Type", "application/json") want := markReadOptions{ - LastReadAt: input, + LastReadAt: referenceTimestamp, } testJSONBody(t, r, want) @@ -139,7 +135,7 @@ func TestActivityService_MarkNotificationsRead_EmptyLastReadAt(t *testing.T) { }) ctx := t.Context() - _, err := client.Activity.MarkNotificationsRead(ctx, input) + _, err := client.Activity.MarkNotificationsRead(ctx, referenceTimestamp) if err != nil { t.Errorf("Activity.MarkNotificationsRead returned error: %v", err) } @@ -149,32 +145,30 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := Timestamp{time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)} - mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Content-Type", "application/json") want := markReadOptions{ - LastReadAt: input, + LastReadAt: referenceTimestamp, } testJSONBody(t, r, want) w.WriteHeader(http.StatusResetContent) }) ctx := t.Context() - _, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", input) + _, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", referenceTimestamp) if err != nil { t.Errorf("Activity.MarkRepositoryNotificationsRead returned error: %v", err) } const methodName = "MarkRepositoryNotificationsRead" testBadOptions(t, methodName, func() (err error) { - _, err = client.Activity.MarkRepositoryNotificationsRead(ctx, "\n", "\n", input) + _, err = client.Activity.MarkRepositoryNotificationsRead(ctx, "\n", "\n", referenceTimestamp) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", input) + return client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", referenceTimestamp) }) } @@ -182,13 +176,11 @@ func TestActivityService_MarkRepositoryNotificationsRead_EmptyLastReadAt(t *test t.Parallel() client, mux, _ := setup(t) - input := Timestamp{} - mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Content-Type", "application/json") want := markReadOptions{ - LastReadAt: input, + LastReadAt: referenceTimestamp, } testJSONBody(t, r, want) @@ -196,7 +188,7 @@ func TestActivityService_MarkRepositoryNotificationsRead_EmptyLastReadAt(t *test }) ctx := t.Context() - _, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", input) + _, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", referenceTimestamp) if err != nil { t.Errorf("Activity.MarkRepositoryNotificationsRead returned error: %v", err) } diff --git a/github/activity_star_test.go b/github/activity_star_test.go index 7ebf1b1c8d6..6286a166772 100644 --- a/github/activity_star_test.go +++ b/github/activity_star_test.go @@ -10,7 +10,6 @@ import ( "net/http" "strings" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -26,7 +25,7 @@ func TestActivityService_ListStargazers(t *testing.T) { "page": "2", }) - fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","user":{"id":1}}]`) + fmt.Fprint(w, `[{"starred_at":`+referenceTimeStr+`,"user":{"id":1}}]`) }) ctx := t.Context() @@ -35,7 +34,7 @@ func TestActivityService_ListStargazers(t *testing.T) { t.Errorf("Activity.ListStargazers returned error: %v", err) } - want := []*Stargazer{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, User: &User{ID: Ptr(int64(1))}}} + want := []*Stargazer{{StarredAt: &referenceTimestamp, User: &User{ID: Ptr(int64(1))}}} if !cmp.Equal(stargazers, want) { t.Errorf("Activity.ListStargazers returned %+v, want %+v", stargazers, want) } @@ -62,7 +61,7 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { mux.HandleFunc("/user/starred", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", strings.Join([]string{mediaTypeStarring, mediaTypeTopicsPreview}, ", ")) - fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","repo":{"id":1}}]`) + fmt.Fprint(w, `[{"starred_at":`+referenceTimeStr+`,"repo":{"id":1}}]`) }) ctx := t.Context() @@ -71,7 +70,7 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { t.Errorf("Activity.ListStarred returned error: %v", err) } - want := []*StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Ptr(int64(1))}}} + want := []*StarredRepository{{StarredAt: &referenceTimestamp, Repository: &Repository{ID: Ptr(int64(1))}}} if !cmp.Equal(repos, want) { t.Errorf("Activity.ListStarred returned %+v, want %+v", repos, want) } @@ -103,7 +102,7 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) { "direction": "asc", "page": "2", }) - fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","repo":{"id":2}}]`) + fmt.Fprint(w, `[{"starred_at":`+referenceTimeStr+`,"repo":{"id":2}}]`) }) opt := &ActivityListStarredOptions{"created", "asc", ListOptions{Page: 2}} @@ -113,7 +112,7 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) { t.Errorf("Activity.ListStarred returned error: %v", err) } - want := []*StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Ptr(int64(2))}}} + want := []*StarredRepository{{StarredAt: &referenceTimestamp, Repository: &Repository{ID: Ptr(int64(2))}}} if !cmp.Equal(repos, want) { t.Errorf("Activity.ListStarred returned %+v, want %+v", repos, want) } diff --git a/github/admin_users_test.go b/github/admin_users_test.go index 1cfd7f40f52..bf462a8b2de 100644 --- a/github/admin_users_test.go +++ b/github/admin_users_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -93,8 +92,8 @@ func TestUserImpersonation_Create(t *testing.T) { "token_last_eight": "1234", "note": null, "note_url": null, - "created_at": "2018-01-01T00:00:00Z", - "updated_at": "2018-01-01T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "scopes": [ "repo" ], @@ -107,7 +106,6 @@ func TestUserImpersonation_Create(t *testing.T) { t.Errorf("Admin.CreateUserImpersonation returned error: %v", err) } - date := Timestamp{Time: time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} want := &UserAuthorization{ ID: Ptr(int64(1234)), URL: Ptr("https://example.com/authorizations"), @@ -121,8 +119,8 @@ func TestUserImpersonation_Create(t *testing.T) { TokenLastEight: Ptr("1234"), Note: nil, NoteURL: nil, - CreatedAt: &date, - UpdatedAt: &date, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Scopes: []string{"repo"}, Fingerprint: nil, } diff --git a/github/apps_test.go b/github/apps_test.go index 55c9b2bd00c..d936a4f3aac 100644 --- a/github/apps_test.go +++ b/github/apps_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -84,7 +83,7 @@ func TestAppsService_ListInstallationRequests(t *testing.T) { "id": 1, "account": { "id": 2 }, "requester": { "id": 3 }, - "created_at": "2018-01-01T00:00:00Z" + "created_at": `+referenceTimeStr+` }]`, ) }) @@ -96,12 +95,11 @@ func TestAppsService_ListInstallationRequests(t *testing.T) { t.Errorf("Apps.ListInstallationRequests returned error: %v", err) } - date := Timestamp{Time: time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} want := []*InstallationRequest{{ ID: Ptr(int64(1)), Account: &User{ID: Ptr(int64(2))}, Requester: &User{ID: Ptr(int64(3))}, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, }} if !cmp.Equal(installationRequests, want) { t.Errorf("Apps.ListInstallationRequests returned %+v, want %+v", installationRequests, want) @@ -176,8 +174,8 @@ func TestAppsService_ListInstallations(t *testing.T) { ], "single_file_name": "config.yml", "repository_selection": "selected", - "created_at": "2018-01-01T00:00:00Z", - "updated_at": "2018-01-01T00:00:00Z"}]`, + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`}]`, ) }) @@ -188,7 +186,6 @@ func TestAppsService_ListInstallations(t *testing.T) { t.Errorf("Apps.ListInstallations returned error: %v", err) } - date := Timestamp{Time: time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} want := []*Installation{{ ID: Ptr(int64(1)), AppID: Ptr(int64(1)), @@ -235,8 +232,8 @@ func TestAppsService_ListInstallations(t *testing.T) { Workflows: Ptr("write"), }, Events: []string{"push", "pull_request"}, - CreatedAt: &date, - UpdatedAt: &date, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), }} if !cmp.Equal(installations, want) { t.Errorf("Apps.ListInstallations returned %+v, want %+v", installations, want) diff --git a/github/classroom_test.go b/github/classroom_test.go index cd96676f127..9cc64b98946 100644 --- a/github/classroom_test.go +++ b/github/classroom_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -37,7 +36,7 @@ func TestClassroomService_GetAssignment(t *testing.T) { "submitted": 40, "passing": 10, "language": "ruby", - "deadline": "2011-01-26T19:06:43Z", + "deadline": `+referenceTimeStr+`, "starter_code_repository": { "id": 1296269, "full_name": "octocat/Hello-World", @@ -78,7 +77,7 @@ func TestClassroomService_GetAssignment(t *testing.T) { Submitted: Ptr(40), Passing: Ptr(10), Language: Ptr("ruby"), - Deadline: func() *Timestamp { t, _ := time.Parse(time.RFC3339, "2011-01-26T19:06:43Z"); return &Timestamp{t} }(), + Deadline: &referenceTimestamp, StarterCodeRepository: &Repository{ ID: Ptr(int64(1296269)), FullName: Ptr("octocat/Hello-World"), @@ -260,7 +259,7 @@ func TestClassroomService_ListClassroomAssignments(t *testing.T) { "submitted": 40, "passing": 10, "language": "ruby", - "deadline": "2011-01-26T19:06:43Z", + "deadline": `+referenceTimeStr+`, "classroom": { "id": 1296269, "name": "Programming Elixir", @@ -285,7 +284,7 @@ func TestClassroomService_ListClassroomAssignments(t *testing.T) { "submitted": 25, "passing": 20, "language": "python", - "deadline": "2020-01-11T11:59:22Z", + "deadline": `+referenceTimeStr+`, "classroom": { "id": 1296269, "name": "Programming Elixir", @@ -321,7 +320,7 @@ func TestClassroomService_ListClassroomAssignments(t *testing.T) { Submitted: Ptr(40), Passing: Ptr(10), Language: Ptr("ruby"), - Deadline: func() *Timestamp { t, _ := time.Parse(time.RFC3339, "2011-01-26T19:06:43Z"); return &Timestamp{t} }(), + Deadline: &referenceTimestamp, Classroom: &Classroom{ ID: Ptr(int64(1296269)), Name: Ptr("Programming Elixir"), @@ -346,7 +345,7 @@ func TestClassroomService_ListClassroomAssignments(t *testing.T) { Submitted: Ptr(25), Passing: Ptr(20), Language: Ptr("python"), - Deadline: func() *Timestamp { t, _ := time.Parse(time.RFC3339, "2020-01-11T11:59:22Z"); return &Timestamp{t} }(), + Deadline: &referenceTimestamp, Classroom: &Classroom{ ID: Ptr(int64(1296269)), Name: Ptr("Programming Elixir"), @@ -422,7 +421,7 @@ func TestClassroomService_ListAcceptedAssignments(t *testing.T) { "submitted": 40, "passing": 10, "language": "ruby", - "deadline": "2011-01-26T19:06:43Z", + "deadline": `+referenceTimeStr+`, "classroom": { "id": 1296269, "name": "Programming Elixir", @@ -470,7 +469,7 @@ func TestClassroomService_ListAcceptedAssignments(t *testing.T) { "submitted": 40, "passing": 10, "language": "ruby", - "deadline": "2011-01-26T19:06:43Z", + "deadline": `+referenceTimeStr+`, "classroom": { "id": 1296269, "name": "Programming Elixir", @@ -529,7 +528,7 @@ func TestClassroomService_ListAcceptedAssignments(t *testing.T) { Submitted: Ptr(40), Passing: Ptr(10), Language: Ptr("ruby"), - Deadline: &Timestamp{time.Date(2011, 1, 26, 19, 6, 43, 0, time.UTC)}, + Deadline: &referenceTimestamp, Classroom: &Classroom{ ID: Ptr(int64(1296269)), Name: Ptr("Programming Elixir"), @@ -577,7 +576,7 @@ func TestClassroomService_ListAcceptedAssignments(t *testing.T) { Submitted: Ptr(40), Passing: Ptr(10), Language: Ptr("ruby"), - Deadline: &Timestamp{time.Date(2011, 1, 26, 19, 6, 43, 0, time.UTC)}, + Deadline: &referenceTimestamp, Classroom: &Classroom{ ID: Ptr(int64(1296269)), Name: Ptr("Programming Elixir"), @@ -622,7 +621,7 @@ func TestClassroomService_GetAssignmentGrades(t *testing.T) { "roster_identifier": "student123", "student_repository_name": "octocat/intro-to-binaries", "student_repository_url": "https://github.com/octocat/intro-to-binaries", - "submission_timestamp": "2011-01-26T19:06:43Z", + "submission_timestamp": `+referenceTimeStr+`, "points_awarded": 10, "points_available": 10, "group_name": "Team Alpha" @@ -635,7 +634,7 @@ func TestClassroomService_GetAssignmentGrades(t *testing.T) { "roster_identifier": "student456", "student_repository_name": "monalisa/intro-to-binaries", "student_repository_url": "https://github.com/monalisa/intro-to-binaries", - "submission_timestamp": "2011-01-27T10:30:15Z", + "submission_timestamp": `+referenceTimeStr+`, "points_awarded": 8, "points_available": 10, "group_name": "Team Beta" @@ -658,7 +657,7 @@ func TestClassroomService_GetAssignmentGrades(t *testing.T) { RosterIdentifier: Ptr("student123"), StudentRepositoryName: Ptr("octocat/intro-to-binaries"), StudentRepositoryURL: Ptr("https://github.com/octocat/intro-to-binaries"), - SubmissionTimestamp: &Timestamp{time.Date(2011, 1, 26, 19, 6, 43, 0, time.UTC)}, + SubmissionTimestamp: &referenceTimestamp, PointsAwarded: Ptr(10), PointsAvailable: Ptr(10), GroupName: Ptr("Team Alpha"), @@ -671,7 +670,7 @@ func TestClassroomService_GetAssignmentGrades(t *testing.T) { RosterIdentifier: Ptr("student456"), StudentRepositoryName: Ptr("monalisa/intro-to-binaries"), StudentRepositoryURL: Ptr("https://github.com/monalisa/intro-to-binaries"), - SubmissionTimestamp: &Timestamp{time.Date(2011, 1, 27, 10, 30, 15, 0, time.UTC)}, + SubmissionTimestamp: &referenceTimestamp, PointsAwarded: Ptr(8), PointsAvailable: Ptr(10), GroupName: Ptr("Team Beta"), diff --git a/github/code_quality_test.go b/github/code_quality_test.go index e7df70b3ef5..b6f7e9c6562 100644 --- a/github/code_quality_test.go +++ b/github/code_quality_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -25,7 +24,7 @@ func TestCodeQualityService_GetSetup(t *testing.T) { "languages": ["javascript-typescript", "python"], "runner_type": "standard", "runner_label": null, - "updated_at": "2026-01-01T00:00:00Z", + "updated_at": `+referenceTimeStr+`, "schedule": "weekly" }`) }) @@ -40,7 +39,7 @@ func TestCodeQualityService_GetSetup(t *testing.T) { State: Ptr("configured"), Languages: []string{"javascript-typescript", "python"}, RunnerType: Ptr("standard"), - UpdatedAt: &Timestamp{time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC)}, + UpdatedAt: &referenceTimestamp, Schedule: Ptr("weekly"), } if diff := cmp.Diff(want, cfg); diff != "" { diff --git a/github/code_scanning_test.go b/github/code_scanning_test.go index d3ec8670f6b..785cec746ba 100644 --- a/github/code_scanning_test.go +++ b/github/code_scanning_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -63,7 +62,7 @@ func TestCodeScanningService_UploadSarif(t *testing.T) { URL: Ptr("https://example.com/testurl"), } - sarifAnalysis := &SarifAnalysis{CommitSHA: Ptr("abc"), Ref: Ptr("ref/head/main"), Sarif: Ptr("abc"), CheckoutURI: Ptr("uri"), StartedAt: &Timestamp{time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)}, ToolName: Ptr("codeql-cli")} + sarifAnalysis := &SarifAnalysis{CommitSHA: Ptr("abc"), Ref: Ptr("ref/head/main"), Sarif: Ptr("abc"), CheckoutURI: Ptr("uri"), StartedAt: &referenceTimestamp, ToolName: Ptr("codeql-cli")} mux.HandleFunc("/repos/o/r/code-scanning/sarifs", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -182,7 +181,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) { "test" ] }, - "created_at":"2020-05-06T12:00:00Z", + "created_at":`+referenceTimeStr+`, "state":"open", "closed_by":null, "closed_at":null, @@ -224,7 +223,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) { "test" ] }, - "created_at":"2020-05-06T12:00:00Z", + "created_at":`+referenceTimeStr+`, "state":"open", "closed_by":null, "closed_at":null, @@ -240,7 +239,6 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) { t.Errorf("CodeScanning.ListAlertsForOrg returned error: %v", err) } - date := Timestamp{time.Date(2020, time.May, 6, 12, 0, 0, 0, time.UTC)} want := []*Alert{ { Repository: &Repository{ @@ -260,7 +258,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) { FullDescription: Ptr("Expression has no effect"), Help: Ptr("Expression has no effect"), }, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, State: Ptr("open"), ClosedBy: nil, ClosedAt: nil, @@ -296,7 +294,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) { FullDescription: Ptr("Expression has no effect"), Help: Ptr("Expression has no effect"), }, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, State: Ptr("open"), ClosedBy: nil, ClosedAt: nil, @@ -386,7 +384,7 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) { "test" ] }, - "created_at":"2020-05-06T12:00:00Z", + "created_at":`+referenceTimeStr+`, "state":"open", "closed_by":null, "closed_at":null, @@ -402,7 +400,6 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) { t.Errorf("CodeScanning.ListAlertsForOrg returned error: %v", err) } - date := Timestamp{time.Date(2020, time.May, 6, 12, 0, 0, 0, time.UTC)} want := []*Alert{ { Repository: &Repository{ @@ -422,7 +419,7 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) { FullDescription: Ptr("Expression has no effect"), Help: Ptr("Expression has no effect"), }, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, State: Ptr("open"), ClosedBy: nil, ClosedAt: nil, @@ -507,7 +504,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) { "test" ] }, - "created_at":"2020-05-06T12:00:00Z", + "created_at":`+referenceTimeStr+`, "state":"open", "closed_by":null, "closed_at":null, @@ -549,7 +546,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) { "test" ] }, - "created_at":"2020-05-06T12:00:00Z", + "created_at":`+referenceTimeStr+`, "state":"open", "closed_by":null, "closed_at":null, @@ -565,7 +562,6 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) { t.Errorf("CodeScanning.ListAlertsForRepo returned error: %v", err) } - date := Timestamp{time.Date(2020, time.May, 6, 12, 0, 0, 0, time.UTC)} want := []*Alert{ { RuleID: Ptr("js/trivial-conditional"), @@ -580,7 +576,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) { FullDescription: Ptr("Expression has no effect"), Help: Ptr("Expression has no effect"), }, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, State: Ptr("open"), ClosedBy: nil, ClosedAt: nil, @@ -616,7 +612,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) { FullDescription: Ptr("Expression has no effect"), Help: Ptr("Expression has no effect"), }, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, State: Ptr("open"), ClosedBy: nil, ClosedAt: nil, @@ -699,7 +695,7 @@ func TestCodeScanningService_UpdateAlert(t *testing.T) { "test" ] }, - "created_at":"2019-01-02T15:04:05Z", + "created_at":`+referenceTimeStr+`, "state":"dismissed", "dismissed_reason": "false positive", "dismissed_comment": "This alert is not actually correct as sanitizer is used", @@ -719,7 +715,6 @@ func TestCodeScanningService_UpdateAlert(t *testing.T) { t.Errorf("CodeScanning.UpdateAlert returned error: %v", err) } - date := Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)} want := &Alert{ RuleID: Ptr("js/useless-expression"), RuleSeverity: Ptr("warning"), @@ -733,7 +728,7 @@ func TestCodeScanningService_UpdateAlert(t *testing.T) { FullDescription: Ptr("Expression has no effect"), Help: Ptr("Expression has no effect"), }, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, State: state, DismissedReason: dismissedReason, DismissedComment: dismissedComment, @@ -897,7 +892,7 @@ func TestCodeScanningService_GetAlert(t *testing.T) { "test" ] }, - "created_at":"2019-01-02T15:04:05Z", + "created_at":`+referenceTimeStr+`, "state":"open", "closed_by":null, "closed_at":null, @@ -912,7 +907,6 @@ func TestCodeScanningService_GetAlert(t *testing.T) { t.Errorf("CodeScanning.GetAlert returned error: %v", err) } - date := Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)} want := &Alert{ RuleID: Ptr("js/useless-expression"), RuleSeverity: Ptr("warning"), @@ -926,7 +920,7 @@ func TestCodeScanningService_GetAlert(t *testing.T) { FullDescription: Ptr("Expression has no effect"), Help: Ptr("Expression has no effect"), }, - CreatedAt: &date, + CreatedAt: &referenceTimestamp, State: Ptr("open"), ClosedBy: nil, ClosedAt: nil, @@ -983,7 +977,7 @@ func TestCodeScanningService_ListAnalysesForRepo(t *testing.T) { "environment": "{\"language\":\"python\"}", "error": "", "category": ".github/workflows/codeql-analysis.yml:analyze/language:python", - "created_at": "2020-08-27T15:05:21Z", + "created_at": `+referenceTimeStr+`, "results_count": 17, "rules_count": 49, "id": 201, @@ -1004,7 +998,7 @@ func TestCodeScanningService_ListAnalysesForRepo(t *testing.T) { "environment": "{}", "error": "", "category": ".github/workflows/shiftleft.yml:build/", - "created_at": "2020-08-27T15:05:21Z", + "created_at": `+referenceTimeStr+`, "results_count": 17, "rules_count": 32, "id": 200, @@ -1028,7 +1022,6 @@ func TestCodeScanningService_ListAnalysesForRepo(t *testing.T) { t.Errorf("CodeScanning.ListAnalysesForRepo returned error: %v", err) } - date := &Timestamp{time.Date(2020, time.August, 27, 15, 5, 21, 0, time.UTC)} want := []*ScanningAnalysis{ { ID: Ptr(int64(201)), @@ -1038,7 +1031,7 @@ func TestCodeScanningService_ListAnalysesForRepo(t *testing.T) { Environment: Ptr("{\"language\":\"python\"}"), Error: Ptr(""), Category: Ptr(".github/workflows/codeql-analysis.yml:analyze/language:python"), - CreatedAt: date, + CreatedAt: &referenceTimestamp, ResultsCount: Ptr(17), RulesCount: Ptr(49), URL: Ptr("https://api.github.com/repos/o/r/code-scanning/analyses/201"), @@ -1059,7 +1052,7 @@ func TestCodeScanningService_ListAnalysesForRepo(t *testing.T) { Environment: Ptr("{}"), Error: Ptr(""), Category: Ptr(".github/workflows/shiftleft.yml:build/"), - CreatedAt: date, + CreatedAt: &referenceTimestamp, ResultsCount: Ptr(17), RulesCount: Ptr(32), URL: Ptr("https://api.github.com/repos/o/r/code-scanning/analyses/200"), @@ -1105,7 +1098,7 @@ func TestCodeScanningService_GetAnalysis(t *testing.T) { "environment": "{\"language\":\"javascript\"}", "error": "", "category": ".github/workflows/codeql-analysis.yml:analyze/language:javascript", - "created_at": "2021-01-13T11:55:49Z", + "created_at": `+referenceTimeStr+`, "results_count": 3, "rules_count": 67, "id": 3602840, @@ -1127,7 +1120,6 @@ func TestCodeScanningService_GetAnalysis(t *testing.T) { t.Errorf("CodeScanning.GetAnalysis returned error: %v", err) } - date := &Timestamp{time.Date(2021, time.January, 13, 11, 55, 49, 0, time.UTC)} want := &ScanningAnalysis{ ID: Ptr(int64(3602840)), Ref: Ptr("refs/heads/main"), @@ -1136,7 +1128,7 @@ func TestCodeScanningService_GetAnalysis(t *testing.T) { Environment: Ptr("{\"language\":\"javascript\"}"), Error: Ptr(""), Category: Ptr(".github/workflows/codeql-analysis.yml:analyze/language:javascript"), - CreatedAt: date, + CreatedAt: &referenceTimestamp, ResultsCount: Ptr(3), RulesCount: Ptr(67), URL: Ptr("https://api.github.com/repos/o/r/code-scanning/analyses/201"), @@ -1242,8 +1234,8 @@ func TestCodeScanningService_ListCodeQLDatabases(t *testing.T) { }, "content_type": "r", "size": 1024, - "created_at": "2021-01-13T11:55:49Z", - "updated_at": "2021-01-13T11:55:49Z", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "url": "s" } ]`) @@ -1255,7 +1247,6 @@ func TestCodeScanningService_ListCodeQLDatabases(t *testing.T) { t.Errorf("CodeScanning.ListCodeQLDatabases returned error: %v", err) } - date := &Timestamp{time.Date(2021, time.January, 13, 11, 55, 49, 0, time.UTC)} want := []*CodeQLDatabase{ { ID: Ptr(int64(1)), @@ -1283,8 +1274,8 @@ func TestCodeScanningService_ListCodeQLDatabases(t *testing.T) { }, ContentType: Ptr("r"), Size: Ptr(int64(1024)), - CreatedAt: date, - UpdatedAt: date, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), URL: Ptr("s"), }, } @@ -1340,8 +1331,8 @@ func TestCodeScanningService_GetCodeQLDatabase(t *testing.T) { }, "content_type": "r", "size": 1024, - "created_at": "2021-01-13T11:55:49Z", - "updated_at": "2021-01-13T11:55:49Z", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "url": "s" }`) }) @@ -1352,7 +1343,6 @@ func TestCodeScanningService_GetCodeQLDatabase(t *testing.T) { t.Errorf("CodeScanning.GetCodeQLDatabase returned error: %v", err) } - date := &Timestamp{time.Date(2021, time.January, 13, 11, 55, 49, 0, time.UTC)} want := &CodeQLDatabase{ ID: Ptr(int64(1)), Name: Ptr("name"), @@ -1379,8 +1369,8 @@ func TestCodeScanningService_GetCodeQLDatabase(t *testing.T) { }, ContentType: Ptr("r"), Size: Ptr(int64(1024)), - CreatedAt: date, - UpdatedAt: date, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), URL: Ptr("s"), } @@ -1417,7 +1407,7 @@ func TestCodeScanningService_GetDefaultSetupConfiguration(t *testing.T) { "typescript" ], "query_suite": "default", - "updated_at": "2006-01-02T15:04:05Z" + "updated_at": `+referenceTimeStr+` }`) if err != nil { t.Fatal(err) @@ -1430,12 +1420,11 @@ func TestCodeScanningService_GetDefaultSetupConfiguration(t *testing.T) { t.Errorf("CodeScanning.GetDefaultSetupConfiguration returned error: %v", err) } - date := &Timestamp{time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)} want := &DefaultSetupConfiguration{ State: Ptr("configured"), Languages: []string{"javascript", "javascript-typescript", "typescript"}, QuerySuite: Ptr("default"), - UpdatedAt: date, + UpdatedAt: &referenceTimestamp, } if !cmp.Equal(cfg, want) { t.Errorf("CodeScanning.GetDefaultSetupConfiguration returned %+v, want %+v", cfg, want) diff --git a/github/codespaces_secrets_test.go b/github/codespaces_secrets_test.go index a74dc77710a..d495b7003d5 100644 --- a/github/codespaces_secrets_test.go +++ b/github/codespaces_secrets_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -32,7 +31,7 @@ func TestCodespacesService_ListSecrets(t *testing.T) { mux.HandleFunc("/user/codespaces/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) }, call: func(ctx context.Context, client *Client) (*Secrets, *Response, error) { @@ -46,7 +45,7 @@ func TestCodespacesService_ListSecrets(t *testing.T) { mux.HandleFunc("/orgs/o/codespaces/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) }, call: func(ctx context.Context, client *Client) (*Secrets, *Response, error) { @@ -63,7 +62,7 @@ func TestCodespacesService_ListSecrets(t *testing.T) { mux.HandleFunc("/repos/o/r/codespaces/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) }, call: func(ctx context.Context, client *Client) (*Secrets, *Response, error) { @@ -92,8 +91,8 @@ func TestCodespacesService_ListSecrets(t *testing.T) { want := &Secrets{ TotalCount: 4, Secrets: []*Secret{ - {Name: "A", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001)}, + {Name: "B", CreatedAt: *refTimestamp(1136178002), UpdatedAt: *refTimestamp(1136178003)}, }, } if !cmp.Equal(secrets, want) { @@ -133,7 +132,7 @@ func TestCodespacesService_GetSecret(t *testing.T) { handleFunc: func(mux *http.ServeMux) { mux.HandleFunc("/user/codespaces/secrets/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) }, call: func(ctx context.Context, client *Client) (*Secret, *Response, error) { @@ -146,7 +145,7 @@ func TestCodespacesService_GetSecret(t *testing.T) { handleFunc: func(mux *http.ServeMux) { mux.HandleFunc("/orgs/o/codespaces/secrets/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) }, call: func(ctx context.Context, client *Client) (*Secret, *Response, error) { @@ -162,7 +161,7 @@ func TestCodespacesService_GetSecret(t *testing.T) { handleFunc: func(mux *http.ServeMux) { mux.HandleFunc("/repos/o/r/codespaces/secrets/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) }, call: func(ctx context.Context, client *Client) (*Secret, *Response, error) { @@ -188,7 +187,7 @@ func TestCodespacesService_GetSecret(t *testing.T) { t.Errorf("Codespaces.%v returned error: %v", tt.methodName, err) } - want := &Secret{Name: "A", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}} + want := &Secret{Name: "A", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001)} if !cmp.Equal(secret, want) { t.Errorf("Codespaces.%v returned %+v, want %+v", tt.methodName, secret, want) } diff --git a/github/codespaces_test.go b/github/codespaces_test.go index 4c6494d0190..7be8eb434f8 100644 --- a/github/codespaces_test.go +++ b/github/codespaces_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -24,7 +23,7 @@ func TestCodespacesService_ListInRepo(t *testing.T) { "page": "1", "per_page": "2", }) - fmt.Fprint(w, `{"total_count":2,"codespaces":[{"id":1,"name":"monalisa-octocat-hello-world-g4wpq6h95q","environment_id":"26a7c758-7299-4a73-b978-5a92a7ae98a0","owner":{"login":"octocat"},"billable_owner":{"login":"octocat"},"repository":{"id":1296269},"machine":{"name":"standardLinux","display_name":"4 cores, 8 GB RAM, 64 GB storage","operating_system":"linux","storage_in_bytes":68719476736,"memory_in_bytes":8589934592,"cpus":4},"prebuild":false,"devcontainer_path":".devcontainer/devcontainer.json","created_at":"2021-10-14T00:53:30-06:00","updated_at":"2021-10-14T00:53:32-06:00","last_used_at":"2021-10-14T00:53:30-06:00","state":"Available","url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q","git_status":{"ahead":0,"behind":0,"has_unpushed_changes":false,"has_uncommitted_changes":false,"ref":"main"},"location":"WestUs2","idle_timeout_minutes":60,"web_url":"https://monalisa-octocat-hello-world-g4wpq6h95q.github.dev","machines_url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q/machines","start_url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q/start","stop_url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q/stop","recent_folders":["testfolder1","testfolder2"]},{"id":2}]}`) + fmt.Fprint(w, `{"total_count":2,"codespaces":[{"id":1,"name":"monalisa-octocat-hello-world-g4wpq6h95q","environment_id":"26a7c758-7299-4a73-b978-5a92a7ae98a0","owner":{"login":"octocat"},"billable_owner":{"login":"octocat"},"repository":{"id":1296269},"machine":{"name":"standardLinux","display_name":"4 cores, 8 GB RAM, 64 GB storage","operating_system":"linux","storage_in_bytes":68719476736,"memory_in_bytes":8589934592,"cpus":4},"prebuild":false,"devcontainer_path":".devcontainer/devcontainer.json","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`,"last_used_at":`+refTimeStr(1136178002)+`,"state":"Available","url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q","git_status":{"ahead":0,"behind":0,"has_unpushed_changes":false,"has_uncommitted_changes":false,"ref":"main"},"location":"WestUs2","idle_timeout_minutes":60,"web_url":"https://monalisa-octocat-hello-world-g4wpq6h95q.github.dev","machines_url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q/machines","start_url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q/start","stop_url":"https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q/stop","recent_folders":["testfolder1","testfolder2"]},{"id":2}]}`) }) opt := &ListOptions{Page: 1, PerPage: 2} @@ -58,9 +57,9 @@ func TestCodespacesService_ListInRepo(t *testing.T) { }, Prebuild: Ptr(false), DevcontainerPath: Ptr(".devcontainer/devcontainer.json"), - CreatedAt: &Timestamp{time.Date(2021, 10, 14, 0, 53, 30, 0, time.FixedZone("", -6*60*60))}, - UpdatedAt: &Timestamp{time.Date(2021, 10, 14, 0, 53, 32, 0, time.FixedZone("", -6*60*60))}, - LastUsedAt: &Timestamp{time.Date(2021, 10, 14, 0, 53, 30, 0, time.FixedZone("", -6*60*60))}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), + LastUsedAt: refTimestamp(1136178002), State: Ptr("Available"), URL: Ptr("https://api.github.com/user/codespaces/monalisa-octocat-hello-world-g4wpq6h95q"), GitStatus: &CodespacesGitStatus{ @@ -643,7 +642,7 @@ func TestCodespacesService_ExportCodespace(t *testing.T) { testMethod(t, r, "POST") fmt.Fprint(w, `{ "state": "succeeded", - "completed_at": "2025-12-11T00:00:00Z", + "completed_at": `+referenceTimeStr+`, "branch": "main", "export_url": "https://api.github.com/user/codespaces/:name/exports/latest" }`) @@ -657,7 +656,7 @@ func TestCodespacesService_ExportCodespace(t *testing.T) { want := &CodespaceExport{ State: Ptr("succeeded"), - CompletedAt: Ptr(Timestamp{Time: time.Date(2025, time.December, 11, 0, 0, 0, 0, time.UTC)}), + CompletedAt: &referenceTimestamp, Branch: Ptr("main"), ExportURL: Ptr("https://api.github.com/user/codespaces/:name/exports/latest"), } @@ -684,7 +683,7 @@ func TestCodespacesService_GetLatestCodespaceExport(t *testing.T) { testMethod(t, r, "GET") fmt.Fprint(w, `{ "state": "succeeded", - "completed_at": "2025-12-11T00:00:00Z", + "completed_at": `+referenceTimeStr+`, "branch": "main", "export_url": "https://api.github.com/user/codespaces/:name/exports/latest" }`) @@ -698,7 +697,7 @@ func TestCodespacesService_GetLatestCodespaceExport(t *testing.T) { want := &CodespaceExport{ State: Ptr("succeeded"), - CompletedAt: Ptr(Timestamp{Time: time.Date(2025, time.December, 11, 0, 0, 0, 0, time.UTC)}), + CompletedAt: &referenceTimestamp, Branch: Ptr("main"), ExportURL: Ptr("https://api.github.com/user/codespaces/:name/exports/latest"), } diff --git a/github/copilot_test.go b/github/copilot_test.go index b94ab051406..8f3cfef2fac 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -11,7 +11,6 @@ import ( "log" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -357,10 +356,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { "total_seats": 4, "seats": [ { - "created_at": "2021-08-03T18:00:00-06:00", - "updated_at": "2021-09-23T15:00:00-06:00", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "pending_cancellation_date": null, - "last_activity_at": "2021-10-14T00:53:32-06:00", + "last_activity_at": `+refTimeStr(1136178002)+`, "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", "assignee": { "login": "octocat", @@ -399,10 +398,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { } }, { - "created_at": "2021-09-23T18:00:00-06:00", - "updated_at": "2021-09-23T15:00:00-06:00", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "pending_cancellation_date": "2021-11-01", - "last_activity_at": "2021-10-13T00:53:32-06:00", + "last_activity_at": `+refTimeStr(1136178002)+`, "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", "assignee": { "login": "octokitten", @@ -426,10 +425,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { } }, { - "created_at": "2021-09-23T18:00:00-06:00", - "updated_at": "2021-09-23T15:00:00-06:00", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "pending_cancellation_date": "2021-11-01", - "last_activity_at": "2021-10-13T00:53:32-06:00", + "last_activity_at": `+refTimeStr(1136178002)+`, "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", "assignee": { "name": "octokittens", @@ -438,10 +437,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { } }, { - "created_at": "2021-09-23T18:00:00-06:00", - "updated_at": "2021-09-23T15:00:00-06:00", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "pending_cancellation_date": "2021-11-01", - "last_activity_at": "2021-10-13T00:53:32-06:00", + "last_activity_at": `+refTimeStr(1136178002)+`, "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", "assignee": { "name": "octocats", @@ -500,10 +499,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { Parent: nil, }, - CreatedAt: Ptr(Timestamp{time.Date(2021, time.August, 3, 18, 0, 0, 0, time.FixedZone("CST", -6*3600))}), - UpdatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 15, 0, 0, 0, time.FixedZone("CST", -6*3600))}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), PendingCancellationDate: nil, - LastActivityAt: Ptr(Timestamp{time.Date(2021, time.October, 14, 0, 53, 32, 0, time.FixedZone("CST", -6*3600))}), + LastActivityAt: refTimestamp(1136178002), LastActivityEditor: Ptr("vscode/1.77.3/copilot/1.86.82"), }, { @@ -528,10 +527,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { SiteAdmin: Ptr(false), }, AssigningTeam: nil, - CreatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 18, 0, 0, 0, time.FixedZone("CST", -6*3600))}), - UpdatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 15, 0, 0, 0, time.FixedZone("CST", -6*3600))}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), PendingCancellationDate: Ptr("2021-11-01"), - LastActivityAt: Ptr(Timestamp{time.Date(2021, time.October, 13, 0, 53, 32, 0, time.FixedZone("CST", -6*3600))}), + LastActivityAt: refTimestamp(1136178002), LastActivityEditor: Ptr("vscode/1.77.3/copilot/1.86.82"), }, { @@ -541,10 +540,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { Type: Ptr("Team"), }, AssigningTeam: nil, - CreatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 18, 0, 0, 0, time.FixedZone("CST", -6*3600))}), - UpdatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 15, 0, 0, 0, time.FixedZone("CST", -6*3600))}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), PendingCancellationDate: Ptr("2021-11-01"), - LastActivityAt: Ptr(Timestamp{time.Date(2021, time.October, 13, 0, 53, 32, 0, time.FixedZone("CST", -6*3600))}), + LastActivityAt: refTimestamp(1136178002), LastActivityEditor: Ptr("vscode/1.77.3/copilot/1.86.82"), }, { @@ -554,10 +553,10 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { Type: Ptr("Organization"), }, AssigningTeam: nil, - CreatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 18, 0, 0, 0, time.FixedZone("CST", -6*3600))}), - UpdatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 15, 0, 0, 0, time.FixedZone("CST", -6*3600))}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), PendingCancellationDate: Ptr("2021-11-01"), - LastActivityAt: Ptr(Timestamp{time.Date(2021, time.October, 13, 0, 53, 32, 0, time.FixedZone("CST", -6*3600))}), + LastActivityAt: refTimestamp(1136178002), LastActivityEditor: Ptr("vscode/1.77.3/copilot/1.86.82"), }, }, @@ -595,10 +594,10 @@ func TestCopilotService_ListCopilotEnterpriseSeats(t *testing.T) { "total_seats": 2, "seats": [ { - "created_at": "2021-08-03T18:00:00-06:00", - "updated_at": "2021-09-23T15:00:00-06:00", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "pending_cancellation_date": null, - "last_activity_at": "2021-10-14T00:53:32-06:00", + "last_activity_at": `+refTimeStr(1136178002)+`, "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", "plan_type": "business", "assignee": { @@ -638,10 +637,10 @@ func TestCopilotService_ListCopilotEnterpriseSeats(t *testing.T) { } }, { - "created_at": "2021-09-23T18:00:00-06:00", - "updated_at": "2021-09-23T15:00:00-06:00", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "pending_cancellation_date": "2021-11-01", - "last_activity_at": "2021-10-13T00:53:32-06:00", + "last_activity_at": `+refTimeStr(1136178002)+`, "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", "assignee": { "login": "octokitten", @@ -714,10 +713,10 @@ func TestCopilotService_ListCopilotEnterpriseSeats(t *testing.T) { RepositoriesURL: Ptr("https://api.github.com/teams/1/repos"), Parent: nil, }, - CreatedAt: Ptr(Timestamp{time.Date(2021, time.August, 3, 18, 0, 0, 0, time.FixedZone("CST", -6*3600))}), - UpdatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 15, 0, 0, 0, time.FixedZone("CST", -6*3600))}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), PendingCancellationDate: nil, - LastActivityAt: Ptr(Timestamp{time.Date(2021, time.October, 14, 0, 53, 32, 0, time.FixedZone("CST", -6*3600))}), + LastActivityAt: refTimestamp(1136178002), LastActivityEditor: Ptr("vscode/1.77.3/copilot/1.86.82"), PlanType: Ptr("business"), }, @@ -743,10 +742,10 @@ func TestCopilotService_ListCopilotEnterpriseSeats(t *testing.T) { SiteAdmin: Ptr(false), }, AssigningTeam: nil, - CreatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 18, 0, 0, 0, time.FixedZone("CST", -6*3600))}), - UpdatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 15, 0, 0, 0, time.FixedZone("CST", -6*3600))}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), PendingCancellationDate: Ptr("2021-11-01"), - LastActivityAt: Ptr(Timestamp{time.Date(2021, time.October, 13, 0, 53, 32, 0, time.FixedZone("CST", -6*3600))}), + LastActivityAt: refTimestamp(1136178002), LastActivityEditor: Ptr("vscode/1.77.3/copilot/1.86.82"), PlanType: nil, }, @@ -1053,10 +1052,10 @@ func TestCopilotService_GetSeatDetails(t *testing.T) { mux.HandleFunc("/orgs/o/members/u/copilot", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `{ - "created_at": "2021-08-03T18:00:00-06:00", - "updated_at": "2021-09-23T15:00:00-06:00", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "pending_cancellation_date": null, - "last_activity_at": "2021-10-14T00:53:32-06:00", + "last_activity_at": `+refTimeStr(1136178002)+`, "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", "assignee": { "login": "octocat", @@ -1138,10 +1137,10 @@ func TestCopilotService_GetSeatDetails(t *testing.T) { RepositoriesURL: Ptr("https://api.github.com/teams/1/repos"), Parent: nil, }, - CreatedAt: Ptr(Timestamp{time.Date(2021, time.August, 3, 18, 0, 0, 0, time.FixedZone("CST", -6*3600))}), - UpdatedAt: Ptr(Timestamp{time.Date(2021, time.September, 23, 15, 0, 0, 0, time.FixedZone("CST", -6*3600))}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), PendingCancellationDate: nil, - LastActivityAt: Ptr(Timestamp{time.Date(2021, time.October, 14, 0, 53, 32, 0, time.FixedZone("CST", -6*3600))}), + LastActivityAt: refTimestamp(1136178002), LastActivityEditor: Ptr("vscode/1.77.3/copilot/1.86.82"), } @@ -3169,7 +3168,7 @@ func TestCopilotService_DownloadPeriodicMetrics(t *testing.T) { "report_start_day": "2026-03-05", "report_end_day": "2026-04-01", "organization_id": "123", - "created_at": "2026-04-02T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "day_totals": [ { "day": "2026-03-05", @@ -3210,7 +3209,7 @@ func TestCopilotService_DownloadPeriodicMetrics(t *testing.T) { ReportStartDay: "2026-03-05", ReportEndDay: "2026-04-01", OrganizationID: Ptr("123"), - CreatedAt: &Timestamp{time.Date(2026, 4, 2, 0, 0, 0, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), DayTotals: []*CopilotDailyMetrics{ { Day: "2026-03-05", @@ -3269,7 +3268,7 @@ func TestCopilotService_DownloadUserDailyMetrics(t *testing.T) { mux.HandleFunc("/path/to/users-daily", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"user_id":1,"user_login":"alice","day":"2026-04-01","user_initiated_interaction_count":5,"chat_panel_edit_mode":2,"used_chat":true,"used_cli":true,"used_copilot_code_review_active":true,"totals_by_cli":{"session_count":2,"request_count":2,"prompt_count":1,"last_known_cli_version":{"sampled_at":"2026-04-01T12:30:00Z","cli_version":"1.0.8"}},"totals_by_ide":[{"ide":"vscode","user_initiated_interaction_count":5,"last_known_plugin_version":{"sampled_at":"2026-04-01T12:00:00Z","plugin":"copilot","plugin_version":"1.0.0"},"last_known_ide_version":{"sampled_at":"2026-04-01T12:00:00Z","ide_version":"1.90"}}]} + fmt.Fprint(w, `{"user_id":1,"user_login":"alice","day":"2026-04-01","user_initiated_interaction_count":5,"chat_panel_edit_mode":2,"used_chat":true,"used_cli":true,"used_copilot_code_review_active":true,"totals_by_cli":{"session_count":2,"request_count":2,"prompt_count":1,"last_known_cli_version":{"sampled_at":`+refTimeStr(1136178000)+`,"cli_version":"1.0.8"}},"totals_by_ide":[{"ide":"vscode","user_initiated_interaction_count":5,"last_known_plugin_version":{"sampled_at":`+refTimeStr(1136178001)+`,"plugin":"copilot","plugin_version":"1.0.0"},"last_known_ide_version":{"sampled_at":`+refTimeStr(1136178002)+`,"ide_version":"1.90"}}]} {"user_id":2,"user_login":"bob","day":"2026-04-01","used_agent":true,"used_copilot_code_review_passive":true} `) }) @@ -3301,7 +3300,7 @@ func TestCopilotService_DownloadUserDailyMetrics(t *testing.T) { RequestCount: Ptr(2), PromptCount: Ptr(1), LastKnownCLIVersion: &CopilotMetricsCLIVersion{ - SampledAt: &Timestamp{time.Date(2026, 4, 1, 12, 30, 0, 0, time.UTC)}, + SampledAt: refTimestamp(1136178000), CLIVersion: "1.0.8", }, }, @@ -3310,12 +3309,12 @@ func TestCopilotService_DownloadUserDailyMetrics(t *testing.T) { IDE: "vscode", UserInitiatedInteractionCount: Ptr(5), LastKnownPluginVersion: &CopilotUserMetricsPluginVersion{ - SampledAt: &Timestamp{time.Date(2026, 4, 1, 12, 0, 0, 0, time.UTC)}, + SampledAt: refTimestamp(1136178001), Plugin: "copilot", PluginVersion: "1.0.0", }, LastKnownIDEVersion: &CopilotUserMetricsIDEVersion{ - SampledAt: &Timestamp{time.Date(2026, 4, 1, 12, 0, 0, 0, time.UTC)}, + SampledAt: refTimestamp(1136178002), IDEVersion: "1.90", }, }, diff --git a/github/dependabot_secrets_test.go b/github/dependabot_secrets_test.go index 0a1f8aa3587..0168293d15c 100644 --- a/github/dependabot_secrets_test.go +++ b/github/dependabot_secrets_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -91,7 +90,7 @@ func TestDependabotService_ListRepoSecrets(t *testing.T) { mux.HandleFunc("/repos/o/r/dependabot/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`},{"name":"B","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -104,8 +103,8 @@ func TestDependabotService_ListRepoSecrets(t *testing.T) { want := &Secrets{ TotalCount: 4, Secrets: []*Secret{ - {Name: "A", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, - {Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}}, + {Name: "A", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001)}, + {Name: "B", CreatedAt: *refTimestamp(1136178002), UpdatedAt: *refTimestamp(1136178003)}, }, } if !cmp.Equal(secrets, want) { @@ -133,7 +132,7 @@ func TestDependabotService_GetRepoSecret(t *testing.T) { mux.HandleFunc("/repos/o/r/dependabot/secrets/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"NAME","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}`) + fmt.Fprint(w, `{"name":"NAME","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`}`) }) ctx := t.Context() @@ -144,8 +143,8 @@ func TestDependabotService_GetRepoSecret(t *testing.T) { want := &Secret{ Name: "NAME", - CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: *refTimestamp(1136178000), + UpdatedAt: *refTimestamp(1136178001), } if !cmp.Equal(secret, want) { t.Errorf("Dependabot.GetRepoSecret returned %+v, want %+v", secret, want) @@ -275,7 +274,7 @@ func TestDependabotService_ListOrgSecrets(t *testing.T) { mux.HandleFunc("/orgs/o/dependabot/secrets", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":3,"secrets":[{"name":"GIST_ID","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"private"},{"name":"DEPLOY_TOKEN","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"all"},{"name":"GH_TOKEN","created_at":"2019-08-10T14:59:22Z","updated_at":"2020-01-10T14:59:22Z","visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/dependabot/secrets/SUPER_SECRET/repositories"}]}`) + fmt.Fprint(w, `{"total_count":3,"secrets":[{"name":"GIST_ID","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`,"visibility":"private"},{"name":"DEPLOY_TOKEN","created_at":`+refTimeStr(1136178002)+`,"updated_at":`+refTimeStr(1136178003)+`,"visibility":"all"},{"name":"GH_TOKEN","created_at":`+refTimeStr(1136178004)+`,"updated_at":`+refTimeStr(1136178005)+`,"visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/dependabot/secrets/SUPER_SECRET/repositories"}]}`) }) opts := &ListOptions{Page: 2, PerPage: 2} @@ -288,9 +287,9 @@ func TestDependabotService_ListOrgSecrets(t *testing.T) { want := &Secrets{ TotalCount: 3, Secrets: []*Secret{ - {Name: "GIST_ID", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "private"}, - {Name: "DEPLOY_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "all"}, - {Name: "GH_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/dependabot/secrets/SUPER_SECRET/repositories"}, + {Name: "GIST_ID", CreatedAt: *refTimestamp(1136178000), UpdatedAt: *refTimestamp(1136178001), Visibility: "private"}, + {Name: "DEPLOY_TOKEN", CreatedAt: *refTimestamp(1136178002), UpdatedAt: *refTimestamp(1136178003), Visibility: "all"}, + {Name: "GH_TOKEN", CreatedAt: *refTimestamp(1136178004), UpdatedAt: *refTimestamp(1136178005), Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/dependabot/secrets/SUPER_SECRET/repositories"}, }, } if !cmp.Equal(secrets, want) { @@ -318,7 +317,7 @@ func TestDependabotService_GetOrgSecret(t *testing.T) { mux.HandleFunc("/orgs/o/dependabot/secrets/NAME", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"name":"NAME","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z","visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/dependabot/secrets/SUPER_SECRET/repositories"}`) + fmt.Fprint(w, `{"name":"NAME","created_at":`+refTimeStr(1136178000)+`,"updated_at":`+refTimeStr(1136178001)+`,"visibility":"selected","selected_repositories_url":"https://api.github.com/orgs/octo-org/dependabot/secrets/SUPER_SECRET/repositories"}`) }) ctx := t.Context() @@ -329,8 +328,8 @@ func TestDependabotService_GetOrgSecret(t *testing.T) { want := &Secret{ Name: "NAME", - CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)}, - UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)}, + CreatedAt: *refTimestamp(1136178000), + UpdatedAt: *refTimestamp(1136178001), Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/dependabot/secrets/SUPER_SECRET/repositories", } diff --git a/github/dependency_graph_snapshots_test.go b/github/dependency_graph_snapshots_test.go index 07ef845944b..ef8f360bada 100644 --- a/github/dependency_graph_snapshots_test.go +++ b/github/dependency_graph_snapshots_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -32,7 +31,7 @@ func TestDependencyGraphService_CreateSnapshot(t *testing.T) { Version: Ptr("0.0.1"), URL: Ptr("https://github.com/octo-org/octo-repo"), }, - Scanned: &Timestamp{time.Date(2022, time.June, 14, 20, 25, 0, 0, time.UTC)}, + Scanned: &referenceTimestamp, Metadata: map[string]any{ "key1": "value1", "key2": "value2", @@ -74,7 +73,7 @@ func TestDependencyGraphService_CreateSnapshot(t *testing.T) { mux.HandleFunc("/repos/o/r/dependency-graph/snapshots", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") testJSONBody(t, r, snapshot) - fmt.Fprint(w, `{"id":12345,"created_at":"2022-06-14T20:25:01Z","message":"Dependency results for the repo have been successfully updated.","result":"SUCCESS"}`) + fmt.Fprint(w, `{"id":12345,"created_at":`+referenceTimeStr+`,"message":"Dependency results for the repo have been successfully updated.","result":"SUCCESS"}`) }) ctx := t.Context() @@ -85,7 +84,7 @@ func TestDependencyGraphService_CreateSnapshot(t *testing.T) { want := &DependencyGraphSnapshotCreationData{ ID: 12345, - CreatedAt: &Timestamp{time.Date(2022, time.June, 14, 20, 25, 1, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, Message: Ptr("Dependency results for the repo have been successfully updated."), Result: Ptr("SUCCESS"), } diff --git a/github/dependency_graph_test.go b/github/dependency_graph_test.go index 1bae03b9559..994c87fa18a 100644 --- a/github/dependency_graph_test.go +++ b/github/dependency_graph_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -23,7 +22,7 @@ func TestDependencyGraphService_GetSBOM(t *testing.T) { fmt.Fprint(w, `{ "sbom":{ "creationInfo":{ - "created":"2021-09-01T00:00:00Z" + "created":`+referenceTimeStr+` }, "name":"owner/repo", "packages":[ @@ -42,11 +41,10 @@ func TestDependencyGraphService_GetSBOM(t *testing.T) { t.Errorf("DependencyGraph.GetSBOM returned error: %v", err) } - testTime := time.Date(2021, 9, 1, 0, 0, 0, 0, time.UTC) want := &SBOM{ &SBOMInfo{ CreationInfo: &CreationInfo{ - Created: &Timestamp{testTime}, + Created: &referenceTimestamp, }, Name: Ptr("owner/repo"), Packages: []*RepoDependencies{ diff --git a/github/enterprise_actions_hosted_runners_test.go b/github/enterprise_actions_hosted_runners_test.go index 1575ef22086..abb6df8db6b 100644 --- a/github/enterprise_actions_hosted_runners_test.go +++ b/github/enterprise_actions_hosted_runners_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -48,7 +47,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }, { "id": 7, @@ -69,7 +68,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { "maximum_runners": 20, "public_ip_enabled": false, "public_ips": [], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` } ] }`) @@ -81,8 +80,6 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { t.Errorf("Enterprise.ListHostedRunners returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} - want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -111,7 +108,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, }, { ID: Ptr(int64(7)), @@ -132,7 +129,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, }, }, } @@ -186,7 +183,7 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -209,7 +206,6 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) { t.Errorf("Enterprise.CreateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -235,7 +231,7 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -614,7 +610,7 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -624,7 +620,6 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) { t.Errorf("Enterprise.GetHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -650,7 +645,7 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -703,7 +698,7 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -721,7 +716,6 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) { t.Errorf("Enterprise.UpdateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -747,7 +741,7 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -800,7 +794,7 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) { "length": 31 } ], - "last_active_on": "2023-04-26T15:23:37Z" + "last_active_on": `+referenceTimeStr+` }`) }) @@ -810,7 +804,6 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) { t.Errorf("Enterprise.DeleteHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -836,7 +829,7 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: &lastActiveOn, + LastActiveOn: &referenceTimestamp, } if !cmp.Equal(hostedRunner, want) { @@ -1035,14 +1028,14 @@ func TestEnterpriseService_ListHostedRunnerCustomImageVersions(t *testing.T) { "size_gb": 75, "state": "Ready", "state_details": "None", - "created_on": "2024-11-09T23:39:01Z" + "created_on": `+referenceTimeStr+` }, { "version": "1.0.0", "size_gb": 75, "state": "Ready", "state_details": "None", - "created_on": "2024-11-08T20:39:01Z" + "created_on": `+referenceTimeStr+` } ] }`) @@ -1062,14 +1055,14 @@ func TestEnterpriseService_ListHostedRunnerCustomImageVersions(t *testing.T) { SizeGB: 75, State: "Ready", StateDetails: "None", - CreatedOn: Timestamp{time.Date(2024, 11, 9, 23, 39, 1, 0, time.UTC)}, + CreatedOn: referenceTimestamp, }, { Version: "1.0.0", SizeGB: 75, State: "Ready", StateDetails: "None", - CreatedOn: Timestamp{time.Date(2024, 11, 8, 20, 39, 1, 0, time.UTC)}, + CreatedOn: referenceTimestamp, }, }, } @@ -1104,7 +1097,7 @@ func TestEnterpriseService_GetHostedRunnerCustomImageVersion(t *testing.T) { "size_gb": 75, "state": "Ready", "state_details": "None", - "created_on": "2024-11-08T20:39:01Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -1119,7 +1112,7 @@ func TestEnterpriseService_GetHostedRunnerCustomImageVersion(t *testing.T) { SizeGB: 75, State: "Ready", StateDetails: "None", - CreatedOn: Timestamp{time.Date(2024, 11, 8, 20, 39, 1, 0, time.UTC)}, + CreatedOn: referenceTimestamp, } if !cmp.Equal(version, want) { diff --git a/github/enterprise_actions_runners_test.go b/github/enterprise_actions_runners_test.go index 1e4df2dd142..eb42876ef50 100644 --- a/github/enterprise_actions_runners_test.go +++ b/github/enterprise_actions_runners_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -58,7 +57,7 @@ func TestEnterpriseService_CreateRegistrationToken(t *testing.T) { mux.HandleFunc("/enterprises/e/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`) + fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":`+referenceTimeStr+`}`) }) ctx := t.Context() @@ -68,9 +67,8 @@ func TestEnterpriseService_CreateRegistrationToken(t *testing.T) { } want := &RegistrationToken{ - Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), - ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35, - 123000000, time.UTC)}, + Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), + ExpiresAt: &referenceTimestamp, } if !cmp.Equal(token, want) { t.Errorf("Enterprise.CreateRegistrationToken returned %+v, want %+v", token, want) diff --git a/github/enterprise_licenses_test.go b/github/enterprise_licenses_test.go index dd79c13c775..288e8572e88 100644 --- a/github/enterprise_licenses_test.go +++ b/github/enterprise_licenses_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -120,7 +119,7 @@ func TestEnterpriseService_GetLicenseSyncStatus(t *testing.T) { "last_sync": { "type": "object", "properties": { - "date": "2025-10-30T10:30:00Z", + "date": `+referenceTimeStr+`, "status": "success", "error": "" } @@ -152,7 +151,7 @@ func TestEnterpriseService_GetLicenseSyncStatus(t *testing.T) { LastSync: &LastLicenseSync{ Type: "object", Properties: &LastLicenseSyncProperties{ - Date: &Timestamp{time.Date(2025, 10, 30, 10, 30, 0, 0, time.UTC)}, + Date: &referenceTimestamp, Status: "success", Error: "", }, diff --git a/github/enterprise_manage_ghes_config_test.go b/github/enterprise_manage_ghes_config_test.go index 3c793149585..cc43ead90b9 100644 --- a/github/enterprise_manage_ghes_config_test.go +++ b/github/enterprise_manage_ghes_config_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -52,7 +51,7 @@ func TestEnterpriseService_Settings(t *testing.T) { "support_key": "ssh-rsa AAAAB3N....", "ssh_allowed": true, "cluster_support": false, - "expire_at": "2018-01-01T00:00:00-00:00" + "expire_at": `+referenceTimeStr+` }, "github_ssl": { "enabled": false, @@ -195,7 +194,7 @@ func TestEnterpriseService_Settings(t *testing.T) { SupportKey: Ptr("ssh-rsa AAAAB3N...."), SSHAllowed: Ptr(true), ClusterSupport: Ptr(false), - ExpireAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + ExpireAt: &referenceTimestamp, }, GithubSSL: &ConfigSettingsGithubSSL{ Enabled: Ptr(false), @@ -415,10 +414,10 @@ func TestEnterpriseService_License(t *testing.T) { "croquetSupport": true, "customTerms": true, "evaluation": false, - "expireAt": "2018-01-01T00:00:00Z", + "expireAt": `+refTimeStr(1136178000)+`, "insightsEnabled": true, - "insightsExpireAt": "2018-01-01T00:00:00Z", - "learningLabEvaluationExpires": "2018-01-01T00:00:00Z", + "insightsExpireAt": `+refTimeStr(1136178001)+`, + "learningLabEvaluationExpires": `+refTimeStr(1136178002)+`, "learningLabSeats": 100, "perpetual": false, "referenceNumber": "32a145", @@ -443,10 +442,10 @@ func TestEnterpriseService_License(t *testing.T) { CroquetSupport: Ptr(true), CustomTerms: Ptr(true), Evaluation: Ptr(false), - ExpireAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + ExpireAt: refTimestamp(1136178000), InsightsEnabled: Ptr(true), - InsightsExpireAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, - LearningLabEvaluationExpires: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + InsightsExpireAt: refTimestamp(1136178001), + LearningLabEvaluationExpires: refTimestamp(1136178002), LearningLabSeats: Ptr(100), Perpetual: Ptr(false), ReferenceNumber: Ptr("32a145"), @@ -479,7 +478,7 @@ func TestEnterpriseService_ConfigApplyEvents(t *testing.T) { "node": "ghes-01.lan", "last_request_id": "387cd628c06d606700e79be368e5e574:0cde553750689c76:0000000000000000", "events": [{ - "timestamp": "2018-01-01T00:00:00+00:00", + "timestamp": `+referenceTimeStr+`, "severity_text": "INFO", "body": "Validating services", "event_name": "Enterprise::ConfigApply::PhaseValidation#config_phase_validation", @@ -510,7 +509,7 @@ func TestEnterpriseService_ConfigApplyEvents(t *testing.T) { Node: Ptr("ghes-01.lan"), LastRequestID: Ptr("387cd628c06d606700e79be368e5e574:0cde553750689c76:0000000000000000"), Events: []*ConfigApplyEventsNodeEvent{{ - Timestamp: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + Timestamp: &referenceTimestamp, SeverityText: Ptr("INFO"), Body: Ptr("Validating services"), EventName: Ptr("Enterprise::ConfigApply::PhaseValidation#config_phase_validation"), diff --git a/github/enterprise_manage_ghes_maintenance_test.go b/github/enterprise_manage_ghes_maintenance_test.go index 82abacb7d0e..0a3f3cf559d 100644 --- a/github/enterprise_manage_ghes_maintenance_test.go +++ b/github/enterprise_manage_ghes_maintenance_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -28,7 +27,7 @@ func TestEnterpriseService_GetMaintenanceStatus(t *testing.T) { "hostname": "primary", "uuid": "1b6cf518-f97c-11ed-8544-061d81f7eedb", "status": "scheduled", - "scheduled_time": "2018-01-01T00:00:00+00:00", + "scheduled_time": `+referenceTimeStr+`, "connection_services": [ { "name": "git operations", @@ -56,7 +55,7 @@ func TestEnterpriseService_GetMaintenanceStatus(t *testing.T) { Hostname: Ptr("primary"), UUID: Ptr("1b6cf518-f97c-11ed-8544-061d81f7eedb"), Status: Ptr("scheduled"), - ScheduledTime: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + ScheduledTime: &referenceTimestamp, ConnectionServices: []*ConnectionServiceItem{{ Name: Ptr("git operations"), Number: Ptr(15), diff --git a/github/enterprise_network_configurations_test.go b/github/enterprise_network_configurations_test.go index 43e1602298f..c4154b5f654 100644 --- a/github/enterprise_network_configurations_test.go +++ b/github/enterprise_network_configurations_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -32,7 +31,7 @@ func TestEnterpriseService_ListEnterpriseNetworkConfigurations(t *testing.T) { "23456789ABDCEF1", "3456789ABDCEF12" ], - "created_on": "2024-04-09T17:30:15Z" + "created_on": `+referenceTimeStr+` }, { "id": "456789ABDCEF123", @@ -42,7 +41,7 @@ func TestEnterpriseService_ListEnterpriseNetworkConfigurations(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345" ], - "created_on": "2024-11-02T12:30:30Z" + "created_on": `+referenceTimeStr+` } ] }`) @@ -64,14 +63,14 @@ func TestEnterpriseService_ListEnterpriseNetworkConfigurations(t *testing.T) { Name: Ptr("configuration one"), ComputeService: Ptr(ComputeService("actions")), NetworkSettingsIDs: []string{"23456789ABDCEF1", "3456789ABDCEF12"}, - CreatedOn: &Timestamp{time.Date(2024, 4, 9, 17, 30, 15, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, }, { ID: Ptr("456789ABDCEF123"), Name: Ptr("configuration two"), ComputeService: Ptr(ComputeService("none")), NetworkSettingsIDs: []string{"56789ABDCEF1234", "6789ABDCEF12345"}, - CreatedOn: &Timestamp{time.Date(2024, 11, 2, 12, 30, 30, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, }, }, } @@ -107,7 +106,7 @@ func TestEnterpriseService_CreateEnterpriseNetworkConfiguration(t *testing.T) { "network_settings_ids": [ "23456789ABDCEF1" ], - "created_on": "2024-04-09T17:30:15Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -130,7 +129,7 @@ func TestEnterpriseService_CreateEnterpriseNetworkConfiguration(t *testing.T) { Name: Ptr("configuration one"), ComputeService: Ptr(ComputeService("actions")), NetworkSettingsIDs: []string{"23456789ABDCEF1"}, - CreatedOn: &Timestamp{time.Date(2024, 4, 9, 17, 30, 15, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, } if !cmp.Equal(configuration, want) { t.Errorf("Enterprise.CreateEnterpriseNetworkConfiguration mismatch (-want +got):\n%v", cmp.Diff(want, configuration)) @@ -202,7 +201,7 @@ func TestEnterpriseService_GetEnterpriseNetworkConfiguration(t *testing.T) { "23456789ABDCEF1", "3456789ABDCEF12" ], - "created_on": "2024-12-10T19:00:15Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -217,7 +216,7 @@ func TestEnterpriseService_GetEnterpriseNetworkConfiguration(t *testing.T) { Name: Ptr("configuration one"), ComputeService: Ptr(ComputeService("actions")), NetworkSettingsIDs: []string{"23456789ABDCEF1", "3456789ABDCEF12"}, - CreatedOn: &Timestamp{time.Date(2024, 12, 10, 19, 0, 15, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, } if !cmp.Equal(configuration, want) { t.Errorf("Enterprise.GetEnterpriseNetworkConfiguration mismatch (-want +got):\n%v", cmp.Diff(want, configuration)) @@ -251,7 +250,7 @@ func TestEnterpriseService_UpdateEnterpriseNetworkConfiguration(t *testing.T) { "network_settings_ids": [ "456789ABDCEF123" ], - "created_on": "2024-12-10T19:00:15Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -273,7 +272,7 @@ func TestEnterpriseService_UpdateEnterpriseNetworkConfiguration(t *testing.T) { Name: Ptr("updated configuration one"), ComputeService: Ptr(ComputeService("none")), NetworkSettingsIDs: []string{"456789ABDCEF123"}, - CreatedOn: &Timestamp{time.Date(2024, 12, 10, 19, 0, 15, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, } if !cmp.Equal(configuration, want) { t.Errorf("Enterprise.UpdateEnterpriseNetworkConfiguration mismatch (-want +get)\n%v", cmp.Diff(want, configuration)) diff --git a/github/enterprise_team_test.go b/github/enterprise_team_test.go index b79f8c3a793..e8a9562fcae 100644 --- a/github/enterprise_team_test.go +++ b/github/enterprise_team_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -27,8 +26,8 @@ func TestEnterpriseService_ListTeams(t *testing.T) { "name": "Team One", "html_url": "https://example.com/html", "slug": "team-one", - "created_at": "2020-01-01T00:00:00Z", - "updated_at": "2020-01-02T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "group_id": "99" }]`) }) @@ -49,8 +48,8 @@ func TestEnterpriseService_ListTeams(t *testing.T) { HTMLURL: "https://example.com/html", Slug: "team-one", GroupID: "99", - CreatedAt: Timestamp{Time: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC)}, - UpdatedAt: Timestamp{Time: time.Date(2020, time.January, 2, 0, 0, 0, 0, time.UTC)}, + CreatedAt: *refTimestamp(1136178000), + UpdatedAt: *refTimestamp(1136178001), }, } diff --git a/github/gists_test.go b/github/gists_test.go index 3a3f08668bb..6a5b2859e5e 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -18,17 +17,15 @@ func TestGistsService_List_specifiedUser(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - since := "2013-01-01T00:00:00Z" - mux.HandleFunc("/users/u/gists", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{ - "since": since, + "since": referenceTimeRaw, }) fmt.Fprint(w, `[{"id": "1"}]`) }) - opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)} + opt := &GistListOptions{Since: referenceTime} ctx := t.Context() gists, _, err := client.Gists.List(ctx, "u", opt) if err != nil { @@ -103,17 +100,15 @@ func TestGistsService_ListAll(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - since := "2013-01-01T00:00:00Z" - mux.HandleFunc("/gists/public", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{ - "since": since, + "since": referenceTimeRaw, }) fmt.Fprint(w, `[{"id": "1"}]`) }) - opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)} + opt := &GistListOptions{Since: referenceTime} ctx := t.Context() gists, _, err := client.Gists.ListAll(ctx, opt) if err != nil { @@ -139,17 +134,15 @@ func TestGistsService_ListStarred(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - since := "2013-01-01T00:00:00Z" - mux.HandleFunc("/gists/starred", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{ - "since": since, + "since": referenceTimeRaw, }) fmt.Fprint(w, `[{"id": "1"}]`) }) - opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)} + opt := &GistListOptions{Since: referenceTime} ctx := t.Context() gists, _, err := client.Gists.ListStarred(ctx, opt) if err != nil { @@ -414,7 +407,7 @@ func TestGistsService_ListCommits(t *testing.T) { "additions": 180, "total": 180 }, - "committed_at": "2010-01-01T00:00:00Z" + "committed_at": `+referenceTimeStr+` } ] `) @@ -430,7 +423,7 @@ func TestGistsService_ListCommits(t *testing.T) { URL: Ptr("https://api.github.com/gists/1/1"), Version: Ptr("1"), User: &User{ID: Ptr(int64(1))}, - CommittedAt: &Timestamp{time.Date(2010, time.January, 1, 0, 0, 0, 0, time.UTC)}, + CommittedAt: &referenceTimestamp, ChangeStatus: &CommitStats{ Additions: Ptr(180), Deletions: Ptr(0), @@ -723,8 +716,8 @@ func TestGistsService_ListForks(t *testing.T) { {"url": "https://api.github.com/gists/1", "user": {"id": 1}, "id": "1", - "created_at": "2010-01-01T00:00:00Z", - "updated_at": "2013-01-01T00:00:00Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` } ] `) @@ -740,8 +733,8 @@ func TestGistsService_ListForks(t *testing.T) { URL: Ptr("https://api.github.com/gists/1"), ID: Ptr("1"), User: &User{ID: Ptr(int64(1))}, - CreatedAt: &Timestamp{time.Date(2010, time.January, 1, 0, 0, 0, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), }} if !cmp.Equal(gistForks, want) { diff --git a/github/github_test.go b/github/github_test.go index 5d47371105f..6d82a59bb1b 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -2424,7 +2424,7 @@ func TestDo_rateLimit(t *testing.T) { w.Header().Set(HeaderRateLimit, "60") w.Header().Set(HeaderRateRemaining, "59") w.Header().Set(HeaderRateUsed, "1") - w.Header().Set(HeaderRateReset, "1372700873") + w.Header().Set(HeaderRateReset, referenceUnixTimeStr) w.Header().Set(HeaderRateResource, "core") }) @@ -2442,9 +2442,8 @@ func TestDo_rateLimit(t *testing.T) { if got, want := resp.Rate.Used, 1; got != want { t.Errorf("Client rate used = %v, want %v", got, want) } - reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC) - if !resp.Rate.Reset.UTC().Equal(reset) { - t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset.UTC(), reset) + if !resp.Rate.Reset.UTC().Equal(referenceTime) { + t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset.UTC(), referenceTime) } if got, want := resp.Rate.Resource, "core"; got != want { t.Errorf("Client rate resource = %v, want %v", got, want) @@ -2542,7 +2541,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { w.Header().Set(HeaderRateLimit, "60") w.Header().Set(HeaderRateRemaining, "59") w.Header().Set(HeaderRateUsed, "1") - w.Header().Set(HeaderRateReset, "1372700873") + w.Header().Set(HeaderRateReset, referenceUnixTimeStr) w.Header().Set(HeaderRateResource, "core") http.Error(w, "Bad Request", 400) }) @@ -2564,9 +2563,8 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { if got, want := resp.Rate.Used, 1; got != want { t.Errorf("Client rate used = %v, want %v", got, want) } - reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC) - if !resp.Rate.Reset.UTC().Equal(reset) { - t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset) + if !resp.Rate.Reset.UTC().Equal(referenceTime) { + t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, referenceTime) } if got, want := resp.Rate.Resource, "core"; got != want { t.Errorf("Client rate resource = %v, want %v", got, want) @@ -2582,7 +2580,7 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) { w.Header().Set(HeaderRateLimit, "60") w.Header().Set(HeaderRateRemaining, "0") w.Header().Set(HeaderRateUsed, "60") - w.Header().Set(HeaderRateReset, "1372700873") + w.Header().Set(HeaderRateReset, referenceUnixTimeStr) w.Header().Set(HeaderRateResource, "core") w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(http.StatusForbidden) @@ -2611,9 +2609,8 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) { if got, want := rateLimitErr.Rate.Used, 60; got != want { t.Errorf("rateLimitErr rate used = %v, want %v", got, want) } - reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC) - if !rateLimitErr.Rate.Reset.UTC().Equal(reset) { - t.Errorf("rateLimitErr rate reset = %v, want %v", rateLimitErr.Rate.Reset.UTC(), reset) + if !rateLimitErr.Rate.Reset.UTC().Equal(referenceTime) { + t.Errorf("rateLimitErr rate reset = %v, want %v", rateLimitErr.Rate.Reset.UTC(), referenceTime) } if got, want := rateLimitErr.Rate.Resource, "core"; got != want { t.Errorf("rateLimitErr rate resource = %v, want %v", got, want) @@ -3457,7 +3454,7 @@ func TestCheckResponse(t *testing.T) { StatusCode: http.StatusBadRequest, Body: io.NopCloser(strings.NewReader(`{"message":"m", "errors": [{"resource": "r", "field": "f", "code": "c"}], - "block": {"reason": "dmca", "created_at": "2016-03-17T15:39:46Z"}}`)), + "block": {"reason": "dmca", "created_at": ` + referenceTimeStr + `}}`)), } var err *ErrorResponse errors.As(CheckResponse(res), &err) @@ -3472,7 +3469,7 @@ func TestCheckResponse(t *testing.T) { Errors: []Error{{Resource: "r", Field: "f", Code: "c"}}, Block: &ErrorBlock{ Reason: "dmca", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, } if !errors.Is(err, want) { @@ -3685,7 +3682,7 @@ func TestErrorResponse_Is(t *testing.T) { Errors: []Error{{Resource: "r", Field: "f", Code: "c"}}, Block: &ErrorBlock{ Reason: "r", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://github.com", } @@ -3701,7 +3698,7 @@ func TestErrorResponse_Is(t *testing.T) { Message: "m", Block: &ErrorBlock{ Reason: "r", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://github.com", }, @@ -3714,7 +3711,7 @@ func TestErrorResponse_Is(t *testing.T) { Message: "m1", Block: &ErrorBlock{ Reason: "r", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://github.com", }, @@ -3727,7 +3724,7 @@ func TestErrorResponse_Is(t *testing.T) { Message: "m", Block: &ErrorBlock{ Reason: "r", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://google.com", }, @@ -3739,7 +3736,7 @@ func TestErrorResponse_Is(t *testing.T) { Message: "m", Block: &ErrorBlock{ Reason: "r", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://github.com", }, @@ -3752,7 +3749,7 @@ func TestErrorResponse_Is(t *testing.T) { Message: "m", Block: &ErrorBlock{ Reason: "r", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://github.com", }, @@ -3765,7 +3762,7 @@ func TestErrorResponse_Is(t *testing.T) { Message: "m", Block: &ErrorBlock{ Reason: "r", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://github.com", }, @@ -3787,7 +3784,7 @@ func TestErrorResponse_Is(t *testing.T) { Message: "m", Block: &ErrorBlock{ Reason: "r1", - CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, }, DocumentationURL: "https://github.com", }, diff --git a/github/issue_import_test.go b/github/issue_import_test.go index 1b7149a983d..e3509145206 100644 --- a/github/issue_import_test.go +++ b/github/issue_import_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -19,18 +18,17 @@ func TestIssueImportService_Create(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - createdAt := time.Date(2020, time.August, 11, 15, 30, 0, 0, time.UTC) input := &IssueImportRequest{ IssueImport: IssueImport{ Assignee: Ptr("developer"), Body: "Dummy description", - CreatedAt: &Timestamp{createdAt}, + CreatedAt: &referenceTimestamp, Labels: []string{"l1", "l2"}, Milestone: Ptr(1), Title: "Dummy Issue", }, Comments: []*Comment{{ - CreatedAt: &Timestamp{createdAt}, + CreatedAt: &referenceTimestamp, Body: "Comment body", }}, } @@ -72,18 +70,17 @@ func TestIssueImportService_Create_deferred(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - createdAt := time.Date(2020, time.August, 11, 15, 30, 0, 0, time.UTC) input := &IssueImportRequest{ IssueImport: IssueImport{ Assignee: Ptr("developer"), Body: "Dummy description", - CreatedAt: &Timestamp{createdAt}, + CreatedAt: &referenceTimestamp, Labels: []string{"l1", "l2"}, Milestone: Ptr(1), Title: "Dummy Issue", }, Comments: []*Comment{{ - CreatedAt: &Timestamp{createdAt}, + CreatedAt: &referenceTimestamp, Body: "Comment body", }}, } @@ -113,18 +110,17 @@ func TestIssueImportService_Create_badResponse(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - createdAt := time.Date(2020, time.August, 11, 15, 30, 0, 0, time.UTC) input := &IssueImportRequest{ IssueImport: IssueImport{ Assignee: Ptr("developer"), Body: "Dummy description", - CreatedAt: &Timestamp{createdAt}, + CreatedAt: &referenceTimestamp, Labels: []string{"l1", "l2"}, Milestone: Ptr(1), Title: "Dummy Issue", }, Comments: []*Comment{{ - CreatedAt: &Timestamp{createdAt}, + CreatedAt: &referenceTimestamp, Body: "Comment body", }}, } @@ -212,7 +208,7 @@ func TestIssueImportService_CheckStatusSince(t *testing.T) { }) ctx := t.Context() - got, _, err := client.IssueImport.CheckStatusSince(ctx, "o", "r", Timestamp{time.Now()}) + got, _, err := client.IssueImport.CheckStatusSince(ctx, "o", "r", referenceTimestamp) if err != nil { t.Errorf("CheckStatusSince returned error: %v", err) } @@ -224,12 +220,12 @@ func TestIssueImportService_CheckStatusSince(t *testing.T) { const methodName = "CheckStatusSince" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.IssueImport.CheckStatusSince(ctx, "\n", "\n", Timestamp{time.Now()}) + _, _, err = client.IssueImport.CheckStatusSince(ctx, "\n", "\n", referenceTimestamp) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.IssueImport.CheckStatusSince(ctx, "o", "r", Timestamp{time.Now()}) + got, resp, err := client.IssueImport.CheckStatusSince(ctx, "o", "r", referenceTimestamp) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -249,7 +245,7 @@ func TestIssueImportService_CheckStatusSince_badResponse(t *testing.T) { }) ctx := t.Context() - if _, _, err := client.IssueImport.CheckStatusSince(ctx, "o", "r", Timestamp{time.Now()}); err == nil { + if _, _, err := client.IssueImport.CheckStatusSince(ctx, "o", "r", referenceTimestamp); err == nil { t.Error("CheckStatusSince returned no error, want JSON err") } } @@ -259,7 +255,7 @@ func TestIssueImportService_CheckStatusSince_invalidOwner(t *testing.T) { client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.IssueImport.CheckStatusSince(ctx, "%", "r", Timestamp{time.Now()}) + _, _, err := client.IssueImport.CheckStatusSince(ctx, "%", "r", referenceTimestamp) testURLParseError(t, err) } diff --git a/github/issues_comments_test.go b/github/issues_comments_test.go index 4f20ee753b5..70a317b5308 100644 --- a/github/issues_comments_test.go +++ b/github/issues_comments_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -24,17 +23,16 @@ func TestIssuesService_ListComments_allIssues(t *testing.T) { testFormValues(t, r, values{ "sort": "updated", "direction": "desc", - "since": "2002-02-10T15:30:00Z", + "since": referenceTimeRaw, "page": "2", }) fmt.Fprint(w, `[{"id":1}]`) }) - since := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC) opt := &IssueListCommentsOptions{ Sort: Ptr("updated"), Direction: Ptr("desc"), - Since: &since, + Since: &referenceTime, ListOptions: ListOptions{Page: 2}, } ctx := t.Context() diff --git a/github/issues_test.go b/github/issues_test.go index e4da6c72c49..3d129fd83ed 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -27,7 +26,7 @@ func TestIssuesService_ListAllIssues(t *testing.T) { "labels": "a,b", "sort": "updated", "direction": "asc", - "since": "2026-01-02T00:00:00Z", + "since": referenceTimeRaw, "collab": "true", "orgs": "true", "owned": "true", @@ -44,7 +43,7 @@ func TestIssuesService_ListAllIssues(t *testing.T) { Labels: []string{"a", "b"}, Sort: "updated", Direction: "asc", - Since: time.Date(2026, time.January, 2, 0, 0, 0, 0, time.UTC), + Since: referenceTime, Collab: true, Orgs: true, Owned: true, @@ -85,7 +84,7 @@ func TestIssuesService_ListUserIssues(t *testing.T) { "labels": "a,b", "sort": "updated", "direction": "asc", - "since": "2026-01-02T00:00:00Z", + "since": referenceTimeRaw, "per_page": "4", "page": "2", }) @@ -99,7 +98,7 @@ func TestIssuesService_ListUserIssues(t *testing.T) { Labels: []string{"a", "b"}, Sort: "updated", Direction: "asc", - Since: time.Date(2026, time.January, 2, 0, 0, 0, 0, time.UTC), + Since: referenceTime, ListOptions: ListOptions{Page: 2, PerPage: 4}, } issues, _, err := client.Issues.ListUserIssues(ctx, opts) @@ -135,7 +134,7 @@ func TestIssuesService_ListByOrg(t *testing.T) { "type": "bug", "sort": "updated", "direction": "asc", - "since": "2026-01-02T00:00:00Z", + "since": referenceTimeRaw, "per_page": "4", "page": "2", }) @@ -151,7 +150,7 @@ func TestIssuesService_ListByOrg(t *testing.T) { Type: "bug", Sort: "updated", Direction: "asc", - Since: time.Date(2026, time.January, 2, 0, 0, 0, 0, time.UTC), + Since: referenceTime, ListOptions: ListOptions{Page: 2, PerPage: 4}, } issues, _, err := client.Issues.ListByOrg(ctx, "o", opts) @@ -195,7 +194,7 @@ func TestIssuesService_ListByRepo(t *testing.T) { "labels": "a,b", "sort": "updated", "direction": "asc", - "since": referenceTime.Format(time.RFC3339), + "since": referenceTimeRaw, "per_page": "1", }) fmt.Fprint(w, `[{"number":1}]`) diff --git a/github/orgs_credential_authorizations_test.go b/github/orgs_credential_authorizations_test.go index 40f35b3c4a6..8770c77c8ec 100644 --- a/github/orgs_credential_authorizations_test.go +++ b/github/orgs_credential_authorizations_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -26,8 +25,8 @@ func TestOrganizationsService_ListCredentialAuthorizations(t *testing.T) { "login": "l", "credential_id": 1, "credential_type": "t", - "credential_authorized_at": "2017-01-21T00:00:00Z", - "credential_accessed_at": "2017-01-21T00:00:00Z", + "credential_authorized_at": `+refTimeStr(1136178000)+`, + "credential_accessed_at": `+refTimeStr(1136178001)+`, "authorized_credential_id": 1 } ]`) @@ -44,14 +43,13 @@ func TestOrganizationsService_ListCredentialAuthorizations(t *testing.T) { t.Errorf("Organizations.ListCredentialAuthorizations returned error: %v", err) } - ts := time.Date(2017, time.January, 21, 0, 0, 0, 0, time.UTC) want := []*CredentialAuthorization{ { Login: Ptr("l"), CredentialID: Ptr(int64(1)), CredentialType: Ptr("t"), - CredentialAuthorizedAt: &Timestamp{ts}, - CredentialAccessedAt: &Timestamp{ts}, + CredentialAuthorizedAt: refTimestamp(1136178000), + CredentialAccessedAt: refTimestamp(1136178001), AuthorizedCredentialID: Ptr(int64(1)), }, } diff --git a/github/orgs_custom_repository_roles_test.go b/github/orgs_custom_repository_roles_test.go index e1acd7ff92b..38a2e5b4182 100644 --- a/github/orgs_custom_repository_roles_test.go +++ b/github/orgs_custom_repository_roles_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -38,8 +37,8 @@ func TestOrganizationsService_ListCustomRepoRoles(t *testing.T) { "location": "l", "email": "e" }, - "created_at": "2024-07-21T19:33:08Z", - "updated_at": "2024-07-21T19:33:08Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` } ] }`) @@ -71,8 +70,8 @@ func TestOrganizationsService_ListCustomRepoRoles(t *testing.T) { Location: Ptr("l"), Email: Ptr("e"), }, - CreatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), }, }, } @@ -118,8 +117,8 @@ func TestOrganizationsService_GetCustomRepoRole(t *testing.T) { "location": "l", "email": "e" }, - "created_at": "2024-07-21T19:33:08Z", - "updated_at": "2024-07-21T19:33:08Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` }`) }) @@ -146,8 +145,8 @@ func TestOrganizationsService_GetCustomRepoRole(t *testing.T) { Location: Ptr("l"), Email: Ptr("e"), }, - CreatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(role, want) { t.Errorf("Organizations.GetCustomRepoRole returned %+v, want %+v", role, want) diff --git a/github/orgs_issue_types_test.go b/github/orgs_issue_types_test.go index 72c1b0ae0c1..dad06d3cbf0 100644 --- a/github/orgs_issue_types_test.go +++ b/github/orgs_issue_types_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -26,16 +25,16 @@ func TestOrganizationsService_ListIssueTypes(t *testing.T) { "node_id": "IT_kwDNAd3NAZo", "name": "Task", "description": "A specific piece of work", - "created_at": "2024-12-11T14:39:09Z", - "updated_at": "2024-12-11T14:39:09Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` }, { "id": 411, "node_id": "IT_kwDNAd3NAZs", "name": "Bug", "description": "An unexpected problem or behavior", - "created_at": "2024-12-11T14:39:09Z", - "updated_at": "2024-12-11T14:39:09Z" + "created_at": `+refTimeStr(1136178002)+`, + "updated_at": `+refTimeStr(1136178003)+` } ]`) }) @@ -52,16 +51,16 @@ func TestOrganizationsService_ListIssueTypes(t *testing.T) { NodeID: Ptr("IT_kwDNAd3NAZo"), Name: Ptr("Task"), Description: Ptr("A specific piece of work"), - CreatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), - UpdatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), }, { ID: Ptr(int64(411)), NodeID: Ptr("IT_kwDNAd3NAZs"), Name: Ptr("Bug"), Description: Ptr("An unexpected problem or behavior"), - CreatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), - UpdatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), + CreatedAt: refTimestamp(1136178002), + UpdatedAt: refTimestamp(1136178003), }, } if !cmp.Equal(issueTypes, want) { @@ -103,8 +102,8 @@ func TestOrganizationsService_CreateIssueType(t *testing.T) { "node_id": "IT_kwDNAd3NAZo", "name": "Epic", "description": "An issue type for a multi-week tracking of work", - "created_at": "2024-12-11T14:39:09Z", - "updated_at": "2024-12-11T14:39:09Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` }`) }) @@ -118,8 +117,8 @@ func TestOrganizationsService_CreateIssueType(t *testing.T) { NodeID: Ptr("IT_kwDNAd3NAZo"), Name: Ptr("Epic"), Description: Ptr("An issue type for a multi-week tracking of work"), - CreatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), - UpdatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(issueType, want) { @@ -161,8 +160,8 @@ func TestOrganizationsService_UpdateIssueType(t *testing.T) { "node_id": "IT_kwDNAd3NAZo", "name": "Epic", "description": "An issue type for a multi-week tracking of work", - "created_at": "2024-12-11T14:39:09Z", - "updated_at": "2024-12-11T14:39:09Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` }`) }) @@ -176,8 +175,8 @@ func TestOrganizationsService_UpdateIssueType(t *testing.T) { NodeID: Ptr("IT_kwDNAd3NAZo"), Name: Ptr("Epic"), Description: Ptr("An issue type for a multi-week tracking of work"), - CreatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), - UpdatedAt: Ptr(Timestamp{time.Date(2024, 12, 11, 14, 39, 9, 0, time.UTC)}), + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), } if !cmp.Equal(issueType, want) { diff --git a/github/orgs_members_test.go b/github/orgs_members_test.go index 7e77f1de3bb..576620a77ec 100644 --- a/github/orgs_members_test.go +++ b/github/orgs_members_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -562,7 +561,7 @@ func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) { "login": "monalisa", "email": "octocat@github.com", "role": "direct_member", - "created_at": "2017-01-21T00:00:00Z", + "created_at": `+referenceTimeStr+`, "inviter": { "login": "other_user", "id": 1, @@ -595,14 +594,13 @@ func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) { t.Errorf("Organizations.ListPendingOrgInvitations returned error: %v", err) } - createdAt := time.Date(2017, time.January, 21, 0, 0, 0, 0, time.UTC) want := []*Invitation{ { ID: Ptr(int64(1)), Login: Ptr("monalisa"), Email: Ptr("octocat@github.com"), Role: Ptr("direct_member"), - CreatedAt: &Timestamp{createdAt}, + CreatedAt: &referenceTimestamp, Inviter: &User{ Login: Ptr("other_user"), ID: Ptr(int64(1)), @@ -767,8 +765,8 @@ func TestOrganizationsService_ListFailedOrgInvitations(t *testing.T) { "node_id":"MDQ6VXNlcjE=", "email":"octocat@github.com", "role":"direct_member", - "created_at":"2016-11-30T06:46:10Z", - "failed_at":"2017-01-02T01:10:00Z", + "created_at":`+refTimeStr(1136178000)+`, + "failed_at":`+refTimeStr(1136178001)+`, "failed_reason":"the reason", "inviter":{ "login":"other_user", @@ -803,7 +801,6 @@ func TestOrganizationsService_ListFailedOrgInvitations(t *testing.T) { t.Errorf("Organizations.ListFailedOrgInvitations returned error: %v", err) } - createdAt := time.Date(2016, time.November, 30, 6, 46, 10, 0, time.UTC) want := []*Invitation{ { ID: Ptr(int64(1)), @@ -811,9 +808,9 @@ func TestOrganizationsService_ListFailedOrgInvitations(t *testing.T) { NodeID: Ptr("MDQ6VXNlcjE="), Email: Ptr("octocat@github.com"), Role: Ptr("direct_member"), - FailedAt: &Timestamp{time.Date(2017, time.January, 2, 1, 10, 0, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + FailedAt: refTimestamp(1136178001), FailedReason: Ptr("the reason"), - CreatedAt: &Timestamp{createdAt}, Inviter: &User{ Login: Ptr("other_user"), ID: Ptr(int64(1)), diff --git a/github/orgs_network_configurations_test.go b/github/orgs_network_configurations_test.go index 5a34238b78a..cb2767cfe51 100644 --- a/github/orgs_network_configurations_test.go +++ b/github/orgs_network_configurations_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -32,7 +31,7 @@ func TestOrganizationsService_ListOrgsNetworkConfigurations(t *testing.T) { "23456789ABDCEF1", "3456789ABDCEF12" ], - "created_on": "2024-04-09T17:30:15Z" + "created_on": `+referenceTimeStr+` }, { "id": "456789ABDCEF123", @@ -42,7 +41,7 @@ func TestOrganizationsService_ListOrgsNetworkConfigurations(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345" ], - "created_on": "2024-11-02T4:30:30Z" + "created_on": `+referenceTimeStr+` }, { "id": "789ABDCEF123456", @@ -52,7 +51,7 @@ func TestOrganizationsService_ListOrgsNetworkConfigurations(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345" ], - "created_on": "2024-12-10T19:30:45Z" + "created_on": `+referenceTimeStr+` } ] }`) @@ -76,7 +75,7 @@ func TestOrganizationsService_ListOrgsNetworkConfigurations(t *testing.T) { "23456789ABDCEF1", "3456789ABDCEF12", }, - CreatedOn: &Timestamp{time.Date(2024, 4, 9, 17, 30, 15, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, }, { ID: Ptr("456789ABDCEF123"), @@ -86,7 +85,7 @@ func TestOrganizationsService_ListOrgsNetworkConfigurations(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345", }, - CreatedOn: &Timestamp{time.Date(2024, 11, 2, 4, 30, 30, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, }, { ID: Ptr("789ABDCEF123456"), @@ -96,7 +95,7 @@ func TestOrganizationsService_ListOrgsNetworkConfigurations(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345", }, - CreatedOn: &Timestamp{time.Date(2024, 12, 10, 19, 30, 45, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, }, }, } @@ -132,7 +131,7 @@ func TestOrganizationsService_CreateOrgsNetworkConfiguration(t *testing.T) { "network_settings_ids": [ "56789ABDCEF1234" ], - "created_on": "2024-11-02T4:30:30Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -158,7 +157,7 @@ func TestOrganizationsService_CreateOrgsNetworkConfiguration(t *testing.T) { NetworkSettingsIDs: []string{ "56789ABDCEF1234", }, - CreatedOn: &Timestamp{time.Date(2024, 11, 2, 4, 30, 30, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, } if !cmp.Equal(want, configuration) { @@ -253,7 +252,7 @@ func TestOrganizationsService_GetOrgsNetworkConfiguration(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345" ], - "created_on": "2024-12-10T19:30:45Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -271,7 +270,7 @@ func TestOrganizationsService_GetOrgsNetworkConfiguration(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345", }, - CreatedOn: &Timestamp{time.Date(2024, 12, 10, 19, 30, 45, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, } if !cmp.Equal(want, configuration) { t.Errorf("Organizations.GetNetworkConfiguration mismatch (-want +got):\n%v", cmp.Diff(want, configuration)) @@ -306,7 +305,7 @@ func TestOrganizationsService_UpdateOrgsNetworkConfiguration(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345" ], - "created_on": "2024-12-10T19:30:45Z" + "created_on": `+referenceTimeStr+` }`) }) @@ -332,7 +331,7 @@ func TestOrganizationsService_UpdateOrgsNetworkConfiguration(t *testing.T) { "56789ABDCEF1234", "6789ABDCEF12345", }, - CreatedOn: &Timestamp{time.Date(2024, 12, 10, 19, 30, 45, 0, time.UTC)}, + CreatedOn: &referenceTimestamp, } if !cmp.Equal(want, configuration) { t.Errorf("Organizations.UpdateNetworkConfiguration mismatch (-want +got):\n%v", cmp.Diff(want, configuration)) diff --git a/github/orgs_organization_roles_test.go b/github/orgs_organization_roles_test.go index 4b5c0ce0180..e1300ad5356 100644 --- a/github/orgs_organization_roles_test.go +++ b/github/orgs_organization_roles_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -37,8 +36,8 @@ func TestOrganizationsService_ListRoles(t *testing.T) { "location": "l", "email": "e" }, - "created_at": "2024-07-21T19:33:08Z", - "updated_at": "2024-07-21T19:33:08Z", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "source": "Organization", "base_role": "admin" } @@ -71,8 +70,8 @@ func TestOrganizationsService_ListRoles(t *testing.T) { Location: Ptr("l"), Email: Ptr("e"), }, - CreatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Source: Ptr("Organization"), BaseRole: Ptr("admin"), }, @@ -109,8 +108,8 @@ func TestOrganizationsService_GetOrgRole(t *testing.T) { "name": "all_repo_read", "description": "Grants read access to all repositories in the organization.", "permissions": [], - "created_at": `+referenceTimeStr+`, - "updated_at": `+referenceTimeStr+`, + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "source": "Predefined", "base_role": "read" }`) @@ -128,8 +127,8 @@ func TestOrganizationsService_GetOrgRole(t *testing.T) { Name: Ptr("all_repo_read"), Description: Ptr("Grants read access to all repositories in the organization."), Permissions: []string{}, - CreatedAt: &Timestamp{referenceTime}, - UpdatedAt: &Timestamp{referenceTime}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Source: Ptr("Predefined"), BaseRole: Ptr("read"), } @@ -150,8 +149,8 @@ func TestOrganizationsService_GetOrgRole(t *testing.T) { "read_organization_custom_repo_role", "write_organization_custom_org_role" ], - "created_at": `+referenceTimeStr+`, - "updated_at": `+referenceTimeStr+`, + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "source": "Organization", "base_role": null }`) @@ -171,8 +170,8 @@ func TestOrganizationsService_GetOrgRole(t *testing.T) { "read_organization_custom_repo_role", "write_organization_custom_org_role", }, - CreatedAt: &Timestamp{referenceTime}, - UpdatedAt: &Timestamp{referenceTime}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Source: Ptr("Organization"), BaseRole: nil, } diff --git a/github/orgs_personal_access_tokens_test.go b/github/orgs_personal_access_tokens_test.go index 0cbc2ba1486..b2d82399cbb 100644 --- a/github/orgs_personal_access_tokens_test.go +++ b/github/orgs_personal_access_tokens_test.go @@ -10,7 +10,6 @@ import ( "net/http" "net/url" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -63,9 +62,9 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokens(t *testing.T) "metadata": "read" } }, - "access_granted_at": "2023-05-16T08:47:09.000-07:00", + "access_granted_at": `+refTimeStr(1136178000)+`, "token_expired": false, - "token_expires_at": "2023-11-16T08:47:09.000-07:00", + "token_expires_at": `+refTimeStr(1136178001)+`, "token_last_used_at": null } ]`) @@ -112,9 +111,9 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokens(t *testing.T) Org: map[string]string{"members": "read"}, Repo: map[string]string{"metadata": "read"}, }, - AccessGrantedAt: &Timestamp{time.Date(2023, time.May, 16, 8, 47, 9, 0, time.FixedZone("PDT", -7*60*60))}, + AccessGrantedAt: refTimestamp(1136178000), TokenExpired: Ptr(false), - TokenExpiresAt: &Timestamp{time.Date(2023, time.November, 16, 8, 47, 9, 0, time.FixedZone("PDT", -7*60*60))}, + TokenExpiresAt: refTimestamp(1136178001), TokenLastUsedAt: nil, }, } @@ -210,11 +209,11 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test "metadata": "read" } }, - "created_at": "2026-02-17T06:49:30Z", + "created_at": `+refTimeStr(1136178000)+`, "token_id": 11579703, "token_name": "testFineGrained", "token_expired": false, - "token_expires_at": "2026-04-18T06:49:30Z", + "token_expires_at": `+refTimeStr(1136178001)+`, "token_last_used_at": null } ]`) @@ -262,11 +261,11 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test Permissions: PersonalAccessTokenPermissions{ Repo: map[string]string{"metadata": "read"}, }, - CreatedAt: &Timestamp{time.Date(2026, time.February, 17, 6, 49, 30, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), TokenID: 11579703, TokenName: "testFineGrained", TokenExpired: false, - TokenExpiresAt: &Timestamp{time.Date(2026, time.April, 18, 6, 49, 30, 0, time.UTC)}, + TokenExpiresAt: refTimestamp(1136178001), TokenLastUsedAt: nil, }, } diff --git a/github/private_registries_test.go b/github/private_registries_test.go index fccb6af0b25..ec0500ef7dd 100644 --- a/github/private_registries_test.go +++ b/github/private_registries_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -32,8 +31,8 @@ func TestPrivateRegistriesService_ListOrganizationPrivateRegistries(t *testing.T "name": "MAVEN_REPOSITORY_SECRET", "registry_type": "maven_repository", "username": "monalisa", - "created_at": "2019-08-10T14:59:22Z", - "updated_at": "2020-01-10T14:59:22Z", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "visibility": "selected" } ] @@ -54,8 +53,8 @@ func TestPrivateRegistriesService_ListOrganizationPrivateRegistries(t *testing.T Name: Ptr("MAVEN_REPOSITORY_SECRET"), RegistryType: Ptr(PrivateRegistryTypeMavenRepository), Username: Ptr("monalisa"), - CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Visibility: Ptr(PrivateRegistryVisibilitySelected), }, }, @@ -110,8 +109,8 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry(t *testing.T "username": "monalisa", "visibility": "selected", "selected_repository_ids": [1, 2, 3], - "created_at": "2019-08-10T14:59:22Z", - "updated_at": "2020-01-10T14:59:22Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` }`) }) @@ -125,8 +124,8 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry(t *testing.T Name: Ptr("MAVEN_REPOSITORY_SECRET"), RegistryType: Ptr(PrivateRegistryTypeMavenRepository), Username: Ptr("monalisa"), - CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Visibility: Ptr(PrivateRegistryVisibilitySelected), SelectedRepositoryIDs: []int64{1, 2, 3}, } @@ -174,8 +173,8 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDC(t *test "registry_type": "maven_repository", "visibility": "selected", "selected_repository_ids": [1, 2, 3], - "created_at": "2019-08-10T14:59:22Z", - "updated_at": "2020-01-10T14:59:22Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` }`) }) @@ -188,8 +187,8 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDC(t *test want := &PrivateRegistry{ Name: Ptr("MAVEN_REPOSITORY_SECRET"), RegistryType: Ptr(PrivateRegistryTypeMavenRepository), - CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Visibility: Ptr(PrivateRegistryVisibilitySelected), SelectedRepositoryIDs: []int64{1, 2, 3}, } @@ -250,8 +249,8 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDCJFrog(t "name": "NPM_REGISTRY_SECRET", "registry_type": "npm_registry", "visibility": "private", - "created_at": "2019-08-10T14:59:22Z", - "updated_at": "2020-01-10T14:59:22Z" + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+` }`) }) @@ -264,8 +263,8 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDCJFrog(t want := &PrivateRegistry{ Name: Ptr("NPM_REGISTRY_SECRET"), RegistryType: Ptr(PrivateRegistryTypeNpmRegistry), - CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Visibility: Ptr(PrivateRegistryVisibilityPrivate), } if diff := cmp.Diff(want, privateRegistry); diff != "" { @@ -325,8 +324,8 @@ func TestPrivateRegistriesService_GetOrganizationPrivateRegistry(t *testing.T) { "name": "MAVEN_REPOSITORY_SECRET", "registry_type": "maven_repository", "username": "monalisa", - "created_at": "2019-08-10T14:59:22Z", - "updated_at": "2020-01-10T14:59:22Z", + "created_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, "visibility": "selected" }`) }) @@ -340,8 +339,8 @@ func TestPrivateRegistriesService_GetOrganizationPrivateRegistry(t *testing.T) { Name: Ptr("MAVEN_REPOSITORY_SECRET"), RegistryType: Ptr(PrivateRegistryTypeMavenRepository), Username: Ptr("monalisa"), - CreatedAt: &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), Visibility: Ptr(PrivateRegistryVisibilitySelected), } if diff := cmp.Diff(want, privateRegistry); diff != "" { diff --git a/github/projects_test.go b/github/projects_test.go index 296b4bf8dba..d786d279de2 100644 --- a/github/projects_test.go +++ b/github/projects_test.go @@ -11,7 +11,6 @@ import ( "fmt" "net/http" "testing" - "time" ) func TestProjectsService_ListOrganizationProjects(t *testing.T) { @@ -1094,7 +1093,7 @@ func TestProjectV2Item_UnmarshalJSON_Issue(t *testing.T) { }, }, }, - CreatedAt: &Timestamp{time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, } want := `{ @@ -1112,7 +1111,7 @@ func TestProjectV2Item_UnmarshalJSON_Issue(t *testing.T) { "name": "test-repo" } }, - "created_at": "2023-01-01T00:00:00Z" + "created_at": ` + referenceTimeStr + ` }` testJSONUnmarshalOnly(t, item, want) @@ -1143,7 +1142,7 @@ func TestProjectV2Item_UnmarshalJSON_PullRequest(t *testing.T) { }, }, }, - CreatedAt: &Timestamp{time.Date(2023, 1, 2, 0, 0, 0, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, } want := `{ @@ -1166,7 +1165,7 @@ func TestProjectV2Item_UnmarshalJSON_PullRequest(t *testing.T) { "sha": "ghi789" } }, - "created_at": "2023-01-02T00:00:00Z" + "created_at": ` + referenceTimeStr + ` }` testJSONUnmarshalOnly(t, item, want) @@ -1187,7 +1186,7 @@ func TestProjectV2Item_UnmarshalJSON_DraftIssue(t *testing.T) { Body: Ptr("Draft issue body content"), }, }, - CreatedAt: &Timestamp{time.Date(2023, 1, 3, 0, 0, 0, 0, time.UTC)}, + CreatedAt: &referenceTimestamp, } want := `{ @@ -1200,7 +1199,7 @@ func TestProjectV2Item_UnmarshalJSON_DraftIssue(t *testing.T) { "title": "Draft Issue Title", "body": "Draft issue body content" }, - "created_at": "2023-01-03T00:00:00Z" + "created_at": ` + referenceTimeStr + ` }` testJSONUnmarshalOnly(t, item, want) diff --git a/github/pulls_comments_test.go b/github/pulls_comments_test.go index cdb11eab420..1171b6bf2d7 100644 --- a/github/pulls_comments_test.go +++ b/github/pulls_comments_test.go @@ -10,7 +10,6 @@ import ( "net/http" "strings" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -26,7 +25,7 @@ func TestPullRequestsService_ListComments_allPulls(t *testing.T) { testFormValues(t, r, values{ "sort": "updated", "direction": "desc", - "since": "2002-02-10T15:30:00Z", + "since": referenceTimeRaw, "page": "2", }) fmt.Fprint(w, `[{"id":1}]`) @@ -35,7 +34,7 @@ func TestPullRequestsService_ListComments_allPulls(t *testing.T) { opt := &PullRequestListCommentsOptions{ Sort: "updated", Direction: "desc", - Since: time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), + Since: referenceTime, ListOptions: ListOptions{Page: 2}, } ctx := t.Context() diff --git a/github/rate_limit_test.go b/github/rate_limit_test.go index 5c90948ecae..67fde2194c4 100644 --- a/github/rate_limit_test.go +++ b/github/rate_limit_test.go @@ -69,73 +69,73 @@ func TestRateLimits(t *testing.T) { Limit: 2, Remaining: 1, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700873), }, Search: &Rate{ Limit: 3, Remaining: 2, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 54, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700874), }, GraphQL: &Rate{ Limit: 4, Remaining: 3, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 55, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700875), }, IntegrationManifest: &Rate{ Limit: 5, Remaining: 4, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 56, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700876), }, SourceImport: &Rate{ Limit: 6, Remaining: 5, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 57, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700877), }, CodeScanningUpload: &Rate{ Limit: 7, Remaining: 6, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 58, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700878), }, ActionsRunnerRegistration: &Rate{ Limit: 8, Remaining: 7, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 59, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700879), }, SCIM: &Rate{ Limit: 9, Remaining: 8, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 0, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700880), }, DependencySnapshots: &Rate{ Limit: 10, Remaining: 9, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 1, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700881), }, CodeSearch: &Rate{ Limit: 11, Remaining: 10, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 2, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700882), }, AuditLog: &Rate{ Limit: 12, Remaining: 11, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 3, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700883), }, DependencySBOM: &Rate{ Limit: 100, Remaining: 100, Used: 0, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 4, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700884), }, } if !cmp.Equal(rate, want) { @@ -253,73 +253,73 @@ func TestRateLimits_overQuota(t *testing.T) { Limit: 2, Remaining: 1, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700873), }, Search: &Rate{ Limit: 3, Remaining: 2, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 54, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700874), }, GraphQL: &Rate{ Limit: 4, Remaining: 3, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 55, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700875), }, IntegrationManifest: &Rate{ Limit: 5, Remaining: 4, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 56, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700876), }, SourceImport: &Rate{ Limit: 6, Remaining: 5, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 57, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700877), }, CodeScanningUpload: &Rate{ Limit: 7, Remaining: 6, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 58, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700878), }, ActionsRunnerRegistration: &Rate{ Limit: 8, Remaining: 7, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 47, 59, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700879), }, SCIM: &Rate{ Limit: 9, Remaining: 8, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 0, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700880), }, DependencySnapshots: &Rate{ Limit: 10, Remaining: 9, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 1, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700881), }, CodeSearch: &Rate{ Limit: 11, Remaining: 10, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 2, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700882), }, AuditLog: &Rate{ Limit: 12, Remaining: 11, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 3, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700883), }, DependencySBOM: &Rate{ Limit: 13, Remaining: 12, Used: 1, - Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 4, 0, time.UTC).Local()}, + Reset: *refTimestamp(1372700884), }, } if !cmp.Equal(rate, want) { diff --git a/github/repos_commits_test.go b/github/repos_commits_test.go index a6b64b3a7f3..1ca3c1f4338 100644 --- a/github/repos_commits_test.go +++ b/github/repos_commits_test.go @@ -28,8 +28,8 @@ func TestRepositoriesService_ListCommits(t *testing.T) { "sha": "s", "path": "p", "author": "a", - "since": "2013-08-01T00:00:00Z", - "until": "2013-09-03T00:00:00Z", + "since": referenceTimeRaw, + "until": "2007-03-04T15:04:05Z", }) fmt.Fprint(w, `[{"sha": "s"}]`) }) @@ -38,8 +38,8 @@ func TestRepositoriesService_ListCommits(t *testing.T) { SHA: "s", Path: "p", Author: "a", - Since: time.Date(2013, time.August, 1, 0, 0, 0, 0, time.UTC), - Until: time.Date(2013, time.September, 3, 0, 0, 0, 0, time.UTC), + Since: referenceTime, + Until: time.Date(2007, time.March, 4, 15, 4, 5, 0, time.UTC), } ctx := t.Context() commits, _, err := client.Repositories.ListCommits(ctx, "o", "r", opt) diff --git a/github/repos_community_health_test.go b/github/repos_community_health_test.go index 87a10cf1492..19705d5ee6c 100644 --- a/github/repos_community_health_test.go +++ b/github/repos_community_health_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -60,7 +59,7 @@ func TestRepositoriesService_GetCommunityHealthMetrics(t *testing.T) { "html_url": "https://github.com/octocat/Hello-World/blob/master/README.md" } }, - "updated_at": "2017-02-28T00:00:00Z", + "updated_at": `+referenceTimeStr+`, "content_reports_enabled": true }`) }) @@ -71,11 +70,10 @@ func TestRepositoriesService_GetCommunityHealthMetrics(t *testing.T) { t.Errorf("Repositories.GetCommunityHealthMetrics returned error: %v", err) } - updatedAt := time.Date(2017, time.February, 28, 0, 0, 0, 0, time.UTC) want := &CommunityHealthMetrics{ HealthPercentage: Ptr(100), Description: Ptr("My first repository on GitHub!"), - UpdatedAt: &Timestamp{updatedAt}, + UpdatedAt: &referenceTimestamp, ContentReportsEnabled: Ptr(true), Files: &CommunityHealthFiles{ CodeOfConduct: &Metric{ diff --git a/github/repos_stats_test.go b/github/repos_stats_test.go index 3968f591e5c..77eb5e23d2b 100644 --- a/github/repos_stats_test.go +++ b/github/repos_stats_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -32,7 +31,7 @@ func TestRepositoriesService_ListContributorsStats(t *testing.T) { "total": 135, "weeks": [ { - "w": 1367712000, + "w": `+referenceUnixTimeStr+`, "a": 6898, "d": 77, "c": 10 @@ -58,7 +57,7 @@ func TestRepositoriesService_ListContributorsStats(t *testing.T) { Total: Ptr(135), Weeks: []*WeeklyStats{ { - Week: &Timestamp{time.Date(2013, time.May, 5, 0, 0, 0, 0, time.UTC).Local()}, + Week: &referenceTimestamp, Additions: Ptr(6898), Deletions: Ptr(77), Commits: Ptr(10), @@ -98,7 +97,7 @@ func TestRepositoriesService_ListCommitActivity(t *testing.T) { { "days": [0, 3, 26, 20, 39, 1, 0], "total": 89, - "week": 1336280400 + "week": `+referenceUnixTimeStr+` } ] `) @@ -114,7 +113,7 @@ func TestRepositoriesService_ListCommitActivity(t *testing.T) { { Days: []int{0, 3, 26, 20, 39, 1, 0}, Total: Ptr(89), - Week: &Timestamp{time.Date(2012, time.May, 6, 5, 0, 0, 0, time.UTC).Local()}, + Week: &referenceTimestamp, }, } @@ -144,7 +143,7 @@ func TestRepositoriesService_ListCodeFrequency(t *testing.T) { mux.HandleFunc("/repos/o/r/stats/code_frequency", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `[[1302998400, 1124, -435]]`) + fmt.Fprint(w, `[[`+referenceUnixTimeStr+`, 1124, -435]]`) }) ctx := t.Context() @@ -154,7 +153,7 @@ func TestRepositoriesService_ListCodeFrequency(t *testing.T) { } want := []*WeeklyStats{{ - Week: &Timestamp{time.Date(2011, time.April, 17, 0, 0, 0, 0, time.UTC).Local()}, + Week: &referenceTimestamp, Additions: Ptr(1124), Deletions: Ptr(-435), }} diff --git a/github/repos_test.go b/github/repos_test.go index bc8211fd15c..cd206c654e1 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -13,7 +13,6 @@ import ( "net/url" "strings" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -4279,7 +4278,7 @@ func TestRepositoriesService_ListRepositoryActivities(t *testing.T) { "before": "abc123def456", "after": "def456ghi789", "ref": "refs/heads/main", - "timestamp": "2023-01-01T12:00:00Z", + "timestamp": `+referenceTimeStr+`, "activity_type": "push", "actor": { "login": "testuser1", @@ -4309,7 +4308,7 @@ func TestRepositoriesService_ListRepositoryActivities(t *testing.T) { "before": "def456ghi789", "after": "ghi789jkl012", "ref": "refs/heads/feature", - "timestamp": "2023-01-01T11:30:00Z", + "timestamp": `+referenceTimeStr+`, "activity_type": "branch_deletion", "actor": { "login": "testuser2", @@ -4350,7 +4349,7 @@ func TestRepositoriesService_ListRepositoryActivities(t *testing.T) { Before: "abc123def456", After: "def456ghi789", Ref: "refs/heads/main", - Timestamp: &Timestamp{Time: time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)}, + Timestamp: &referenceTimestamp, ActivityType: "push", Actor: &RepositoryActor{ Login: Ptr("testuser1"), @@ -4380,7 +4379,7 @@ func TestRepositoriesService_ListRepositoryActivities(t *testing.T) { Before: "def456ghi789", After: "ghi789jkl012", Ref: "refs/heads/feature", - Timestamp: &Timestamp{Time: time.Date(2023, 1, 1, 11, 30, 0, 0, time.UTC)}, + Timestamp: &referenceTimestamp, ActivityType: "branch_deletion", Actor: &RepositoryActor{ Login: Ptr("testuser2"), @@ -4433,8 +4432,8 @@ func TestRepositoriesService_ListRepositoryActivities_withOptions(t *testing.T) testMethod(t, r, "GET") testFormValues(t, r, values{ "direction": "desc", - "before": "2023-01-01T12:00:00Z", - "after": "2023-01-01T11:30:00Z", + "before": refTimeStr(1136178000), + "after": refTimeStr(1136178001), "ref": "refs/heads/main", "actor": "testuser1", "time_period": "day", @@ -4448,7 +4447,7 @@ func TestRepositoriesService_ListRepositoryActivities_withOptions(t *testing.T) "before": "abc123def456", "after": "def456ghi789", "ref": "refs/heads/main", - "timestamp": "2023-01-01T12:00:00Z", + "timestamp": `+referenceTimeStr+`, "activity_type": "push", "actor": { "login": "testuser1", @@ -4477,8 +4476,8 @@ func TestRepositoriesService_ListRepositoryActivities_withOptions(t *testing.T) opts := &ListRepositoryActivityOptions{ Direction: "desc", - Before: "2023-01-01T12:00:00Z", - After: "2023-01-01T11:30:00Z", + Before: refTimeStr(1136178000), + After: refTimeStr(1136178001), Ref: "refs/heads/main", Actor: "testuser1", TimePeriod: "day", @@ -4498,7 +4497,7 @@ func TestRepositoriesService_ListRepositoryActivities_withOptions(t *testing.T) Before: "abc123def456", After: "def456ghi789", Ref: "refs/heads/main", - Timestamp: &Timestamp{Time: time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)}, + Timestamp: &referenceTimestamp, ActivityType: "push", Actor: &RepositoryActor{ Login: Ptr("testuser1"), diff --git a/github/repos_traffic_test.go b/github/repos_traffic_test.go index d01d5b87320..3578739fbe3 100644 --- a/github/repos_traffic_test.go +++ b/github/repos_traffic_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -109,7 +108,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) { fmt.Fprint(w, `{"count": 7, "uniques": 6, "views": [{ - "timestamp": "2016-05-31T16:00:00.000Z", + "timestamp": `+referenceTimeStr+`, "count": 7, "uniques": 6 }]}`) @@ -123,7 +122,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) { want := &TrafficViews{ Views: []*TrafficData{{ - Timestamp: &Timestamp{time.Date(2016, time.May, 31, 16, 0, 0, 0, time.UTC)}, + Timestamp: &referenceTimestamp, Count: Ptr(7), Uniques: Ptr(6), }}, @@ -159,7 +158,7 @@ func TestRepositoriesService_ListTrafficClones(t *testing.T) { fmt.Fprint(w, `{"count": 7, "uniques": 6, "clones": [{ - "timestamp": "2016-05-31T16:00:00.00Z", + "timestamp": `+referenceTimeStr+`, "count": 7, "uniques": 6 }]}`) @@ -173,7 +172,7 @@ func TestRepositoriesService_ListTrafficClones(t *testing.T) { want := &TrafficClones{ Clones: []*TrafficData{{ - Timestamp: &Timestamp{time.Date(2016, time.May, 31, 16, 0, 0, 0, time.UTC)}, + Timestamp: &referenceTimestamp, Count: Ptr(7), Uniques: Ptr(6), }}, diff --git a/github/scim_test.go b/github/scim_test.go index 115bc896092..a26a3cb17c1 100644 --- a/github/scim_test.go +++ b/github/scim_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -53,8 +52,8 @@ func TestSCIMService_ListSCIMProvisionedIdentities(t *testing.T) { "active": true, "meta": { "resourceType": "User", - "created": "2018-02-13T15:05:24.000-00:00", - "lastModified": "2018-02-13T15:05:24.000-00:00", + "created": ` + refTimeStr(1136178000) + `, + "lastModified": ` + refTimeStr(1136178001) + `, "location": "https://api.github.com/scim/v2/organizations/octo-org/Users/5fc0c238-1112-11e8-8e45-920c87bdbd75" } } @@ -73,7 +72,6 @@ func TestSCIMService_ListSCIMProvisionedIdentities(t *testing.T) { t.Errorf("SCIM.ListSCIMProvisionedIdentities returned error: %v", err) } - date := Timestamp{time.Date(2018, time.February, 13, 15, 5, 24, 0, time.UTC)} want := SCIMProvisionedIdentities{ Schemas: []string{"urn:ietf:params:scim:api:messages:2.0:ListResponse"}, TotalResults: Ptr(1), @@ -84,8 +82,8 @@ func TestSCIMService_ListSCIMProvisionedIdentities(t *testing.T) { ID: Ptr("5fc0c238-1112-11e8-8e45-920c87bdbd75"), Meta: &SCIMMeta{ ResourceType: Ptr("User"), - Created: &date, - LastModified: &date, + Created: refTimestamp(1136178000), + LastModified: refTimestamp(1136178001), Location: Ptr("https://api.github.com/scim/v2/organizations/octo-org/Users/5fc0c238-1112-11e8-8e45-920c87bdbd75"), }, UserName: "octocat@github.com", @@ -209,8 +207,8 @@ func TestSCIMService_GetSCIMProvisioningInfoForUser(t *testing.T) { "active": true, "meta": { "resourceType": "User", - "created": "2017-03-09T16:11:13-00:00", - "lastModified": "2017-03-09T16:11:13-00:00", + "created": ` + refTimeStr(1136178000) + `, + "lastModified": ` + refTimeStr(1136178001) + `, "location": "https://api.github.com/scim/v2/organizations/octo-org/Users/edefdfedf-050c-11e7-8d32" } }`)) @@ -222,13 +220,12 @@ func TestSCIMService_GetSCIMProvisioningInfoForUser(t *testing.T) { t.Errorf("SCIM.GetSCIMProvisioningInfoForUser returned error: %v", err) } - date := Timestamp{time.Date(2017, time.March, 9, 16, 11, 13, 0, time.UTC)} want := SCIMUserAttributes{ ID: Ptr("edefdfedf-050c-11e7-8d32"), Meta: &SCIMMeta{ ResourceType: Ptr("User"), - Created: &date, - LastModified: &date, + Created: refTimestamp(1136178000), + LastModified: refTimestamp(1136178001), Location: Ptr("https://api.github.com/scim/v2/organizations/octo-org/Users/edefdfedf-050c-11e7-8d32"), }, UserName: "mona.octocat@okta.example.com", diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index 651d1f5ab0a..852e3da073f 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -24,7 +23,7 @@ func TestSecretScanningService_ListAlertsForEnterprise(t *testing.T) { fmt.Fprint(w, `[{ "number": 1, - "created_at": "1996-06-20T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", "html_url": "https://github.com/o/r/security/secret-scanning/1", "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", @@ -50,11 +49,10 @@ func TestSecretScanningService_ListAlertsForEnterprise(t *testing.T) { t.Errorf("SecretScanning.ListAlertsForEnterprise returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := []*SecretScanningAlert{ { Number: Ptr(1), - CreatedAt: &date, + CreatedAt: refTimestamp(1136178000), URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), @@ -99,7 +97,7 @@ func TestSecretScanningService_ListAlertsForOrg(t *testing.T) { fmt.Fprint(w, `[{ "number": 1, - "created_at": "1996-06-20T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", "html_url": "https://github.com/o/r/security/secret-scanning/1", "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", @@ -120,11 +118,10 @@ func TestSecretScanningService_ListAlertsForOrg(t *testing.T) { t.Errorf("SecretScanning.ListAlertsForOrg returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := []*SecretScanningAlert{ { Number: Ptr(1), - CreatedAt: &date, + CreatedAt: refTimestamp(1136178000), URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), @@ -164,7 +161,7 @@ func TestSecretScanningService_ListAlertsForOrgListOptions(t *testing.T) { fmt.Fprint(w, `[{ "number": 1, - "created_at": "1996-06-20T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", "html_url": "https://github.com/o/r/security/secret-scanning/1", "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", @@ -187,11 +184,10 @@ func TestSecretScanningService_ListAlertsForOrgListOptions(t *testing.T) { t.Errorf("SecretScanning.ListAlertsForOrg returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := []*SecretScanningAlert{ { Number: Ptr(1), - CreatedAt: &date, + CreatedAt: refTimestamp(1136178000), URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), @@ -231,7 +227,7 @@ func TestSecretScanningService_ListAlertsForRepo(t *testing.T) { fmt.Fprint(w, `[{ "number": 1, - "created_at": "1996-06-20T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", "html_url": "https://github.com/o/r/security/secret-scanning/1", "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", @@ -252,11 +248,10 @@ func TestSecretScanningService_ListAlertsForRepo(t *testing.T) { t.Errorf("SecretScanning.ListAlertsForRepo returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := []*SecretScanningAlert{ { Number: Ptr(1), - CreatedAt: &date, + CreatedAt: refTimestamp(1136178000), URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), @@ -295,7 +290,7 @@ func TestSecretScanningService_GetAlert(t *testing.T) { fmt.Fprint(w, `{ "number": 1, - "created_at": "1996-06-20T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", "html_url": "https://github.com/o/r/security/secret-scanning/1", "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", @@ -315,10 +310,9 @@ func TestSecretScanningService_GetAlert(t *testing.T) { t.Errorf("SecretScanning.GetAlert returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := &SecretScanningAlert{ Number: Ptr(1), - CreatedAt: &date, + CreatedAt: refTimestamp(1136178000), URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), @@ -358,14 +352,14 @@ func TestSecretScanningService_UpdateAlert(t *testing.T) { testJSONBody(t, r, opts) fmt.Fprint(w, `{ "number": 1, - "created_at": "1996-06-20T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", "html_url": "https://github.com/o/r/security/secret-scanning/1", "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", "state": "resolved", "resolution": "used_in_tests", "resolution_comment": "resolution comment", - "resolved_at": "1996-06-20T00:00:00Z", + "resolved_at": `+refTimeStr(1136178001)+`, "resolved_by": null, "secret_type": "mailchimp_api_key", "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2" @@ -378,17 +372,16 @@ func TestSecretScanningService_UpdateAlert(t *testing.T) { t.Errorf("SecretScanning.UpdateAlert returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := &SecretScanningAlert{ Number: Ptr(1), - CreatedAt: &date, + CreatedAt: refTimestamp(1136178000), URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), State: Ptr("resolved"), Resolution: Ptr("used_in_tests"), ResolutionComment: Ptr("resolution comment"), - ResolvedAt: &date, + ResolvedAt: refTimestamp(1136178001), ResolvedBy: nil, SecretType: Ptr("mailchimp_api_key"), Secret: Ptr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), @@ -490,7 +483,7 @@ func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) { testJSONBody(t, r, opts) fmt.Fprint(w, `{ "reason": "valid reason", - "expire_at": "2018-01-01T00:00:00Z", + "expire_at": `+refTimeStr(1136178000)+`, "token_type": "github_token" }`) }) @@ -502,10 +495,9 @@ func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) { t.Errorf("SecretScanning.CreatePushProtectionBypass returned error: %v", err) } - expireTime := Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} want := &PushProtectionBypass{ Reason: "valid reason", - ExpireAt: &expireTime, + ExpireAt: refTimestamp(1136178000), TokenType: "github_token", } @@ -537,8 +529,8 @@ func TestSecretScanningService_GetScanHistory(t *testing.T) { { "type": "incremental", "status": "success", - "completed_at": "2025-07-29T10:00:00Z", - "started_at": "2025-07-29T09:55:00Z" + "completed_at": `+refTimeStr(1136178000)+`, + "started_at": `+refTimeStr(1136178001)+` } ], "backfill_scans": [], @@ -548,7 +540,7 @@ func TestSecretScanningService_GetScanHistory(t *testing.T) { "type": "custom_backfill", "status": "in_progress", "completed_at": null, - "started_at": "2025-07-29T09:00:00Z", + "started_at": `+refTimeStr(1136178002)+`, "pattern_slug": "my-custom-pattern", "pattern_scope": "organization" } @@ -563,19 +555,15 @@ func TestSecretScanningService_GetScanHistory(t *testing.T) { t.Errorf("SecretScanning.GetScanHistory returned error: %v", err) } - incrementalScanStartAt := Timestamp{time.Date(2025, time.July, 29, 9, 55, 0, 0, time.UTC)} - incrementalScancompleteAt := Timestamp{time.Date(2025, time.July, 29, 10, 0, 0, 0, time.UTC)} - customPatternBackfillScanStartedAt := Timestamp{time.Date(2025, time.July, 29, 9, 0, 0, 0, time.UTC)} - want := &SecretScanningScanHistory{ IncrementalScans: []*SecretsScan{ - {Type: "incremental", Status: "success", CompletedAt: &incrementalScancompleteAt, StartedAt: &incrementalScanStartAt}, + {Type: "incremental", Status: "success", CompletedAt: refTimestamp(1136178000), StartedAt: refTimestamp(1136178001)}, }, BackfillScans: []*SecretsScan{}, PatternUpdateScans: []*SecretsScan{}, CustomPatternBackfillScans: []*CustomPatternBackfillScan{ { - SecretsScan: SecretsScan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: &customPatternBackfillScanStartedAt}, + SecretsScan: SecretsScan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: refTimestamp(1136178002)}, PatternSlug: Ptr("my-custom-pattern"), PatternScope: Ptr("organization"), }, diff --git a/github/security_advisories_test.go b/github/security_advisories_test.go index 0890763c25b..a5135a76b06 100644 --- a/github/security_advisories_test.go +++ b/github/security_advisories_test.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -87,9 +86,9 @@ func TestSecurityAdvisoriesService_CreateTemporaryPrivateFork(t *testing.T) { "name": "repo-ghsa-xxxx-xxxx-xxxx", "full_name": "owner/repo-ghsa-xxxx-xxxx-xxxx", "default_branch": "master", - "created_at": "2023-12-08T17:22:41Z", - "pushed_at": "2023-12-03T11:27:08Z", - "updated_at": "2023-12-08T17:22:42Z", + "created_at": `+refTimeStr(1136178000)+`, + "pushed_at": `+refTimeStr(1136178001)+`, + "updated_at": `+refTimeStr(1136178002)+`, "html_url": "https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx", "clone_url": "https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git", "git_url": "git://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git", @@ -196,9 +195,9 @@ func TestSecurityAdvisoriesService_CreateTemporaryPrivateFork(t *testing.T) { Name: Ptr("repo-ghsa-xxxx-xxxx-xxxx"), FullName: Ptr("owner/repo-ghsa-xxxx-xxxx-xxxx"), DefaultBranch: Ptr("master"), - CreatedAt: &Timestamp{time.Date(2023, time.December, 8, 17, 22, 41, 0, time.UTC)}, - PushedAt: &Timestamp{time.Date(2023, time.December, 3, 11, 27, 8, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2023, time.December, 8, 17, 22, 42, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + PushedAt: refTimestamp(1136178001), + UpdatedAt: refTimestamp(1136178002), HTMLURL: Ptr("https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx"), CloneURL: Ptr("https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git"), GitURL: Ptr("git://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git"), @@ -323,9 +322,9 @@ func TestSecurityAdvisoriesService_CreateTemporaryPrivateFork_deferred(t *testin "name": "repo-ghsa-xxxx-xxxx-xxxx", "full_name": "owner/repo-ghsa-xxxx-xxxx-xxxx", "default_branch": "master", - "created_at": "2023-12-08T17:22:41Z", - "pushed_at": "2023-12-03T11:27:08Z", - "updated_at": "2023-12-08T17:22:42Z", + "created_at": `+refTimeStr(1136178000)+`, + "pushed_at": `+refTimeStr(1136178001)+`, + "updated_at": `+refTimeStr(1136178002)+`, "html_url": "https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx", "clone_url": "https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git", "git_url": "git://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git", @@ -432,9 +431,9 @@ func TestSecurityAdvisoriesService_CreateTemporaryPrivateFork_deferred(t *testin Name: Ptr("repo-ghsa-xxxx-xxxx-xxxx"), FullName: Ptr("owner/repo-ghsa-xxxx-xxxx-xxxx"), DefaultBranch: Ptr("master"), - CreatedAt: &Timestamp{time.Date(2023, time.December, 8, 17, 22, 41, 0, time.UTC)}, - PushedAt: &Timestamp{time.Date(2023, time.December, 3, 11, 27, 8, 0, time.UTC)}, - UpdatedAt: &Timestamp{time.Date(2023, time.December, 8, 17, 22, 42, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), + PushedAt: refTimestamp(1136178001), + UpdatedAt: refTimestamp(1136178002), HTMLURL: Ptr("https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx"), CloneURL: Ptr("https://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git"), GitURL: Ptr("git://github.com/owner/repo-ghsa-xxxx-xxxx-xxxx.git"), @@ -774,10 +773,10 @@ func TestListGlobalSecurityAdvisories(t *testing.T) { } ], "references": ["https://nvd.nist.gov/vuln/detail/CVE-xoxo-1234"], - "published_at": "1996-06-20T00:00:00Z", - "updated_at": "1996-06-20T00:00:00Z", - "github_reviewed_at": "1996-06-20T00:00:00Z", - "nvd_published_at": "1996-06-20T00:00:00Z", + "published_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, + "github_reviewed_at": `+refTimeStr(1136178002)+`, + "nvd_published_at": `+refTimeStr(1136178003)+`, "withdrawn_at": null, "vulnerabilities": [ { @@ -837,7 +836,6 @@ func TestListGlobalSecurityAdvisories(t *testing.T) { t.Errorf("SecurityAdvisories.ListGlobalSecurityAdvisories returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := []*GlobalSecurityAdvisory{ { ID: Ptr(int64(1)), @@ -859,8 +857,8 @@ func TestListGlobalSecurityAdvisories(t *testing.T) { Value: Ptr("CVE-xoxo-1234"), }, }, - PublishedAt: &date, - UpdatedAt: &date, + PublishedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), WithdrawnAt: nil, CVSS: &AdvisoryCVSS{ VectorString: Ptr("CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:H/I:H/A:H"), @@ -888,8 +886,8 @@ func TestListGlobalSecurityAdvisories(t *testing.T) { RepositoryAdvisoryURL: Ptr("https://api.github.com/repos/project/a-package/security-advisories/GHSA-xoxo-1234-xoxo"), Type: Ptr("reviewed"), SourceCodeLocation: Ptr("https://github.com/project/a-package"), - GithubReviewedAt: &date, - NVDPublishedAt: &date, + GithubReviewedAt: refTimestamp(1136178002), + NVDPublishedAt: refTimestamp(1136178003), Credits: []*Credit{ { User: &User{ @@ -959,10 +957,10 @@ func TestGetGlobalSecurityAdvisories(t *testing.T) { } ], "references": ["https://nvd.nist.gov/vuln/detail/CVE-xoxo-1234"], - "published_at": "1996-06-20T00:00:00Z", - "updated_at": "1996-06-20T00:00:00Z", - "github_reviewed_at": "1996-06-20T00:00:00Z", - "nvd_published_at": "1996-06-20T00:00:00Z", + "published_at": `+refTimeStr(1136178000)+`, + "updated_at": `+refTimeStr(1136178001)+`, + "github_reviewed_at": `+refTimeStr(1136178002)+`, + "nvd_published_at": `+refTimeStr(1136178003)+`, "withdrawn_at": null, "vulnerabilities": [ { @@ -1019,7 +1017,6 @@ func TestGetGlobalSecurityAdvisories(t *testing.T) { t.Errorf("SecurityAdvisories.GetGlobalSecurityAdvisories returned error: %v", err) } - date := Timestamp{time.Date(1996, time.June, 20, 0, 0, 0, 0, time.UTC)} want := &GlobalSecurityAdvisory{ ID: Ptr(int64(1)), SecurityAdvisory: SecurityAdvisory{ @@ -1040,8 +1037,8 @@ func TestGetGlobalSecurityAdvisories(t *testing.T) { Value: Ptr("CVE-xoxo-1234"), }, }, - PublishedAt: &date, - UpdatedAt: &date, + PublishedAt: refTimestamp(1136178000), + UpdatedAt: refTimestamp(1136178001), WithdrawnAt: nil, CVSS: &AdvisoryCVSS{ VectorString: Ptr("CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:H/I:H/A:H"), @@ -1058,8 +1055,8 @@ func TestGetGlobalSecurityAdvisories(t *testing.T) { Type: Ptr("reviewed"), SourceCodeLocation: Ptr("https://github.com/project/a-package"), References: []string{"https://nvd.nist.gov/vuln/detail/CVE-xoxo-1234"}, - GithubReviewedAt: &date, - NVDPublishedAt: &date, + GithubReviewedAt: refTimestamp(1136178002), + NVDPublishedAt: refTimestamp(1136178003), Vulnerabilities: []*GlobalSecurityVulnerability{ { diff --git a/github/teams_discussion_comments_test.go b/github/teams_discussion_comments_test.go index 5863fe0a49c..c25ba0f12d9 100644 --- a/github/teams_discussion_comments_test.go +++ b/github/teams_discussion_comments_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -66,13 +65,13 @@ func TestTeamsService_ListComments(t *testing.T) { "body": "comment", "body_html": "
comment
", "body_version": "version", - "created_at": "2018-01-01T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "last_edited_at": null, "discussion_url": "https://api.github.com/teams/2/discussions/3", "html_url": "https://github.com/orgs/1/teams/2/discussions/3/comments/4", "node_id": "node", "number": 4, - "updated_at": "2018-01-01T00:00:00Z", + "updated_at": `+refTimeStr(1136178001)+`, "url": "https://api.github.com/teams/2/discussions/3/comments/4" } ]`) @@ -102,13 +101,13 @@ func TestTeamsService_ListComments(t *testing.T) { Body: Ptr("comment"), BodyHTML: Ptr("comment
"), BodyVersion: Ptr("version"), - CreatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), LastEditedAt: nil, DiscussionURL: Ptr("https://api.github.com/teams/2/discussions/3"), HTMLURL: Ptr("https://github.com/orgs/1/teams/2/discussions/3/comments/4"), NodeID: Ptr("node"), Number: Ptr(4), - UpdatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + UpdatedAt: refTimestamp(1136178001), URL: Ptr("https://api.github.com/teams/2/discussions/3/comments/4"), }, } diff --git a/github/teams_discussions_test.go b/github/teams_discussions_test.go index 70d5898bb7c..11be8d3ddda 100644 --- a/github/teams_discussions_test.go +++ b/github/teams_discussions_test.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/google/go-cmp/cmp" ) @@ -51,7 +50,7 @@ func TestTeamsService_ListDiscussionsByID(t *testing.T) { "body_version": "version", "comments_count": 1, "comments_url": "https://api.github.com/teams/2/discussions/3/comments", - "created_at": "2018-01-01T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "last_edited_at": null, "html_url": "https://github.com/orgs/1/teams/2/discussions/3", "node_id": "node", @@ -60,7 +59,7 @@ func TestTeamsService_ListDiscussionsByID(t *testing.T) { "private": false, "team_url": "https://api.github.com/teams/2", "title": "test", - "updated_at": "2018-01-01T00:00:00Z", + "updated_at": `+refTimeStr(1136178001)+`, "url": "https://api.github.com/teams/2/discussions/3" } ]`) @@ -97,7 +96,7 @@ func TestTeamsService_ListDiscussionsByID(t *testing.T) { BodyVersion: Ptr("version"), CommentsCount: Ptr(1), CommentsURL: Ptr("https://api.github.com/teams/2/discussions/3/comments"), - CreatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), LastEditedAt: nil, HTMLURL: Ptr("https://github.com/orgs/1/teams/2/discussions/3"), NodeID: Ptr("node"), @@ -106,7 +105,7 @@ func TestTeamsService_ListDiscussionsByID(t *testing.T) { Private: Ptr(false), TeamURL: Ptr("https://api.github.com/teams/2"), Title: Ptr("test"), - UpdatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + UpdatedAt: refTimestamp(1136178001), URL: Ptr("https://api.github.com/teams/2/discussions/3"), }, } @@ -166,7 +165,7 @@ func TestTeamsService_ListDiscussionsBySlug(t *testing.T) { "body_version": "version", "comments_count": 1, "comments_url": "https://api.github.com/teams/2/discussions/3/comments", - "created_at": "2018-01-01T00:00:00Z", + "created_at": `+refTimeStr(1136178000)+`, "last_edited_at": null, "html_url": "https://github.com/orgs/1/teams/2/discussions/3", "node_id": "node", @@ -175,7 +174,7 @@ func TestTeamsService_ListDiscussionsBySlug(t *testing.T) { "private": false, "team_url": "https://api.github.com/teams/2", "title": "test", - "updated_at": "2018-01-01T00:00:00Z", + "updated_at": `+refTimeStr(1136178001)+`, "url": "https://api.github.com/teams/2/discussions/3" } ]`) @@ -212,7 +211,7 @@ func TestTeamsService_ListDiscussionsBySlug(t *testing.T) { BodyVersion: Ptr("version"), CommentsCount: Ptr(1), CommentsURL: Ptr("https://api.github.com/teams/2/discussions/3/comments"), - CreatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + CreatedAt: refTimestamp(1136178000), LastEditedAt: nil, HTMLURL: Ptr("https://github.com/orgs/1/teams/2/discussions/3"), NodeID: Ptr("node"), @@ -221,7 +220,7 @@ func TestTeamsService_ListDiscussionsBySlug(t *testing.T) { Private: Ptr(false), TeamURL: Ptr("https://api.github.com/teams/2"), Title: Ptr("test"), - UpdatedAt: &Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}, + UpdatedAt: refTimestamp(1136178001), URL: Ptr("https://api.github.com/teams/2/discussions/3"), }, } diff --git a/github/timestamp_test.go b/github/timestamp_test.go index 65e5ed88e50..8b31320efbb 100644 --- a/github/timestamp_test.go +++ b/github/timestamp_test.go @@ -13,6 +13,7 @@ import ( const ( emptyTimeStr = `"0001-01-01T00:00:00Z"` + referenceTimeRaw = "2006-01-02T15:04:05Z" referenceTimeStr = `"2006-01-02T15:04:05Z"` referenceTimeStrFractional = `"2006-01-02T15:04:05.000Z"` // This format was returned by the Projects API before October 1, 2017. referenceUnixTimeStr = `1136214245` @@ -20,8 +21,11 @@ const ( ) var ( - referenceTime = time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC) - unixOrigin = time.Unix(0, 0).In(time.UTC) + referenceTime = time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC) + referenceTimestamp = Timestamp{referenceTime} + refTimeStr = func(unix int64) string { return `"` + refTimestamp(unix).Format(time.RFC3339) + `"` } + refTimestamp = func(unix int64) *Timestamp { return &Timestamp{time.Unix(unix, 0).In(time.UTC).Local()} } + unixOrigin = time.Unix(0, 0).In(time.UTC) ) func TestTimestamp_Marshal(t *testing.T) {