prysm-pulse/validator/rpc/server_test.go
james-prysm c0fb16a96f
HTTP validator API: health endpoints (#13149)
* updating health endpoints

* updating tests

* updating tests

* moving where the header is written and adding allow origin header

* removing header

* Update validator/rpc/handlers_health.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update validator/rpc/handlers_health.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update validator/rpc/handlers_health.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* radek's comments

* Update handlers_health.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* adding the correct errors to handle error

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2023-11-02 15:51:21 +00:00

48 lines
1.6 KiB
Go

package rpc
import (
"net/http"
"testing"
"github.com/gorilla/mux"
pb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/v4/testing/require"
)
var _ pb.AuthServer = (*Server)(nil)
func TestServer_InitializeRoutes(t *testing.T) {
s := Server{
router: mux.NewRouter(),
}
err := s.InitializeRoutes()
require.NoError(t, err)
wantRouteList := map[string][]string{
"/eth/v1/keystores": {http.MethodGet, http.MethodPost, http.MethodDelete},
"/eth/v1/remotekeys": {http.MethodGet, http.MethodPost, http.MethodDelete},
"/eth/v1/validator/{pubkey}/gas_limit": {http.MethodGet, http.MethodPost, http.MethodDelete},
"/eth/v1/validator/{pubkey}/feerecipient": {http.MethodGet, http.MethodPost, http.MethodDelete},
"/eth/v1/validator/{pubkey}/voluntary_exit": {http.MethodPost},
"/v2/validator/health/version": {http.MethodGet},
"/v2/validator/health/logs/validator/stream": {http.MethodGet},
"/v2/validator/health/logs/beacon/stream": {http.MethodGet},
}
gotRouteList := make(map[string][]string)
err = s.router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
tpl, err1 := route.GetPathTemplate()
require.NoError(t, err1)
met, err2 := route.GetMethods()
require.NoError(t, err2)
methods, ok := gotRouteList[tpl]
if !ok {
gotRouteList[tpl] = []string{met[0]}
} else {
gotRouteList[tpl] = append(methods, met[0])
}
return nil
})
require.NoError(t, err)
require.DeepEqual(t, wantRouteList, gotRouteList)
}