@@ -87,3 +87,53 @@ func TestBodyDumpFails(t *testing.T) {
87
87
}
88
88
})
89
89
}
90
+
91
+ func TestBodyDumpResponseWriter_CanNotFlush (t * testing.T ) {
92
+ bdrw := bodyDumpResponseWriter {
93
+ ResponseWriter : new (testResponseWriterNoFlushHijack ), // this RW does not support flush
94
+ }
95
+
96
+ assert .PanicsWithError (t , "response writer flushing is not supported" , func () {
97
+ bdrw .Flush ()
98
+ })
99
+ }
100
+
101
+ func TestBodyDumpResponseWriter_CanFlush (t * testing.T ) {
102
+ trwu := testResponseWriterUnwrapperHijack {testResponseWriterUnwrapper : testResponseWriterUnwrapper {rw : httptest .NewRecorder ()}}
103
+ bdrw := bodyDumpResponseWriter {
104
+ ResponseWriter : & trwu ,
105
+ }
106
+
107
+ bdrw .Flush ()
108
+ assert .Equal (t , 1 , trwu .unwrapCalled )
109
+ }
110
+
111
+ func TestBodyDumpResponseWriter_CanUnwrap (t * testing.T ) {
112
+ trwu := & testResponseWriterUnwrapper {rw : httptest .NewRecorder ()}
113
+ bdrw := bodyDumpResponseWriter {
114
+ ResponseWriter : trwu ,
115
+ }
116
+
117
+ result := bdrw .Unwrap ()
118
+ assert .Equal (t , trwu , result )
119
+ }
120
+
121
+ func TestBodyDumpResponseWriter_CanHijack (t * testing.T ) {
122
+ trwu := testResponseWriterUnwrapperHijack {testResponseWriterUnwrapper : testResponseWriterUnwrapper {rw : httptest .NewRecorder ()}}
123
+ bdrw := bodyDumpResponseWriter {
124
+ ResponseWriter : & trwu , // this RW supports hijacking through unwrapping
125
+ }
126
+
127
+ _ , _ , err := bdrw .Hijack ()
128
+ assert .EqualError (t , err , "can hijack" )
129
+ }
130
+
131
+ func TestBodyDumpResponseWriter_CanNotHijack (t * testing.T ) {
132
+ trwu := testResponseWriterUnwrapper {rw : httptest .NewRecorder ()}
133
+ bdrw := bodyDumpResponseWriter {
134
+ ResponseWriter : & trwu , // this RW supports hijacking through unwrapping
135
+ }
136
+
137
+ _ , _ , err := bdrw .Hijack ()
138
+ assert .EqualError (t , err , "feature not supported" )
139
+ }
0 commit comments