|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +package abuse_reports_test |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "errors" |
| 8 | + "os" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/cloudflare/cloudflare-go/v6" |
| 12 | + "github.com/cloudflare/cloudflare-go/v6/abuse_reports" |
| 13 | + "github.com/cloudflare/cloudflare-go/v6/internal/testutil" |
| 14 | + "github.com/cloudflare/cloudflare-go/v6/option" |
| 15 | +) |
| 16 | + |
| 17 | +func TestAbuseReportNewWithOptionalParams(t *testing.T) { |
| 18 | + t.Skip("TODO: investigate unauthorized HTTP response") |
| 19 | + baseURL := "http://localhost:4010" |
| 20 | + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { |
| 21 | + baseURL = envURL |
| 22 | + } |
| 23 | + if !testutil.CheckTestServer(t, baseURL) { |
| 24 | + return |
| 25 | + } |
| 26 | + client := cloudflare.NewClient( |
| 27 | + option.WithBaseURL(baseURL), |
| 28 | + option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), |
| 29 | + option.WithAPIEmail("user@example.com"), |
| 30 | + ) |
| 31 | + _, err := client.AbuseReports.New( |
| 32 | + context.TODO(), |
| 33 | + "report_param", |
| 34 | + abuse_reports.AbuseReportNewParams{ |
| 35 | + AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), |
| 36 | + Body: abuse_reports.AbuseReportNewParamsBodyAbuseReportsDmcaReport{ |
| 37 | + Act: cloudflare.F(abuse_reports.AbuseReportNewParamsBodyAbuseReportsDmcaReportActAbuseDmca), |
| 38 | + Address1: cloudflare.F("x"), |
| 39 | + AgentName: cloudflare.F("x"), |
| 40 | + Agree: cloudflare.F(abuse_reports.AbuseReportNewParamsBodyAbuseReportsDmcaReportAgree1), |
| 41 | + City: cloudflare.F("x"), |
| 42 | + Country: cloudflare.F("x"), |
| 43 | + Email: cloudflare.F("email"), |
| 44 | + Email2: cloudflare.F("email2"), |
| 45 | + HostNotification: cloudflare.F(abuse_reports.AbuseReportNewParamsBodyAbuseReportsDmcaReportHostNotificationSend), |
| 46 | + Name: cloudflare.F("x"), |
| 47 | + OriginalWork: cloudflare.F("x"), |
| 48 | + OwnerNotification: cloudflare.F(abuse_reports.AbuseReportNewParamsBodyAbuseReportsDmcaReportOwnerNotificationSend), |
| 49 | + Signature: cloudflare.F("signature"), |
| 50 | + State: cloudflare.F("x"), |
| 51 | + URLs: cloudflare.F("urls"), |
| 52 | + Comments: cloudflare.F("x"), |
| 53 | + Company: cloudflare.F("x"), |
| 54 | + ReportedCountry: cloudflare.F("xx"), |
| 55 | + ReportedUserAgent: cloudflare.F("x"), |
| 56 | + Tele: cloudflare.F("x"), |
| 57 | + Title: cloudflare.F("x"), |
| 58 | + }, |
| 59 | + }, |
| 60 | + ) |
| 61 | + if err != nil { |
| 62 | + var apierr *cloudflare.Error |
| 63 | + if errors.As(err, &apierr) { |
| 64 | + t.Log(string(apierr.DumpRequest(true))) |
| 65 | + } |
| 66 | + t.Fatalf("err should be nil: %s", err.Error()) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +func TestAbuseReportListWithOptionalParams(t *testing.T) { |
| 71 | + baseURL := "http://localhost:4010" |
| 72 | + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { |
| 73 | + baseURL = envURL |
| 74 | + } |
| 75 | + if !testutil.CheckTestServer(t, baseURL) { |
| 76 | + return |
| 77 | + } |
| 78 | + client := cloudflare.NewClient( |
| 79 | + option.WithBaseURL(baseURL), |
| 80 | + option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), |
| 81 | + option.WithAPIEmail("user@example.com"), |
| 82 | + ) |
| 83 | + _, err := client.AbuseReports.List(context.TODO(), abuse_reports.AbuseReportListParams{ |
| 84 | + AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), |
| 85 | + CreatedAfter: cloudflare.F("2009-11-10T23:00:00Z"), |
| 86 | + CreatedBefore: cloudflare.F("2009-11-10T23:00:00Z"), |
| 87 | + Domain: cloudflare.F("domain"), |
| 88 | + MitigationStatus: cloudflare.F(abuse_reports.AbuseReportListParamsMitigationStatusPending), |
| 89 | + Page: cloudflare.F(int64(0)), |
| 90 | + PerPage: cloudflare.F(int64(0)), |
| 91 | + Sort: cloudflare.F("sort"), |
| 92 | + Status: cloudflare.F(abuse_reports.AbuseReportListParamsStatusAccepted), |
| 93 | + Type: cloudflare.F(abuse_reports.AbuseReportListParamsTypePhish), |
| 94 | + }) |
| 95 | + if err != nil { |
| 96 | + var apierr *cloudflare.Error |
| 97 | + if errors.As(err, &apierr) { |
| 98 | + t.Log(string(apierr.DumpRequest(true))) |
| 99 | + } |
| 100 | + t.Fatalf("err should be nil: %s", err.Error()) |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +func TestAbuseReportGet(t *testing.T) { |
| 105 | + baseURL := "http://localhost:4010" |
| 106 | + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { |
| 107 | + baseURL = envURL |
| 108 | + } |
| 109 | + if !testutil.CheckTestServer(t, baseURL) { |
| 110 | + return |
| 111 | + } |
| 112 | + client := cloudflare.NewClient( |
| 113 | + option.WithBaseURL(baseURL), |
| 114 | + option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), |
| 115 | + option.WithAPIEmail("user@example.com"), |
| 116 | + ) |
| 117 | + _, err := client.AbuseReports.Get( |
| 118 | + context.TODO(), |
| 119 | + "report_param", |
| 120 | + abuse_reports.AbuseReportGetParams{ |
| 121 | + AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), |
| 122 | + }, |
| 123 | + ) |
| 124 | + if err != nil { |
| 125 | + var apierr *cloudflare.Error |
| 126 | + if errors.As(err, &apierr) { |
| 127 | + t.Log(string(apierr.DumpRequest(true))) |
| 128 | + } |
| 129 | + t.Fatalf("err should be nil: %s", err.Error()) |
| 130 | + } |
| 131 | +} |
0 commit comments