From c1d32c52676ea4d2ca4a0a7e2486624fa1c49f55 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:59:33 +0100 Subject: [PATCH] Use resty as http response --- integration-tests/client/chainlink.go | 31 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/integration-tests/client/chainlink.go b/integration-tests/client/chainlink.go index 3638fa11c7f..ef7bd061426 100644 --- a/integration-tests/client/chainlink.go +++ b/integration-tests/client/chainlink.go @@ -117,11 +117,11 @@ func (c *ChainlinkClient) MustCreateJob(spec JobSpec) (*Job, error) { if err != nil { return nil, err } - return job, VerifyStatusCode(resp.StatusCode, http.StatusOK) + return job, VerifyStatusCode(resp.RawResponse.StatusCode, http.StatusOK) } // CreateJob creates a Chainlink job based on the provided spec struct -func (c *ChainlinkClient) CreateJob(spec JobSpec) (*Job, *http.Response, error) { +func (c *ChainlinkClient) CreateJob(spec JobSpec) (*Job, *resty.Response, error) { job := &Job{} specString, err := spec.String() if err != nil { @@ -138,7 +138,7 @@ func (c *ChainlinkClient) CreateJob(spec JobSpec) (*Job, *http.Response, error) if err != nil { return nil, nil, err } - return job, resp.RawResponse, err + return job, resp, err } // ReadJobs reads all jobs from the Chainlink node @@ -881,8 +881,16 @@ func (c *ChainlinkClient) CreateCSAKey() (*CSAKey, *http.Response, error) { return csaKey, resp.RawResponse, err } +func (c *ChainlinkClient) MustReadCSAKeys() (*CSAKeys, *resty.Response, error) { + csaKeys, res, err := c.ReadCSAKeys() + if err != nil { + return nil, res, err + } + return csaKeys, res, VerifyStatusCodeWithResponse(res, http.StatusOK) +} + // ReadCSAKeys reads CSA keys from the Chainlink node -func (c *ChainlinkClient) ReadCSAKeys() (*CSAKeys, *http.Response, error) { +func (c *ChainlinkClient) ReadCSAKeys() (*CSAKeys, *resty.Response, error) { csaKeys := &CSAKeys{} c.l.Info().Str(NodeURL, c.Config.URL).Msg("Reading CSA Keys") resp, err := c.APIClient.R(). @@ -894,7 +902,7 @@ func (c *ChainlinkClient) ReadCSAKeys() (*CSAKeys, *http.Response, error) { if err != nil { return nil, nil, err } - return csaKeys, resp.RawResponse, err + return csaKeys, resp, err } // CreateEI creates an EI on the Chainlink node based on the provided attributes and returns the respective secrets @@ -1105,6 +1113,19 @@ func VerifyStatusCode(actStatusCd, expStatusCd int) error { return nil } +func VerifyStatusCodeWithResponse(res *resty.Response, expStatusCd int) error { + actStatusCd := res.RawResponse.StatusCode + if actStatusCd != expStatusCd { + return fmt.Errorf( + "unexpected response code, got %d, expected %d, response: %s", + actStatusCd, + expStatusCd, + res.Body(), + ) + } + return nil +} + func CreateNodeKeysBundle(nodes []*ChainlinkClient, chainName string, chainId string) ([]NodeKeysBundle, []*CLNodesWithKeys, error) { nkb := make([]NodeKeysBundle, 0) var clNodes []*CLNodesWithKeys