Skip to content

Commit cfa26f9

Browse files
test: added more test cases for DownloadCopilotMetrics and skip the method in metadata
1 parent fcfdd12 commit cfa26f9

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

github/copilot_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,10 +2827,13 @@ func TestCopilotService_DownloadCopilotMetrics(t *testing.T) {
28272827

28282828
ctx := t.Context()
28292829
url := client.BaseURL.String() + "path/to/download"
2830-
got, _, err := client.Copilot.DownloadCopilotMetrics(ctx, url)
2830+
got, resp, err := client.Copilot.DownloadCopilotMetrics(ctx, url)
28312831
if err != nil {
28322832
t.Errorf("Copilot.DownloadCopilotMetrics returned error: %v", err)
28332833
}
2834+
if resp.StatusCode != http.StatusOK {
2835+
t.Errorf("Copilot.DownloadCopilotMetrics returned status code: %v", resp.StatusCode)
2836+
}
28342837

28352838
want := []*CopilotMetrics{
28362839
{
@@ -2885,6 +2888,29 @@ func TestCopilotService_DownloadCopilotMetrics(t *testing.T) {
28852888
urlErr := client.BaseURL.String() + "path/to/download/error"
28862889
_, _, err = client.Copilot.DownloadCopilotMetrics(ctx, urlErr)
28872890
if err == nil {
2888-
t.Errorf("Copilot.DownloadCopilotMetrics expected error but got none")
2891+
t.Error("Copilot.DownloadCopilotMetrics expected error but got none")
2892+
}
2893+
2894+
// Test invalid URL (fails http.NewRequestWithContext)
2895+
_, _, err = client.Copilot.DownloadCopilotMetrics(ctx, "\n")
2896+
if err == nil {
2897+
t.Error("Copilot.DownloadCopilotMetrics expected error for invalid URL, got none")
2898+
}
2899+
2900+
// Test invalid scheme (fails client.Do)
2901+
_, _, err = client.Copilot.DownloadCopilotMetrics(ctx, "invalid-scheme://test")
2902+
if err == nil {
2903+
t.Error("Copilot.DownloadCopilotMetrics expected error for invalid scheme, got none")
2904+
}
2905+
2906+
// Test json decoding error
2907+
mux.HandleFunc("/path/to/download/badjson", func(w http.ResponseWriter, r *http.Request) {
2908+
testMethod(t, r, "GET")
2909+
fmt.Fprint(w, `[{invalid JSON`)
2910+
})
2911+
urlBadJson := client.BaseURL.String() + "path/to/download/badjson"
2912+
_, _, err = client.Copilot.DownloadCopilotMetrics(ctx, urlBadJson)
2913+
if err == nil {
2914+
t.Error("Copilot.DownloadCopilotMetrics expected error for bad JSON, got none")
28892915
}
28902916
}

tools/metadata/metadata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,5 @@ var skipServiceMethod = map[string]bool{
547547
"BillingService.GetOrganizationStorageBilling": true,
548548
"BillingService.GetPackagesBilling": true,
549549
"BillingService.GetStorageBilling": true,
550+
"CopilotService.DownloadCopilotMetrics": true,
550551
}

0 commit comments

Comments
 (0)