This repository has been archived by the owner on Mar 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from bstasyszyn/292
feat: Add REST endpoint for Sidetree version
- Loading branch information
Showing
8 changed files
with
98 additions
and
2 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
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
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
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
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
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,27 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package sidetreehandler | ||
|
||
import ( | ||
"github.com/trustbloc/sidetree-fabric/pkg/rest/versionhandler" | ||
) | ||
|
||
const ( | ||
moduleName = "Sidetree" | ||
) | ||
|
||
// Version handles version requests | ||
type Version struct { | ||
*versionhandler.Version | ||
} | ||
|
||
// NewVersionHandler returns a new Version handler | ||
func NewVersionHandler(channelID string, cfg Config) *Version { | ||
return &Version{ | ||
Version: versionhandler.New(channelID, cfg.BasePath, moduleName, cfg.Version), | ||
} | ||
} |
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,59 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package sidetreehandler | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/trustbloc/sidetree-fabric/pkg/httpserver" | ||
"github.com/trustbloc/sidetree-fabric/pkg/rest/versionhandler" | ||
) | ||
|
||
const ( | ||
channel1 = "channel1" | ||
version = "0.1.3" | ||
) | ||
|
||
func TestNewVersionHandler(t *testing.T) { | ||
handlerCfg := Config{ | ||
BasePath: "/sidetree", | ||
} | ||
|
||
h := NewVersionHandler(channel1, handlerCfg) | ||
require.NotNil(t, h) | ||
|
||
require.Equal(t, "/sidetree/version", h.Path()) | ||
require.Equal(t, http.MethodGet, h.Method()) | ||
} | ||
|
||
func TestVersion_Handler(t *testing.T) { | ||
handlerCfg := Config{ | ||
BasePath: "/sidetree", | ||
Version: version, | ||
} | ||
|
||
h := NewVersionHandler(channel1, handlerCfg) | ||
require.NotNil(t, h) | ||
|
||
rw := httptest.NewRecorder() | ||
req := httptest.NewRequest(http.MethodGet, "/sidetree/version", nil) | ||
|
||
h.Handler()(rw, req) | ||
|
||
require.Equal(t, http.StatusOK, rw.Result().StatusCode) | ||
require.Equal(t, httpserver.ContentTypeJSON, rw.Header().Get(httpserver.ContentTypeHeader)) | ||
|
||
resp := &versionhandler.Response{} | ||
require.NoError(t, json.Unmarshal(rw.Body.Bytes(), resp)) | ||
require.Equal(t, moduleName, resp.Name) | ||
require.Equal(t, version, resp.Version) | ||
} |
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