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

Reintroduce missing code for rest endpoint wiring #2080

Merged
merged 6 commits into from
Jan 30, 2023

Conversation

mmulji-ic
Copy link
Contributor

Fixes issue #2074

@mmulji-ic
Copy link
Contributor Author

Note integration tests are not added at this point.

@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #2080 (a1b53a2) into main (983a9fe) will decrease coverage by 0.24%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2080      +/-   ##
==========================================
- Coverage   84.85%   84.62%   -0.24%     
==========================================
  Files          21       21              
  Lines        1466     1470       +4     
==========================================
  Hits         1244     1244              
- Misses        177      181       +4     
  Partials       45       45              
Impacted Files Coverage Δ
app/app.go 75.22% <0.00%> (-1.36%) ⬇️

Copy link
Contributor

@faddat faddat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly approve of this. Thank you so much for catching it.

)

// Helper function to read the response body and unmarshal it into a map
func readJSON(resp *http.Response) (map[string]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 60 to 64
if err != nil {
testOk = false
s.T().Logf("failed to get endpoint: %s, %v", endpointURL+endpoint.Path, err)
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil {
testOk = false
s.T().Logf("failed to get endpoint: %s, %v", endpointURL+endpoint.Path, err)
continue
}
s.NoError(err, fmt.Sprintf("Failed to get endpoint: %s%s, %s", endpointURL, endpoint.Path, err.Error()))

Comment on lines 67 to 72
jsonBody, errJSON := readJSON(resp)
if errJSON != nil {
testOk = false
s.T().Logf("failed to read body of endpoint: %s, %v", endpointURL+endpoint.Path, errJSON)
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jsonBody, errJSON := readJSON(resp)
if errJSON != nil {
testOk = false
s.T().Logf("failed to read body of endpoint: %s, %v", endpointURL+endpoint.Path, errJSON)
continue
}
jsonBody, err := readJSON(resp)
s.NoError(err, fmt.Sprintf("Failed to read body of endpoint: %s%s, %s", endpointURL, endpoint.Path, err.Error()))

for _, endpoint := range testEndpoints {

// Call the required endpoint
resp, err := http.Get(endpointURL + endpoint.Path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For failure cases, if the endpoint doesn't exist, there's not really a reason for the final test clause, you might as well just assert s.EqualValues(resp.StatusCode, 200), which will fail as the missing_endpoint test case will return a 501

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. I also wanted to check the structure strictly (will leave that for later).

{"/node_info", false},
{"/syncing", false},
{"/missing_endpoint", true},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check every endpoint, not limited to these 3, but can do this later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. atm just want to make sure that the module is wired ok.


if endpoint.ExpectedFail == false && jsonBody["message"] == "Not Implemented" {
testOk = false
s.T().Logf("Encountered a Not implemented endpoint: %s", endpointURL+endpoint.Path)
Copy link
Contributor

@yaruwangway yaruwangway Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it should be "Not Implemented""? otherwise, can just fail here, log might not make people realize if this test fails. maybe can use s.Require.False(jsonBody["message"] == "Not Implemented") or use s.Require.True to check how the jsonBody["message"] should be might be better.

@mmulji-ic mmulji-ic requested a review from mpoke January 30, 2023 09:56
Copy link
Contributor

@MSalopek MSalopek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Left some nits.

8. Staking params
*/

var (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe consider using const.

Suggested change
var (
const (

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed nit

@sonarcloud
Copy link

sonarcloud bot commented Jan 30, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mmulji-ic mmulji-ic merged commit 690f167 into main Jan 30, 2023
@mmulji-ic mmulji-ic deleted the mmulji-ic/fix-broken-rest-routes branch January 30, 2023 12:33
mergify bot pushed a commit that referenced this pull request Jan 30, 2023
* Reintroduce missing code for rest endpoint wiring

* Fix gofumpt

* e2e test to check if endpoints are available

* Ran linter/formater

* Refactor and add comprehensive tests for missing routes (#2094)

* Fixed var -> const definition

---------

Co-authored-by: lg <lauren@interchain.io>
Co-authored-by: lg <8335464+glnro@users.noreply.github.com>
(cherry picked from commit 690f167)
mergify bot pushed a commit that referenced this pull request Jan 30, 2023
* Reintroduce missing code for rest endpoint wiring

* Fix gofumpt

* e2e test to check if endpoints are available

* Ran linter/formater

* Refactor and add comprehensive tests for missing routes (#2094)

* Fixed var -> const definition

---------

Co-authored-by: lg <lauren@interchain.io>
Co-authored-by: lg <8335464+glnro@users.noreply.github.com>
(cherry picked from commit 690f167)
mmulji-ic added a commit that referenced this pull request Jan 30, 2023
* Reintroduce missing code for rest endpoint wiring

* Fix gofumpt

* e2e test to check if endpoints are available

* Ran linter/formater

* Refactor and add comprehensive tests for missing routes (#2094)

* Fixed var -> const definition

---------

Co-authored-by: lg <lauren@interchain.io>
Co-authored-by: lg <8335464+glnro@users.noreply.github.com>
(cherry picked from commit 690f167)

Co-authored-by: Milan Mulji <98309852+mmulji-ic@users.noreply.github.com>
mmulji-ic added a commit that referenced this pull request Jan 30, 2023
* Reintroduce missing code for rest endpoint wiring

* Fix gofumpt

* e2e test to check if endpoints are available

* Ran linter/formater

* Refactor and add comprehensive tests for missing routes (#2094)

* Fixed var -> const definition

---------

Co-authored-by: lg <lauren@interchain.io>
Co-authored-by: lg <8335464+glnro@users.noreply.github.com>
(cherry picked from commit 690f167)

Co-authored-by: Milan Mulji <98309852+mmulji-ic@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants