mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
refactor: enhance TLS cert generation and refactor HTTP client architecture (#3638)
- Refactored HTTP client from global cache to struct-based approach (global state was shared between tests, including what certificates to use) - Enhanced pkg/test/tls to support ECDSA and ED25519 key types - Replaced static certificate files with dynamic generation in golang tests - Fixed test cleanup issues and improved resource management This eliminates dependency on external cert generation scripts and improves test maintainability. Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
@@ -26,12 +26,13 @@ func getDefaultSearchConf(baseURL string) SearchConfig {
|
||||
outputFormat := "text"
|
||||
|
||||
return SearchConfig{
|
||||
ServURL: baseURL,
|
||||
ResultWriter: io.Discard,
|
||||
VerifyTLS: verifyTLS,
|
||||
Debug: debug,
|
||||
Verbose: verbose,
|
||||
OutputFormat: outputFormat,
|
||||
ServURL: baseURL,
|
||||
ResultWriter: io.Discard,
|
||||
VerifyTLS: verifyTLS,
|
||||
Debug: debug,
|
||||
Verbose: verbose,
|
||||
OutputFormat: outputFormat,
|
||||
SearchService: NewSearchService(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +89,8 @@ func TestDoHTTPRequest(t *testing.T) {
|
||||
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, url, nil)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(func() { _, _ = doHTTPRequest(req, false, false, nil, io.Discard) }, ShouldNotPanic)
|
||||
httpClient := NewHTTPClient()
|
||||
So(func() { _, _ = httpClient.doHTTPRequest(req, false, false, nil, io.Discard) }, ShouldNotPanic)
|
||||
})
|
||||
|
||||
Convey("doHTTPRequest bad return json", t, func() {
|
||||
@@ -112,21 +114,25 @@ func TestDoHTTPRequest(t *testing.T) {
|
||||
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(func() { _, _ = doHTTPRequest(req, false, false, &ispec.Manifest{}, io.Discard) }, ShouldNotPanic)
|
||||
httpClient := NewHTTPClient()
|
||||
So(func() { _, _ = httpClient.doHTTPRequest(req, false, false, &ispec.Manifest{}, io.Discard) }, ShouldNotPanic)
|
||||
})
|
||||
|
||||
Convey("makeGraphQLRequest bad request context", t, func() {
|
||||
err := makeGraphQLRequest(nil, "", "", "", "", false, false, nil, io.Discard) //nolint:staticcheck
|
||||
httpClient := NewHTTPClient()
|
||||
err := httpClient.makeGraphQLRequest(nil, "", "", "", "", false, false, nil, io.Discard) //nolint:staticcheck
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("makeHEADRequest bad request context", t, func() {
|
||||
_, err := makeHEADRequest(nil, "", "", "", false, false) //nolint:staticcheck
|
||||
httpClient := NewHTTPClient()
|
||||
_, err := httpClient.makeHEADRequest(nil, "", "", "", false, false) //nolint:staticcheck
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("makeGETRequest bad request context", t, func() {
|
||||
_, err := makeGETRequest(nil, "", "", "", false, false, nil, io.Discard) //nolint:staticcheck
|
||||
httpClient := NewHTTPClient()
|
||||
_, err := httpClient.makeGETRequest(nil, "", "", "", false, false, nil, io.Discard) //nolint:staticcheck
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user