github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/utils/http_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestGetHTTPClient(t *testing.T) {
    13  	assert.NotNil(t, GetHTTPClient())
    14  }
    15  
    16  func TestGetUnixSockClient(t *testing.T) {
    17  	assert.NotNil(t, GetUnixSockClient())
    18  }
    19  
    20  func TestGetHTTPSClient(t *testing.T) {
    21  	ctx := context.Background()
    22  	client, err := GetHTTPSClient(ctx, "", "abc", "", "", "")
    23  	assert.NoError(t, err)
    24  	assert.NotNil(t, client)
    25  
    26  	client, err = GetHTTPSClient(ctx, os.TempDir(), "abc", "1", "2", "3")
    27  	assert.Error(t, err)
    28  	assert.Nil(t, client)
    29  }
    30  
    31  func TestCheckRedirect(t *testing.T) {
    32  	via := []*http.Request{{Method: http.MethodGet}}
    33  	err := checkRedirect(nil, via)
    34  	assert.Equal(t, err, http.ErrUseLastResponse)
    35  }