From b7ab286df29371a47dcf27d00bf7cbba56a45736 Mon Sep 17 00:00:00 2001 From: Rein Krul Date: Mon, 11 Dec 2023 15:53:05 +0100 Subject: [PATCH] test coverage --- discovery/api/v1/wapper_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/discovery/api/v1/wapper_test.go b/discovery/api/v1/wapper_test.go index e0931c724c..df838920f0 100644 --- a/discovery/api/v1/wapper_test.go +++ b/discovery/api/v1/wapper_test.go @@ -19,11 +19,13 @@ package v1 import ( + "errors" "github.com/nuts-foundation/go-did/vc" "github.com/nuts-foundation/nuts-node/discovery" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" + "net/http" "testing" ) @@ -62,6 +64,14 @@ func TestWrapper_GetPresentations(t *testing.T) { assert.Equal(t, latestTag, discovery.Tag(response.(GetPresentations200JSONResponse).Tag)) assert.Equal(t, presentations, response.(GetPresentations200JSONResponse).Entries) }) + t.Run("error", func(t *testing.T) { + test := newMockContext(t) + test.server.EXPECT().Get(serviceID, nil).Return(nil, nil, errors.New("foo")) + + _, err := test.wrapper.GetPresentations(nil, GetPresentationsRequestObject{ServiceID: serviceID}) + + assert.Error(t, err) + }) } func TestWrapper_RegisterPresentation(t *testing.T) { @@ -92,6 +102,20 @@ func TestWrapper_RegisterPresentation(t *testing.T) { }) } +func TestWrapper_ResolveStatusCode(t *testing.T) { + expected := map[error]int{ + discovery.ErrServerModeDisabled: http.StatusBadRequest, + discovery.ErrInvalidPresentation: http.StatusBadRequest, + errors.New("foo"): http.StatusInternalServerError, + } + wrapper := Wrapper{} + for err, expectedCode := range expected { + t.Run(err.Error(), func(t *testing.T) { + assert.Equal(t, expectedCode, wrapper.ResolveStatusCode(err)) + }) + } +} + type mockContext struct { ctrl *gomock.Controller server *discovery.MockServer