Skip to content

Commit

Permalink
Part two removing test interface httpclient.Client (#6756)
Browse files Browse the repository at this point in the history
### Description of the change

Follows on from #6746 removing more uses of the httpclient.Client test
interface that's causing pain when adding new features, and updates
tests to use an `httptest.Server` instead of mocking the client.

### Benefits

See #6726 

Also fixes more tests that were feigning to assert that errors were
equal, but were simply asserting that an error was raised.

### Possible drawbacks

### Applicable issues

- fixes #6726

### Additional information

~~One more PR following which removes the remainder and the interface
itself.~~ (Ended up just adding to this PR).

---------

Signed-off-by: Michael Nelson <minelson@vmware.com>
  • Loading branch information
absoludity authored Sep 5, 2023
1 parent f78f651 commit b939493
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 364 deletions.
8 changes: 4 additions & 4 deletions cmd/asset-syncer/server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ type OCIRegistry struct {
filter *apprepov1alpha1.FilterRuleSpec
}

func doReq(url string, cli httpclient.Client, headers map[string]string, userAgent string) ([]byte, error) {
func doReq(url string, cli *http.Client, headers map[string]string, userAgent string) ([]byte, error) {
headers["User-Agent"] = userAgent
return httpclient.Get(url, cli, headers)
}
Expand Down Expand Up @@ -342,7 +342,7 @@ type OciAPIClient struct {
RegistryNamespaceUrl *url.URL
// The HttpClient is used for all http requests to the OCI Distribution
// spec API.
HttpClient httpclient.Client
HttpClient *http.Client
// The GrpcClient is used when querying our OCI Catalog service, which
// aims to work around some of the shortfalls of the OCI Distribution spec
// API
Expand Down Expand Up @@ -834,7 +834,7 @@ func getOCIRepo(namespace, name, repoURL, authorizationHeader string, filter *ap
}, nil
}

func fetchRepoIndex(url, authHeader string, cli httpclient.Client, userAgent string) ([]byte, error) {
func fetchRepoIndex(url, authHeader string, cli *http.Client, userAgent string) ([]byte, error) {
indexURL, err := parseRepoURL(url)
if err != nil {
log.Errorf("Failed to parse URL, url=%s: %v", url, err)
Expand Down Expand Up @@ -863,7 +863,7 @@ func chartTarballURL(r *models.AppRepositoryInternal, cv models.ChartVersion) st

type fileImporter struct {
manager assetManager
netClient httpclient.Client
netClient *http.Client
}

func (f *fileImporter) fetchFiles(charts []models.Chart, repo ChartCatalog, userAgent string, passCredentials bool) {
Expand Down
Loading

0 comments on commit b939493

Please sign in to comment.