github.com/cloudwego/hertz@v0.9.3/pkg/network/dialer/dialer_test.go (about) 1 /* 2 * Copyright 2022 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 dialer 18 19 import ( 20 "crypto/tls" 21 "errors" 22 "net" 23 "testing" 24 "time" 25 26 "github.com/cloudwego/hertz/pkg/common/test/assert" 27 "github.com/cloudwego/hertz/pkg/network" 28 ) 29 30 func TestDialer(t *testing.T) { 31 SetDialer(&mockDialer{}) 32 dialer := DefaultDialer() 33 assert.DeepEqual(t, &mockDialer{}, dialer) 34 35 _, err := AddTLS(nil, nil) 36 assert.NotNil(t, err) 37 38 _, err = DialConnection("", "", 0, nil) 39 assert.NotNil(t, err) 40 41 _, err = DialTimeout("", "", 0, nil) 42 assert.NotNil(t, err) 43 } 44 45 type mockDialer struct{} 46 47 func (m *mockDialer) DialConnection(network, address string, timeout time.Duration, tlsConfig *tls.Config) (conn network.Conn, err error) { 48 return nil, errors.New("method not implement") 49 } 50 51 func (m *mockDialer) DialTimeout(network, address string, timeout time.Duration, tlsConfig *tls.Config) (conn net.Conn, err error) { 52 return nil, errors.New("method not implement") 53 } 54 55 func (m *mockDialer) AddTLS(conn network.Conn, tlsConfig *tls.Config) (network.Conn, error) { 56 return nil, errors.New("method not implement") 57 }