github.com/google/go-github/v74@v74.0.0/github/orgs_attestations_test.go (about) 1 // Copyright 2024 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 "fmt" 11 "net/http" 12 "testing" 13 14 "github.com/google/go-cmp/cmp" 15 ) 16 17 func TestOrganizationsService_ListAttestations(t *testing.T) { 18 t.Parallel() 19 client, mux, _ := setup(t) 20 21 mux.HandleFunc("/orgs/o/attestations/digest", func(w http.ResponseWriter, r *http.Request) { 22 testMethod(t, r, "GET") 23 fmt.Fprint(w, `{ 24 "attestations": [ 25 { 26 "repository_id": 1, 27 "bundle": {} 28 }, 29 { 30 "repository_id": 2, 31 "bundle": {} 32 } 33 ] 34 }`) 35 }) 36 ctx := context.Background() 37 attestations, _, err := client.Organizations.ListAttestations(ctx, "o", "digest", &ListOptions{}) 38 if err != nil { 39 t.Errorf("Organizations.ListAttestations returned error: %v", err) 40 } 41 42 want := &AttestationsResponse{ 43 Attestations: []*Attestation{ 44 { 45 RepositoryID: 1, 46 Bundle: []byte(`{}`), 47 }, 48 { 49 RepositoryID: 2, 50 Bundle: []byte(`{}`), 51 }, 52 }, 53 } 54 55 if !cmp.Equal(attestations, want) { 56 t.Errorf("Organizations.ListAttestations = %+v, want %+v", attestations, want) 57 } 58 const methodName = "ListAttestations" 59 60 testBadOptions(t, methodName, func() (err error) { 61 _, _, err = client.Organizations.ListAttestations(ctx, "\n", "\n", &ListOptions{}) 62 return err 63 }) 64 65 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 66 got, resp, err := client.Organizations.ListAttestations(ctx, "o", "digest", nil) 67 if got != nil { 68 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 69 } 70 return resp, err 71 }) 72 }