Skip to content

Commit

Permalink
Use resty as http response in E2E tests and fix if testing.T context …
Browse files Browse the repository at this point in the history
…is nil (#11271)

* Use resty as http response

* Fix for nil testing.T context
  • Loading branch information
lukaszcl authored Nov 14, 2023
1 parent 6fb7fae commit ac94719
Show file tree
Hide file tree
Showing 2 changed files with 30 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
4 changes: 4 additions & 0 deletions integration-tests/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func TestContext(tb testing.TB) context.Context {
var cancel func()
switch t := tb.(type) {
case *testing.T:
// Return background context if testing.T not set
if t == nil {
return ctx
}
if d, ok := t.Deadline(); ok {
ctx, cancel = context.WithDeadline(ctx, d)
}
Expand Down

0 comments on commit ac94719

Please sign in to comment.