-
Notifications
You must be signed in to change notification settings - Fork 14
/
url_replace_handler_test.go
44 lines (37 loc) · 1.1 KB
/
url_replace_handler_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
37
38
39
40
41
42
43
44
package nethttplibrary
import (
"errors"
"github.com/stretchr/testify/assert"
nethttp "net/http"
"testing"
)
type SpyPipeline struct {
client *nethttp.Client
receivedRequest *nethttp.Request
}
func (pipeline *SpyPipeline) Next(req *nethttp.Request, middlewareIndex int) (*nethttp.Response, error) {
pipeline.receivedRequest = req
return nil, errors.New("Spy executor only")
}
func newSpyPipeline() *SpyPipeline {
return &SpyPipeline{
client: getDefaultClientWithoutMiddleware(),
}
}
func (pipeline *SpyPipeline) GetReceivedRequest() *nethttp.Request {
return pipeline.receivedRequest
}
func TestURLReplacementHandler(t *testing.T) {
handler := NewUrlReplaceHandler(true, map[string]string{"/users/me-token-to-replace": "/me"})
if handler == nil {
t.Error("handler is nil")
}
url := "https://msgraph.com/users/me-token-to-replace/contactFolders"
req, err := nethttp.NewRequest(nethttp.MethodGet, url, nil)
if err != nil {
t.Error(err)
}
pipeline := newSpyPipeline()
_, _ = handler.Intercept(pipeline, 0, req)
assert.Equal(t, pipeline.GetReceivedRequest().URL.Path, "/me/contactFolders")
}