From 0493cac34e2aa55845bf8b832d628468ec5b1313 Mon Sep 17 00:00:00 2001 From: Will Winder Date: Tue, 27 Apr 2021 14:35:15 -0400 Subject: [PATCH 1/2] Fix GetGenesis endpoint. (#204) --- Makefile | 2 +- client/v2/common/common.go | 6 ++++++ test/indexer_integration_test.go | 6 +++++- test/responses_unit_test.go | 8 +++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 63166bb6..955e7142 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ build: generate unit: go test $(TEST_SOURCES_NO_CUCUMBER) - cd test && go test --godog.strict=true --godog.format=pretty --godog.tags="@unit.offline,@unit.algod,@unit.indexer,@unit.rekey,@unit.tealsign,@unit.dryrun,@unit.responses,@unit.applications,@unit.transactions,@unit.indexer.rekey,@unit.responses.messagepack,@unit.responses.231,@unit.responses.messagepack.231" --test.v . + cd test && go test --godog.strict=true --godog.format=pretty --godog.tags="@unit.offline,@unit.algod,@unit.indexer,@unit.rekey,@unit.tealsign,@unit.dryrun,@unit.responses,@unit.applications,@unit.transactions,@unit.indexer.rekey,@unit.responses.messagepack,@unit.responses.231,@unit.responses.messagepack.231,@unit.responses.genesis" --test.v . integration: go test $(TEST_SOURCES_NO_CUCUMBER) diff --git a/client/v2/common/common.go b/client/v2/common/common.go index a13b4e3b..ff2ab456 100644 --- a/client/v2/common/common.go +++ b/client/v2/common/common.go @@ -175,6 +175,12 @@ func (client *Client) submitForm(ctx context.Context, response interface{}, path responseErr := extractError(resp.StatusCode, bodyBytes) + // The caller wants a string + if strResponse, ok := response.(*string); ok { + *strResponse = string(bodyBytes) + return err + } + // Attempt to unmarshal a response regardless of whether or not there was an error. err = json.Unmarshal(bodyBytes, response) if responseErr != nil { diff --git a/test/indexer_integration_test.go b/test/indexer_integration_test.go index fb56a40f..caa593f5 100644 --- a/test/indexer_integration_test.go +++ b/test/indexer_integration_test.go @@ -589,7 +589,11 @@ func theParsedResponseShouldEqual(jsonfileName string) error { var responseJson string baselinePath := path.Join("./features/resources/", jsonfileName) - responseJson = string(json.Encode(response)) + if responseStr, ok := response.(string); ok { + responseJson = responseStr + } else { + responseJson = string(json.Encode(response)) + } return VerifyResponse(baselinePath, responseJson) } diff --git a/test/responses_unit_test.go b/test/responses_unit_test.go index 46e4e7f1..12831be7 100644 --- a/test/responses_unit_test.go +++ b/test/responses_unit_test.go @@ -140,6 +140,8 @@ func weMakeAnyCallTo(client /* algod/indexer */, endpoint string) (err error) { response, err = algodC.TealDryrun(models.DryrunRequest{}).Do(context.Background()) case "Proof": response, err = algodC.GetProof(10, "asdf").Do(context.Background()) + case "GetGenesis": + response, err = algodC.GetGenesis().Do(context.Background()) case "any": // This is an error case // pickup the error as the response @@ -169,7 +171,11 @@ func theParsedResponseShouldEqualTheMockResponse() error { parts := strings.SplitAfterN(responseJson, ":", 2) responseJson = parts[1] } else { - responseJson = string(json.Encode(response)) + if responseStr, ok := response.(string); ok { + responseJson = responseStr + } else { + responseJson = string(json.Encode(response)) + } } return VerifyResponse(baselinePath, responseJson) From 5d59dfcf6a3b8c2ca13983dc57255109ca67c1f9 Mon Sep 17 00:00:00 2001 From: John Lee Date: Tue, 27 Apr 2021 14:59:21 -0400 Subject: [PATCH 2/2] Update CHANGELOG. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79454ba5..d3d995d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.7.0 +# Bugfix +- Fix GetGenesis endpoint. # 1.6.0 # Added - Code generation for more of the http client