Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use resty as http response in E2E tests and fix if testing.T context is nil #11271

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading