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:
Andrei Aaron
2025-12-13 09:47:32 +02:00
committed by GitHub
parent 1447bb24b4
commit cf8b0bdbf9
22 changed files with 1590 additions and 554 deletions
+17 -11
View File
@@ -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)
})