Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #109 from DRK3/FixIntermittentFailingUnitTest
Browse files Browse the repository at this point in the history
fix: intermittently failing unit test
  • Loading branch information
Derek Trider authored Aug 27, 2020
2 parents 517f872 + 80cb176 commit 4940e3a
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions pkg/restapi/operation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,24 +732,37 @@ func TestReadAllDocuments(t *testing.T) {
readAllDocumentsEndpointHandler.Handle().ServeHTTP(rr, req)
require.Equal(t, http.StatusOK, rr.Code)

// This unmarshalling and remarshalling is done so that we can directly compare the expected output
// with the output from the EDV service.
var expectedEncryptedDoc1 models.EncryptedDocument
var actualDocs []models.EncryptedDocument

err = json.Unmarshal([]byte(testEncryptedDocument), &expectedEncryptedDoc1)
err = json.Unmarshal(rr.Body.Bytes(), &actualDocs)
require.NoError(t, err)

var expectedEncryptedDoc2 models.EncryptedDocument
// Marshal to bytes so that we can compare with the expected docs easily
actualDocumentsBytes1, err := json.Marshal(actualDocs[0])
require.NoError(t, err)

err = json.Unmarshal([]byte(testEncryptedDocument2), &expectedEncryptedDoc2)
actualDocumentsBytes2, err := json.Marshal(actualDocs[1])
require.NoError(t, err)

expectedEncryptedDocs := []models.EncryptedDocument{expectedEncryptedDoc1, expectedEncryptedDoc2}
var gotExpectedDocs bool

expectedEncryptedDocsBytes, err := json.Marshal(expectedEncryptedDocs)
require.NoError(t, err)
// The order of the returned docs can vary - either order is acceptable
if string(actualDocumentsBytes1) == testEncryptedDocument &&
string(actualDocumentsBytes2) == testEncryptedDocument2 {
gotExpectedDocs = true
} else if string(actualDocumentsBytes1) == testEncryptedDocument2 &&
string(actualDocumentsBytes2) == testEncryptedDocument {
gotExpectedDocs = true
}

require.True(t, gotExpectedDocs, `Expected these two documents (in any order):
Expected document 1: %s
Expected document 2: %s
require.Equal(t, string(expectedEncryptedDocsBytes), rr.Body.String())
Actual document 1: %s
Actual document 2: %s`, testEncryptedDocument, testEncryptedDocument2,
actualDocumentsBytes1, actualDocumentsBytes2)
})
t.Run("Vault does not exist", func(t *testing.T) {
op := New(memedvprovider.NewProvider())
Expand Down

0 comments on commit 4940e3a

Please sign in to comment.