2017-09-14 20:14:31 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-09-29 15:09:41 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2017-09-14 20:14:31 +00:00
|
|
|
)
|
|
|
|
|
2017-09-29 15:09:41 +00:00
|
|
|
// localMethods are methods that should be executed locally.
|
|
|
|
var localTestMethods = []string{"some_weirdo_method", "shh_newMessageFilter", "eth_accounts"}
|
2017-09-14 20:14:31 +00:00
|
|
|
|
|
|
|
func TestRouteWithUpstream(t *testing.T) {
|
|
|
|
router := newRouter(true)
|
|
|
|
|
2017-09-19 09:52:38 +00:00
|
|
|
for _, method := range remoteMethods {
|
2017-09-25 16:04:40 +00:00
|
|
|
require.True(t, router.routeRemote(method), "method "+method+" should routed to remote")
|
2017-09-14 20:14:31 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 15:09:41 +00:00
|
|
|
for _, method := range localTestMethods {
|
2017-09-19 09:52:38 +00:00
|
|
|
t.Run(method, func(t *testing.T) {
|
2017-09-25 16:04:40 +00:00
|
|
|
require.False(t, router.routeRemote(method), "method "+method+" should routed to local")
|
2017-09-19 09:52:38 +00:00
|
|
|
})
|
2017-09-14 20:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRouteWithoutUpstream(t *testing.T) {
|
|
|
|
router := newRouter(false)
|
|
|
|
|
2017-09-19 09:52:38 +00:00
|
|
|
for _, method := range remoteMethods {
|
2017-09-25 16:04:40 +00:00
|
|
|
require.False(t, router.routeRemote(method), "method "+method+" should routed to locally without UpstreamEnabled")
|
2017-09-14 20:14:31 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 15:09:41 +00:00
|
|
|
for _, method := range localTestMethods {
|
2017-09-25 16:04:40 +00:00
|
|
|
require.False(t, router.routeRemote(method), "method "+method+" should routed to local")
|
2017-09-14 20:14:31 +00:00
|
|
|
}
|
|
|
|
}
|