github.com/cloudwego/kitex@v0.9.0/pkg/generic/option_test.go (about) 1 /* 2 * Copyright 2023 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package generic 18 19 import ( 20 "testing" 21 22 "github.com/cloudwego/dynamicgo/conv" 23 24 "github.com/cloudwego/kitex/internal/test" 25 ) 26 27 func TestWithCustomDynamicGoConvOpts(t *testing.T) { 28 convOpts := conv.Options{WriteRequireField: true, WriteDefaultField: true} 29 var opt []Option 30 opt = append(opt, WithCustomDynamicGoConvOpts(&convOpts)) 31 var opts Options 32 opts.apply(opt) 33 test.DeepEqual(t, opts.dynamicgoConvOpts, convOpts) 34 } 35 36 func TestUseRawBodyForHTTPResp(t *testing.T) { 37 var opt []Option 38 opt = append(opt, UseRawBodyForHTTPResp(true)) 39 var opts Options 40 test.Assert(t, !opts.useRawBodyForHTTPResp) 41 opts.apply(opt) 42 test.Assert(t, opts.useRawBodyForHTTPResp) 43 opt = opt[0:0] 44 opt = append(opt, UseRawBodyForHTTPResp(false)) 45 opts.apply(opt) 46 test.Assert(t, !opts.useRawBodyForHTTPResp) 47 }