github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/acceptor/http_client_test.go (about) 1 // (c) Copyright IBM Corp. 2024 2 3 package acceptor_test 4 5 import ( 6 "os" 7 "testing" 8 "time" 9 10 "github.com/instana/go-sensor/acceptor" 11 ) 12 13 func TestNewHTTPClient(t *testing.T) { 14 type args struct { 15 timeout time.Duration 16 } 17 tests := []struct { 18 name string 19 args args 20 wantErr bool 21 }{ 22 { 23 name: "success", 24 args: args{ 25 timeout: 500 * time.Millisecond, 26 }, 27 wantErr: false, 28 }, 29 { 30 name: "err", 31 args: args{ 32 timeout: 500 * time.Millisecond, 33 }, 34 wantErr: true, 35 }, 36 } 37 for _, tt := range tests { 38 if !tt.wantErr { 39 os.Setenv("INSTANA_ENDPOINT_PROXY", "localhost") 40 } else { 41 os.Setenv("INSTANA_ENDPOINT_PROXY", "http://{example.com") 42 } 43 t.Run(tt.name, func(t *testing.T) { 44 _, err := acceptor.NewHTTPClient(tt.args.timeout) 45 if (err != nil) != tt.wantErr { 46 t.Errorf("NewHTTPClient() error = %v, wantErr %v", err, tt.wantErr) 47 return 48 } 49 }) 50 } 51 }