Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
import cycle
Browse files Browse the repository at this point in the history
reinkrul committed Jan 5, 2024
1 parent 96f6a98 commit 271d125
Showing 4 changed files with 9 additions and 14 deletions.
8 changes: 3 additions & 5 deletions discovery/api/v1/client/http.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ import (
"fmt"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/discovery"
v1 "github.com/nuts-foundation/nuts-node/discovery/api/v1"
"io"
"net/http"
@@ -64,10 +63,10 @@ func (h HTTPInvoker) Register(ctx context.Context, serviceEndpointURL string, pr
return nil
}

func (h HTTPInvoker) Get(ctx context.Context, serviceEndpointURL string, tag *discovery.Tag) ([]vc.VerifiablePresentation, *discovery.Tag, error) {
func (h HTTPInvoker) Get(ctx context.Context, serviceEndpointURL string, tag *string) ([]vc.VerifiablePresentation, *string, error) {
httpRequest, err := http.NewRequestWithContext(ctx, http.MethodGet, serviceEndpointURL, nil)
if tag != nil {
httpRequest.URL.RawQuery = url.Values{"tag": []string{string(*tag)}}.Encode()
httpRequest.URL.RawQuery = url.Values{"tag": []string{*tag}}.Encode()
}
if err != nil {
return nil, nil, err
@@ -88,6 +87,5 @@ func (h HTTPInvoker) Get(ctx context.Context, serviceEndpointURL string, tag *di
if err := json.Unmarshal(responseData, &result); err != nil {
return nil, nil, fmt.Errorf("failed to unmarshal response from remote Discovery Service (url=%s): %w", serviceEndpointURL, err)
}
resultTag := discovery.Tag(result.Tag)
return result.Entries, &resultTag, nil
return result.Entries, &result.Tag, nil
}
7 changes: 3 additions & 4 deletions discovery/api/v1/client/http_test.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"context"
ssi "github.com/nuts-foundation/go-did"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/discovery"
testHTTP "github.com/nuts-foundation/nuts-node/test/http"
"github.com/stretchr/testify/assert"
"net/http"
@@ -59,7 +58,7 @@ func TestHTTPInvoker_Get(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, presentations, 1)
assert.Empty(t, handler.RequestQuery.Get("tag"))
assert.Equal(t, discovery.Tag(serverTag), *tag)
assert.Equal(t, serverTag, *tag)
})
t.Run("tag provided by client", func(t *testing.T) {
handler := &testHTTP.Handler{StatusCode: http.StatusOK}
@@ -70,13 +69,13 @@ func TestHTTPInvoker_Get(t *testing.T) {
server := httptest.NewServer(handler)
client := New(server.Client())

inputTag := discovery.Tag(clientTag)
inputTag := clientTag
presentations, tag, err := client.Get(context.Background(), server.URL, &inputTag)

assert.NoError(t, err)
assert.Len(t, presentations, 1)
assert.Equal(t, clientTag, handler.RequestQuery.Get("tag"))
assert.Equal(t, discovery.Tag(serverTag), *tag)
assert.Equal(t, serverTag, *tag)
})
t.Run("server returns invalid status code", func(t *testing.T) {
handler := &testHTTP.Handler{StatusCode: http.StatusInternalServerError}
3 changes: 1 addition & 2 deletions discovery/api/v1/client/interface.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ package client
import (
"context"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/discovery"
)

// Invoker is the interface for the client that invokes the remote Discovery Service.
@@ -31,5 +30,5 @@ type Invoker interface {

// Get retrieves Verifiable Presentations from the remote Discovery Service, that were added since the given tag.
// If tag is nil, all Verifiable Presentations are retrieved.
Get(ctx context.Context, serviceEndpointURL string, tag *discovery.Tag) ([]vc.VerifiablePresentation, *discovery.Tag, error)
Get(ctx context.Context, serviceEndpointURL string, tag *string) ([]vc.VerifiablePresentation, *string, error)
}
5 changes: 2 additions & 3 deletions discovery/api/v1/client/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 271d125

Please sign in to comment.