@@ -109,6 +109,41 @@ func TestHttpThriftCodecWithDynamicGo(t *testing.T) {
109109 test .Assert (t , ok )
110110}
111111
112+ func TestHttpThriftCodecWithFailOnNilValueForRequired (t * testing.T ) {
113+ // without dynamicgo
114+ p , err := NewThriftFileProvider ("./http_test/idl/binary_echo.thrift" )
115+ test .Assert (t , err == nil )
116+ gOpts := & Options {dynamicgoConvOpts : DefaultHTTPDynamicGoConvOpts , failOnNilValueForRequiredField : true }
117+ htc := newHTTPThriftCodec (p , gOpts )
118+ test .Assert (t , ! htc .dynamicgoEnabled )
119+ test .Assert (t , ! htc .useRawBodyForHTTPResp )
120+ test .Assert (t , htc .failOnNilValueForRequiredField )
121+ test .DeepEqual (t , htc .convOpts , conv.Options {})
122+ test .DeepEqual (t , htc .convOptsWithThriftBase , conv.Options {})
123+ defer htc .Close ()
124+ test .Assert (t , htc .Name () == "HttpThrift" )
125+
126+ req := & HTTPRequest {Request : getStdHttpRequest ()}
127+ // wrong
128+ method , err := htc .getMethod ("test" )
129+ test .Assert (t , err .Error () == "req is invalid, need descriptor.HTTPRequest" && method == nil )
130+ // right
131+ method , err = htc .getMethod (req )
132+ test .Assert (t , err == nil && method .Name == "BinaryEcho" )
133+ test .Assert (t , method .StreamingMode == serviceinfo .StreamingNone )
134+ test .Assert (t , htc .svcName == "ExampleService" )
135+
136+ rw := htc .getMessageReaderWriter ()
137+ _ , ok := rw .(error )
138+ test .Assert (t , ! ok )
139+
140+ rw = htc .getMessageReaderWriter ()
141+ _ , ok = rw .(thrift.MessageWriter )
142+ test .Assert (t , ok )
143+ _ , ok = rw .(thrift.MessageReader )
144+ test .Assert (t , ok )
145+ }
146+
112147func getStdHttpRequest () * http.Request {
113148 body := map [string ]interface {}{
114149 "msg" : []byte ("hello" ),
0 commit comments