@@ -2,13 +2,11 @@ package routing
22
33import (
44 "fmt"
5- "net/http"
6- "net/url"
7-
5+ httpv1alpha1 "github.com/kedacore/http-add-on/operator/apis/http/v1alpha1"
86 . "github.com/onsi/ginkgo/v2"
97 . "github.com/onsi/gomega"
10-
11- httpv1alpha1 "github.com/kedacore/http-add-on/operator/apis/http/v1alpha1 "
8+ "net/http"
9+ "net/url "
1210)
1311
1412var _ = Describe ("Key" , func () {
@@ -125,23 +123,36 @@ var _ = Describe("Key", func() {
125123 })
126124
127125 Context ("NewFromRequest" , func () {
126+ const (
127+ host = "kubernetes.io"
128+ path = "abc/def"
129+ norm0 = "//kubernetes.io/abc/def/"
130+ norm1 = "//get-thing/abc/def/"
131+ serviceHeader = "x-service-action-a"
132+ serviceHost = "get-thing"
133+ )
134+
128135 It ("returns expected key for Request" , func () {
129- const (
130- host = "kubernetes.io"
131- path = "abc/def"
132- norm = "//kubernetes.io/abc/def/"
133- )
136+ r , err := http .NewRequest ("GET" , fmt .Sprintf ("https://%s:443/%s?123=456#789" , host , path ), nil )
137+ Expect (err ).NotTo (HaveOccurred ())
138+ Expect (r ).NotTo (BeNil ())
139+
140+ key := NewKeyFromRequest (r , "" )
141+ Expect (key ).To (Equal (Key (norm0 )))
142+ })
134143
144+ It ("returns service host for Request with http routing header" , func () {
135145 r , err := http .NewRequest ("GET" , fmt .Sprintf ("https://%s:443/%s?123=456#789" , host , path ), nil )
136146 Expect (err ).NotTo (HaveOccurred ())
137147 Expect (r ).NotTo (BeNil ())
148+ r .Header .Set (serviceHeader , serviceHost )
138149
139- key := NewKeyFromRequest (r )
140- Expect (key ).To (Equal (Key (norm )))
150+ key := NewKeyFromRequest (r , serviceHeader )
151+ Expect (key ).To (Equal (Key (norm1 )))
141152 })
142153
143154 It ("returns nil for nil Request" , func () {
144- key := NewKeyFromRequest (nil )
155+ key := NewKeyFromRequest (nil , "" )
145156 Expect (key ).To (BeNil ())
146157 })
147158 })
0 commit comments