github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/routes/node_version_info_test.go (about) 1 package routes 2 3 import ( 4 "fmt" 5 "net/http" 6 "net/url" 7 "testing" 8 9 mocktestify "github.com/stretchr/testify/mock" 10 "github.com/stretchr/testify/require" 11 12 "github.com/onflow/flow-go/access" 13 "github.com/onflow/flow-go/access/mock" 14 "github.com/onflow/flow-go/cmd/build" 15 "github.com/onflow/flow-go/utils/unittest" 16 ) 17 18 func nodeVersionInfoURL(t *testing.T) string { 19 u, err := url.ParseRequestURI("/v1/node_version_info") 20 require.NoError(t, err) 21 22 return u.String() 23 } 24 25 func TestGetNodeVersionInfo(t *testing.T) { 26 backend := mock.NewAPI(t) 27 28 t.Run("get node version info", func(t *testing.T) { 29 req := getNodeVersionInfoRequest(t) 30 31 params := &access.NodeVersionInfo{ 32 Semver: build.Version(), 33 Commit: build.Commit(), 34 SporkId: unittest.IdentifierFixture(), 35 ProtocolVersion: unittest.Uint64InRange(10, 30), 36 SporkRootBlockHeight: unittest.Uint64InRange(1000, 10_000), 37 NodeRootBlockHeight: unittest.Uint64InRange(10_000, 100_000), 38 } 39 40 backend.Mock. 41 On("GetNodeVersionInfo", mocktestify.Anything). 42 Return(params, nil) 43 44 expected := nodeVersionInfoExpectedStr(params) 45 46 assertOKResponse(t, req, expected, backend) 47 mocktestify.AssertExpectationsForObjects(t, backend) 48 }) 49 } 50 51 func nodeVersionInfoExpectedStr(nodeVersionInfo *access.NodeVersionInfo) string { 52 return fmt.Sprintf(`{ 53 "semver": "%s", 54 "commit": "%s", 55 "spork_id": "%s", 56 "protocol_version": "%d", 57 "spork_root_block_height": "%d", 58 "node_root_block_height": "%d" 59 }`, 60 nodeVersionInfo.Semver, 61 nodeVersionInfo.Commit, 62 nodeVersionInfo.SporkId.String(), 63 nodeVersionInfo.ProtocolVersion, 64 nodeVersionInfo.SporkRootBlockHeight, 65 nodeVersionInfo.NodeRootBlockHeight, 66 ) 67 } 68 69 func getNodeVersionInfoRequest(t *testing.T) *http.Request { 70 req, err := http.NewRequest("GET", nodeVersionInfoURL(t), nil) 71 require.NoError(t, err) 72 return req 73 }