From 41146cce2bb672c2082537a39f608fbf20f8985f Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Tue, 17 Aug 2021 17:37:17 +0000 Subject: test: move os.stat check before the hcc creation --- client/httpclient.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/httpclient.go b/client/httpclient.go index fceb0f4..a2ecfd0 100644 --- a/client/httpclient.go +++ b/client/httpclient.go @@ -74,6 +74,13 @@ func NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath stri } else if strings.HasPrefix(gitlabURL, httpProtocol) { transport, host = buildHttpTransport(gitlabURL) } else if strings.HasPrefix(gitlabURL, httpsProtocol) { + if _, err := os.Stat(caFile); err != nil { + if os.IsNotExist(err) { + return nil, fmt.Errorf("cannot find cafile '%s': %w", caFile, ErrCafileNotFound) + } + return nil, err + } + hcc := &httpClientCfg{ caFile: caFile, caPath: caPath, @@ -83,13 +90,6 @@ func NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath stri opt(hcc) } - if _, err := os.Stat(caFile); err != nil { - if os.IsNotExist(err) { - return nil, fmt.Errorf("cannot find cafile '%s': %w", caFile, ErrCafileNotFound) - } - return nil, err - } - transport, host, err = buildHttpsTransport(*hcc, selfSignedCert, gitlabURL) if err != nil { return nil, err -- cgit v1.2.1