add mock http client
Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
parent
fb020f2a79
commit
e4431a3f55
4 changed files with 32 additions and 1 deletions
|
|
@ -25,6 +25,9 @@ func NewClientWithMockGHClient(hasNextPage bool) Client {
|
||||||
githubAPI: mockAPIClient{
|
githubAPI: mockAPIClient{
|
||||||
OnRESTWithNext: fetcher.OnRESTSuccessWithNextPage,
|
OnRESTWithNext: fetcher.OnRESTSuccessWithNextPage,
|
||||||
},
|
},
|
||||||
|
httpClient: mockHttpClient{
|
||||||
|
OnGet: fetcher.OnGetSuccess,
|
||||||
|
},
|
||||||
logger: l,
|
logger: l,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -33,6 +36,9 @@ func NewClientWithMockGHClient(hasNextPage bool) Client {
|
||||||
githubAPI: mockAPIClient{
|
githubAPI: mockAPIClient{
|
||||||
OnRESTWithNext: fetcher.OnRESTSuccess,
|
OnRESTWithNext: fetcher.OnRESTSuccess,
|
||||||
},
|
},
|
||||||
|
httpClient: mockHttpClient{
|
||||||
|
OnGet: fetcher.OnGetSuccess,
|
||||||
|
},
|
||||||
logger: l,
|
logger: l,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func (m MockClient) GetTrustDomain() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTestAttestation() Attestation {
|
func makeTestAttestation() Attestation {
|
||||||
return Attestation{Bundle: data.SigstoreBundle(nil)}
|
return Attestation{Bundle: data.SigstoreBundle(nil), BundleURL: "https://example.com"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnGetByRepoAndDigestSuccess(repo, digest string, limit int) ([]*Attestation, error) {
|
func OnGetByRepoAndDigestSuccess(repo, digest string, limit int) ([]*Attestation, error) {
|
||||||
|
|
|
||||||
25
pkg/cmd/attestation/api/mock_httpClient_test.go
Normal file
25
pkg/cmd/attestation/api/mock_httpClient_test.go
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cli/cli/v2/pkg/cmd/attestation/test/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mockHttpClient struct {
|
||||||
|
OnGet func(url string) (*http.Response, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockHttpClient) Get(url string) (*http.Response, error) {
|
||||||
|
return m.OnGet(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockDataGenerator) OnGetSuccess(url string) (*http.Response, error) {
|
||||||
|
bundle := data.SigstoreBundle(nil)
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: 200,
|
||||||
|
Body: io.NopCloser(strings.NewReader(bundle.String())),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue