forked from manyminds/api2go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resolver_test.go
33 lines (28 loc) · 859 Bytes
/
resolver_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
package api2go
import (
"net/http"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Resolver test", func() {
Context("basic function of callback resolver", func() {
It("works", func() {
callback := func(r http.Request) string {
if r.Header.Get("lol") != "" {
return "funny"
}
return "unfunny"
}
resolver := NewCallbackResolver(callback)
Expect(resolver.GetBaseURL()).To(Equal("unfunny"))
req, err := http.NewRequest("GET", "/v1/posts", nil)
req.Header.Set("lol", "lol")
Expect(err).To(BeNil())
requestResolver, ok := resolver.(RequestAwareURLResolver)
Expect(ok).To(Equal(true), "does not implement interface")
Expect(requestResolver.GetBaseURL()).To(Equal("unfunny"))
requestResolver.SetRequest(*req)
Expect(requestResolver.GetBaseURL()).To(Equal("funny"))
})
})
})