@@ -36,6 +36,7 @@ type routeTest struct {
36
36
scheme string // the expected scheme of the built URL
37
37
host string // the expected host of the built URL
38
38
path string // the expected path of the built URL
39
+ query string // the expected query string to match
39
40
pathTemplate string // the expected path template of the route
40
41
hostTemplate string // the expected host template of the route
41
42
methods []string // the expected route methods
@@ -744,6 +745,7 @@ func TestQueries(t *testing.T) {
744
745
vars : map [string ]string {},
745
746
host : "" ,
746
747
path : "" ,
748
+ query : "foo=bar&baz=ding" ,
747
749
shouldMatch : true ,
748
750
},
749
751
{
@@ -753,6 +755,7 @@ func TestQueries(t *testing.T) {
753
755
vars : map [string ]string {},
754
756
host : "" ,
755
757
path : "" ,
758
+ query : "foo=bar&baz=ding" ,
756
759
pathTemplate : `/api` ,
757
760
hostTemplate : `www.example.com` ,
758
761
shouldMatch : true ,
@@ -764,6 +767,7 @@ func TestQueries(t *testing.T) {
764
767
vars : map [string ]string {},
765
768
host : "" ,
766
769
path : "" ,
770
+ query : "foo=bar&baz=ding" ,
767
771
pathTemplate : `/api` ,
768
772
hostTemplate : `www.example.com` ,
769
773
shouldMatch : true ,
@@ -784,6 +788,7 @@ func TestQueries(t *testing.T) {
784
788
vars : map [string ]string {"v1" : "bar" },
785
789
host : "" ,
786
790
path : "" ,
791
+ query : "foo=bar" ,
787
792
shouldMatch : true ,
788
793
},
789
794
{
@@ -793,6 +798,7 @@ func TestQueries(t *testing.T) {
793
798
vars : map [string ]string {"v1" : "bar" , "v2" : "ding" },
794
799
host : "" ,
795
800
path : "" ,
801
+ query : "foo=bar&baz=ding" ,
796
802
shouldMatch : true ,
797
803
},
798
804
{
@@ -802,6 +808,7 @@ func TestQueries(t *testing.T) {
802
808
vars : map [string ]string {"v1" : "10" },
803
809
host : "" ,
804
810
path : "" ,
811
+ query : "foo=10" ,
805
812
shouldMatch : true ,
806
813
},
807
814
{
@@ -820,6 +827,7 @@ func TestQueries(t *testing.T) {
820
827
vars : map [string ]string {"v1" : "1" },
821
828
host : "" ,
822
829
path : "" ,
830
+ query : "foo=1" ,
823
831
shouldMatch : true ,
824
832
},
825
833
{
@@ -829,6 +837,7 @@ func TestQueries(t *testing.T) {
829
837
vars : map [string ]string {"v1" : "1" },
830
838
host : "" ,
831
839
path : "" ,
840
+ query : "foo=1" ,
832
841
shouldMatch : true ,
833
842
},
834
843
{
@@ -847,6 +856,7 @@ func TestQueries(t *testing.T) {
847
856
vars : map [string ]string {"v1" : "1a" },
848
857
host : "" ,
849
858
path : "" ,
859
+ query : "foo=1a" ,
850
860
shouldMatch : true ,
851
861
},
852
862
{
@@ -865,6 +875,7 @@ func TestQueries(t *testing.T) {
865
875
vars : map [string ]string {"v-1" : "bar" },
866
876
host : "" ,
867
877
path : "" ,
878
+ query : "foo=bar" ,
868
879
shouldMatch : true ,
869
880
},
870
881
{
@@ -874,6 +885,7 @@ func TestQueries(t *testing.T) {
874
885
vars : map [string ]string {"v-1" : "bar" , "v-2" : "ding" },
875
886
host : "" ,
876
887
path : "" ,
888
+ query : "foo=bar&baz=ding" ,
877
889
shouldMatch : true ,
878
890
},
879
891
{
@@ -883,6 +895,7 @@ func TestQueries(t *testing.T) {
883
895
vars : map [string ]string {"v-1" : "10" },
884
896
host : "" ,
885
897
path : "" ,
898
+ query : "foo=10" ,
886
899
shouldMatch : true ,
887
900
},
888
901
{
@@ -892,6 +905,7 @@ func TestQueries(t *testing.T) {
892
905
vars : map [string ]string {"v-1" : "1a" },
893
906
host : "" ,
894
907
path : "" ,
908
+ query : "foo=1a" ,
895
909
shouldMatch : true ,
896
910
},
897
911
{
@@ -901,6 +915,7 @@ func TestQueries(t *testing.T) {
901
915
vars : map [string ]string {},
902
916
host : "" ,
903
917
path : "" ,
918
+ query : "foo=" ,
904
919
shouldMatch : true ,
905
920
},
906
921
{
@@ -919,6 +934,7 @@ func TestQueries(t *testing.T) {
919
934
vars : map [string ]string {},
920
935
host : "" ,
921
936
path : "" ,
937
+ query : "foo=" ,
922
938
shouldMatch : true ,
923
939
},
924
940
{
@@ -946,6 +962,7 @@ func TestQueries(t *testing.T) {
946
962
vars : map [string ]string {"foo" : "" },
947
963
host : "" ,
948
964
path : "" ,
965
+ query : "foo=" ,
949
966
shouldMatch : true ,
950
967
},
951
968
{
@@ -1537,6 +1554,7 @@ func testRoute(t *testing.T, test routeTest) {
1537
1554
route := test .route
1538
1555
vars := test .vars
1539
1556
shouldMatch := test .shouldMatch
1557
+ query := test .query
1540
1558
shouldRedirect := test .shouldRedirect
1541
1559
uri := url.URL {
1542
1560
Scheme : test .scheme ,
@@ -1606,6 +1624,13 @@ func testRoute(t *testing.T, test routeTest) {
1606
1624
return
1607
1625
}
1608
1626
}
1627
+ if query != "" {
1628
+ u , _ := route .URL (mapToPairs (match .Vars )... )
1629
+ if query != u .RawQuery {
1630
+ t .Errorf ("(%v) URL query not equal: expected %v, got %v" , test .title , query , u .RawQuery )
1631
+ return
1632
+ }
1633
+ }
1609
1634
if shouldRedirect && match .Handler == nil {
1610
1635
t .Errorf ("(%v) Did not redirect" , test .title )
1611
1636
return
0 commit comments