forked from kilnfi/go-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: solve parsing autorest voluntary exit response (#10)
* fix: solve parsing autorest voluntary exit response * fix: solve tests * fix: solve linter * fix: solve linter
- Loading branch information
Showing
2 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ethereum/consensus/client/http/submit_signed_voluntary_exit_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package eth2http | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSubmitSignedVoluntaryExit(t *testing.T) { | ||
u, err := url.Parse("http://localhost") | ||
require.NoError(t, err) | ||
var ( | ||
errMsg = "Invalid voluntary exit, it will never pass validation so it's rejected" | ||
errStatusCode = http.StatusBadRequest | ||
errBodyMsg = fmt.Sprintf(`{"code": %d,"message": %q}`, errStatusCode, errMsg) | ||
respError = &http.Response{StatusCode: errStatusCode, Body: io.NopCloser(bytes.NewReader([]byte(errBodyMsg))), Request: &http.Request{Method: http.MethodPost, URL: u}} | ||
) | ||
|
||
respMsg, err := inspectSubmitSignedVoluntaryExitResponse(respError) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), errMsg) | ||
require.Nil(t, respMsg) | ||
|
||
var ( | ||
okMsg = "all right" | ||
okStatusCode = http.StatusOK | ||
okBodyMsg = fmt.Sprintf(`{"code": %d,"message": %q}`, okStatusCode, okMsg) | ||
) | ||
|
||
respOK := &http.Response{StatusCode: okStatusCode, Body: io.NopCloser(bytes.NewReader([]byte(okBodyMsg))), Request: &http.Request{Method: http.MethodPost, URL: u}} | ||
respMsg, err = inspectSubmitSignedVoluntaryExitResponse(respOK) | ||
require.NoError(t, err) | ||
require.NotNil(t, respMsg) | ||
assert.Equal(t, okStatusCode, respMsg.Code) | ||
assert.Equal(t, okMsg, respMsg.Message) | ||
} |