1- package traefik_query_to_header_test
1+ package query_to_header_test
22
33import (
44 "context"
55 "net/http"
66 "net/http/httptest"
77 "testing"
88
9- traefik_query_to_header "github.com/muench-dev/query-to-header"
9+ "github.com/muench-dev/query-to-header"
1010)
1111
1212func TestNew_RejectsNilConfig (t * testing.T ) {
1313 next := http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {})
1414
15- if _ , err := traefik_query_to_header .New (context .Background (), next , nil , "test" ); err == nil {
15+ if _ , err := query_to_header .New (context .Background (), next , nil , "test" ); err == nil {
1616 t .Fatal ("expected an error for a nil config, got none" )
1717 }
1818}
1919
2020func TestNew_RejectsIncompleteMapping (t * testing.T ) {
2121 next := http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {})
22- cfg := & traefik_query_to_header .Config {
23- Mappings : []traefik_query_to_header .Mapping {{Query : "token" }},
22+ cfg := & query_to_header .Config {
23+ Mappings : []query_to_header .Mapping {{Query : "token" }},
2424 }
2525
26- if _ , err := traefik_query_to_header .New (context .Background (), next , cfg , "test" ); err == nil {
26+ if _ , err := query_to_header .New (context .Background (), next , cfg , "test" ); err == nil {
2727 t .Fatal ("expected an error for a mapping missing a header name, got none" )
2828 }
2929}
3030
3131func TestServeHTTP_SetsHeaderFromQuery (t * testing.T ) {
32- cfg := & traefik_query_to_header .Config {
33- Mappings : []traefik_query_to_header .Mapping {
32+ cfg := & query_to_header .Config {
33+ Mappings : []query_to_header .Mapping {
3434 {Query : "token" , Header : "X-Token" },
3535 },
3636 }
@@ -40,7 +40,7 @@ func TestServeHTTP_SetsHeaderFromQuery(t *testing.T) {
4040 gotHeader = req .Header .Get ("X-Token" )
4141 })
4242
43- handler , err := traefik_query_to_header .New (context .Background (), next , cfg , "test" )
43+ handler , err := query_to_header .New (context .Background (), next , cfg , "test" )
4444 if err != nil {
4545 t .Fatalf ("unexpected error: %v" , err )
4646 }
@@ -56,8 +56,8 @@ func TestServeHTTP_SetsHeaderFromQuery(t *testing.T) {
5656}
5757
5858func TestServeHTTP_PrefixesValueWithBearer (t * testing.T ) {
59- cfg := & traefik_query_to_header .Config {
60- Mappings : []traefik_query_to_header .Mapping {
59+ cfg := & query_to_header .Config {
60+ Mappings : []query_to_header .Mapping {
6161 {Query : "token" , Header : "Authorization" , Bearer : true },
6262 },
6363 }
@@ -67,7 +67,7 @@ func TestServeHTTP_PrefixesValueWithBearer(t *testing.T) {
6767 gotHeader = req .Header .Get ("Authorization" )
6868 })
6969
70- handler , err := traefik_query_to_header .New (context .Background (), next , cfg , "test" )
70+ handler , err := query_to_header .New (context .Background (), next , cfg , "test" )
7171 if err != nil {
7272 t .Fatalf ("unexpected error: %v" , err )
7373 }
@@ -83,8 +83,8 @@ func TestServeHTTP_PrefixesValueWithBearer(t *testing.T) {
8383}
8484
8585func TestServeHTTP_DoesNotOverwriteExistingHeaderByDefault (t * testing.T ) {
86- cfg := & traefik_query_to_header .Config {
87- Mappings : []traefik_query_to_header .Mapping {
86+ cfg := & query_to_header .Config {
87+ Mappings : []query_to_header .Mapping {
8888 {Query : "token" , Header : "X-Token" },
8989 },
9090 }
@@ -94,7 +94,7 @@ func TestServeHTTP_DoesNotOverwriteExistingHeaderByDefault(t *testing.T) {
9494 gotHeader = req .Header .Get ("X-Token" )
9595 })
9696
97- handler , err := traefik_query_to_header .New (context .Background (), next , cfg , "test" )
97+ handler , err := query_to_header .New (context .Background (), next , cfg , "test" )
9898 if err != nil {
9999 t .Fatalf ("unexpected error: %v" , err )
100100 }
@@ -111,8 +111,8 @@ func TestServeHTTP_DoesNotOverwriteExistingHeaderByDefault(t *testing.T) {
111111}
112112
113113func TestServeHTTP_RemovesQueryParamWhenConfigured (t * testing.T ) {
114- cfg := & traefik_query_to_header .Config {
115- Mappings : []traefik_query_to_header .Mapping {
114+ cfg := & query_to_header .Config {
115+ Mappings : []query_to_header .Mapping {
116116 {Query : "token" , Header : "X-Token" , Remove : true },
117117 },
118118 }
@@ -122,7 +122,7 @@ func TestServeHTTP_RemovesQueryParamWhenConfigured(t *testing.T) {
122122 gotQuery = req .URL .RawQuery
123123 })
124124
125- handler , err := traefik_query_to_header .New (context .Background (), next , cfg , "test" )
125+ handler , err := query_to_header .New (context .Background (), next , cfg , "test" )
126126 if err != nil {
127127 t .Fatalf ("unexpected error: %v" , err )
128128 }
0 commit comments