...

Source file src/github.com/google/go-github/v55/github/security_advisories_test.go

Documentation: github.com/google/go-github/v55/github

     1  // Copyright 2023 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"net/http"
    11  	"testing"
    12  )
    13  
    14  func TestSecurityAdvisoriesService_RequestCVE(t *testing.T) {
    15  	client, mux, _, teardown := setup()
    16  	defer teardown()
    17  
    18  	mux.HandleFunc("/repos/o/r/security-advisories/ghsa_id_ok/cve", func(w http.ResponseWriter, r *http.Request) {
    19  		testMethod(t, r, "POST")
    20  		w.WriteHeader(http.StatusOK)
    21  	})
    22  
    23  	mux.HandleFunc("/repos/o/r/security-advisories/ghsa_id_accepted/cve", func(w http.ResponseWriter, r *http.Request) {
    24  		testMethod(t, r, "POST")
    25  		w.WriteHeader(http.StatusAccepted)
    26  	})
    27  
    28  	ctx := context.Background()
    29  	_, err := client.SecurityAdvisories.RequestCVE(ctx, "o", "r", "ghsa_id_ok")
    30  	if err != nil {
    31  		t.Errorf("SecurityAdvisoriesService.RequestCVE returned error: %v", err)
    32  	}
    33  
    34  	_, err = client.SecurityAdvisories.RequestCVE(ctx, "o", "r", "ghsa_id_accepted")
    35  	if err != nil {
    36  		t.Errorf("SecurityAdvisoriesService.RequestCVE returned error: %v", err)
    37  	}
    38  
    39  	const methodName = "RequestCVE"
    40  	testBadOptions(t, methodName, func() (err error) {
    41  		_, err = client.SecurityAdvisories.RequestCVE(ctx, "\n", "\n", "\n")
    42  		return err
    43  	})
    44  
    45  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    46  		resp, err := client.SecurityAdvisories.RequestCVE(ctx, "o", "r", "ghsa_id")
    47  		if err == nil {
    48  			t.Errorf("testNewRequestAndDoFailure %v should have return err", methodName)
    49  		}
    50  		return resp, err
    51  	})
    52  }
    53  

View as plain text