@@ -20,53 +20,83 @@ func TestServer(t *testing.T) {
2020 defer cancel ()
2121
2222 tests := []struct {
23- desc string
24- reqState string
25- port int
26- q url.Values
27- failPage bool
28- statusCode int
23+ desc string
24+ reqState string
25+ port int
26+ q url.Values
27+ failPage bool
28+ statusCode int
29+ successPage []byte
30+ errorPage []byte
2931 }{
3032 {
31- desc : "Error: Query Values has 'error' key" ,
32- reqState : "state" ,
33- port : 0 ,
34- q : url.Values {"state" : []string {"state" }, "error" : []string {"error" }},
35- statusCode : 200 ,
36- failPage : true ,
33+ desc : "Error: Query Values has 'error' key" ,
34+ reqState : "state" ,
35+ port : 0 ,
36+ q : url.Values {"state" : []string {"state" }, "error" : []string {"error" }},
37+ statusCode : 200 ,
38+ failPage : true ,
39+ successPage : nil ,
40+ errorPage : nil ,
3741 },
3842 {
39- desc : "Error: Query Values missing 'state' key" ,
40- reqState : "state" ,
41- port : 0 ,
42- q : url.Values {"code" : []string {"code" }},
43- statusCode : http .StatusInternalServerError ,
43+ desc : "Error: Query Values missing 'state' key" ,
44+ reqState : "state" ,
45+ port : 0 ,
46+ q : url.Values {"code" : []string {"code" }},
47+ statusCode : http .StatusInternalServerError ,
48+ successPage : nil ,
49+ errorPage : nil ,
4450 },
4551 {
46- desc : "Error: Query Values missing had 'state' key value that was different that requested" ,
47- reqState : "state" ,
48- port : 0 ,
49- q : url.Values {"state" : []string {"etats" }, "code" : []string {"code" }},
50- statusCode : http .StatusInternalServerError ,
52+ desc : "Error: Query Values missing had 'state' key value that was different that requested" ,
53+ reqState : "state" ,
54+ port : 0 ,
55+ q : url.Values {"state" : []string {"etats" }, "code" : []string {"code" }},
56+ statusCode : http .StatusInternalServerError ,
57+ successPage : nil ,
58+ errorPage : nil ,
5159 },
5260 {
53- desc : "Error: Query Values missing 'code' key" ,
54- reqState : "state" ,
55- port : 0 ,
56- q : url.Values {"state" : []string {"state" }},
57- statusCode : http .StatusInternalServerError ,
61+ desc : "Error: Query Values missing 'code' key" ,
62+ reqState : "state" ,
63+ port : 0 ,
64+ q : url.Values {"state" : []string {"state" }},
65+ statusCode : http .StatusInternalServerError ,
66+ successPage : nil ,
67+ errorPage : nil ,
5868 },
5969 {
60- desc : "Success" ,
61- reqState : "state" ,
62- port : 0 ,
63- q : url.Values {"state" : []string {"state" }, "code" : []string {"code" }},
64- statusCode : 200 ,
70+ desc : "Success" ,
71+ reqState : "state" ,
72+ port : 0 ,
73+ q : url.Values {"state" : []string {"state" }, "code" : []string {"code" }},
74+ statusCode : 200 ,
75+ successPage : nil ,
76+ errorPage : nil ,
77+ },
78+ {
79+ desc : "Success, with optional success page" ,
80+ reqState : "state" ,
81+ port : 0 ,
82+ q : url.Values {"state" : []string {"state" }, "code" : []string {"code" }},
83+ statusCode : 200 ,
84+ successPage : []byte ("test option success page" ),
85+ errorPage : nil ,
86+ },
87+ {
88+ desc : "Error: Query Values missing 'state' key, and optional error page" ,
89+ reqState : "state" ,
90+ port : 0 ,
91+ q : url.Values {"code" : []string {"code" }},
92+ statusCode : http .StatusInternalServerError ,
93+ successPage : nil ,
94+ errorPage : []byte ("test option error page" ),
6595 },
6696 }
6797
6898 for _ , test := range tests {
69- serv , err := New (test .reqState , test .port )
99+ serv , err := New (test .reqState , test .port , test . successPage , test . errorPage )
70100 if err != nil {
71101 panic (err )
72102 }
@@ -129,6 +159,20 @@ func TestServer(t *testing.T) {
129159 continue
130160 }
131161
162+ if len (test .successPage ) > 0 {
163+ if ! strings .Contains (string (content ), "test option success page" ) {
164+ t .Errorf ("TestServer(%s): -want/+got:\n test option error page" , test .desc )
165+ }
166+ continue
167+
168+ }
169+ if len (test .errorPage ) > 0 {
170+ if ! strings .Contains (string (content ), "test option error page" ) {
171+ t .Errorf ("TestServer(%s): -want/+got:\n test option error page" , test .desc )
172+ }
173+ continue
174+ }
175+
132176 if ! strings .Contains (string (content ), "Authentication Complete" ) {
133177 t .Errorf ("TestServer(%s): got failed page, okay page" , test .desc )
134178 }
0 commit comments