forked from gojek/fiber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy_caller_test.go
36 lines (26 loc) · 946 Bytes
/
proxy_caller_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package fiber_test
import (
"context"
"fmt"
"net/url"
"testing"
"github.com/gojek/fiber"
testUtilsHttp "github.com/gojek/fiber/internal/testutils/http"
"github.com/stretchr/testify/assert"
)
func TestProxyCaller_Dispatch(t *testing.T) {
host, path := "http://localhost:8080", "/recommendations/search"
req := testUtilsHttp.MockReq("POST", fmt.Sprintf("%s%s", host, path), "")
dispatcher := new(MockDispatcher)
dispatcher.On("Do", req).Return(nil)
backendName := "test-backend"
backendEndpoint := "http://proxy-test:9090/api"
backend := fiber.NewBackend(backendName, backendEndpoint)
caller, _ := fiber.NewCaller(backendName, dispatcher)
proxy := fiber.NewProxy(backend, caller)
assert.Equal(t, backendName, proxy.ID())
<-proxy.Dispatch(context.Background(), req).Iter()
expectedURL, _ := url.Parse(fmt.Sprintf("%s%s", backendEndpoint, path))
assert.Equal(t, expectedURL, req.URL)
dispatcher.AssertExpectations(t)
}