Skip to content

Commit

Permalink
Use resty as http response
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl committed Nov 13, 2023
1 parent 58b0e25 commit c1d32c5
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions integration-tests/client/chainlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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().
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c1d32c5

Please sign in to comment.