MCPcopy Index your code
hub / github.com/google/go-github / TestCodeScanningService_UploadSarif

Function TestCodeScanningService_UploadSarif

github/code_scanning_test.go:57–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestCodeScanningService_UploadSarif(t *testing.T) {
58 t.Parallel()
59 client, mux, _ := setup(t)
60
61 expectedSarifID := &SarifID{
62 ID: Ptr("testid"),
63 URL: Ptr("https://example.com/testurl"),
64 }
65
66 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")}
67
68 mux.HandleFunc("/repos/o/r/code-scanning/sarifs", func(w http.ResponseWriter, r *http.Request) {
69 testMethod(t, r, "POST")
70 testJSONBody(t, r, sarifAnalysis)
71 w.WriteHeader(http.StatusAccepted)
72 respBody, _ := json.Marshal(expectedSarifID)
73 _, _ = w.Write(respBody)
74 })
75
76 ctx := t.Context()
77 respSarifID, _, err := client.CodeScanning.UploadSarif(ctx, "o", "r", sarifAnalysis)
78 if err != nil {
79 t.Errorf("CodeScanning.UploadSarif returned error: %v", err)
80 }
81 if !cmp.Equal(expectedSarifID, respSarifID) {
82 t.Errorf("Sarif response = %+v, want %+v", respSarifID, expectedSarifID)
83 }
84
85 const methodName = "UploadSarif"
86 testBadOptions(t, methodName, func() (err error) {
87 _, _, err = client.CodeScanning.UploadSarif(ctx, "\n", "\n", sarifAnalysis)
88 return err
89 })
90
91 testNewRequestAndDoFailureCategory(t, methodName, client, CodeScanningUploadCategory, func() (*Response, error) {
92 _, resp, err := client.CodeScanning.UploadSarif(ctx, "o", "r", sarifAnalysis)
93 return resp, err
94 })
95}
96
97func TestCodeScanningService_GetSARIF(t *testing.T) {
98 t.Parallel()

Callers

nothing calls this directly

Calls 8

testMethodFunction · 0.85
testJSONBodyFunction · 0.85
testBadOptionsFunction · 0.85
UploadSarifMethod · 0.80
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…