github.com/argoproj/argo-cd/v3@v3.2.1/reposerver/apiclient/clientset_test.go (about)

     1  package apiclient_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/argoproj/argo-cd/v3/reposerver/apiclient"
    10  	"github.com/argoproj/argo-cd/v3/reposerver/apiclient/mocks"
    11  )
    12  
    13  func TestNewRepoServerClient_CorrectClientReturned(t *testing.T) {
    14  	mockClientset := &mocks.Clientset{
    15  		RepoServerServiceClient: &mocks.RepoServerServiceClient{},
    16  	}
    17  
    18  	closer, client, err := mockClientset.NewRepoServerClient()
    19  
    20  	require.NoError(t, err)
    21  	assert.NotNil(t, closer)
    22  	assert.NotNil(t, client)
    23  	assert.Equal(t, mockClientset.RepoServerServiceClient, client)
    24  }
    25  
    26  func TestNewRepoServerClientset_InvalidInput(t *testing.T) {
    27  	// Call the function with invalid inputs
    28  	invalidClientset := apiclient.NewRepoServerClientset("", -1, apiclient.TLSConfiguration{})
    29  
    30  	assert.NotNil(t, invalidClientset)
    31  	assert.Implements(t, (*apiclient.Clientset)(nil), invalidClientset)
    32  }
    33  
    34  func TestNewRepoServerClientset_SuccessfulConnection(t *testing.T) {
    35  	// Call the function with valid inputs
    36  	clientset := apiclient.NewRepoServerClientset("localhost:8080", 1, apiclient.TLSConfiguration{})
    37  
    38  	assert.NotNil(t, clientset)
    39  	assert.Implements(t, (*apiclient.Clientset)(nil), clientset)
    40  }
    41  
    42  func TestNewRepoServerClientset_SuccessfulConnectionWithTLS(t *testing.T) {
    43  	// Call the function with valid inputs
    44  	clientset := apiclient.NewRepoServerClientset("localhost:8080", 1, apiclient.TLSConfiguration{
    45  		DisableTLS:       false,
    46  		StrictValidation: true,
    47  		Certificates:     nil,
    48  	})
    49  
    50  	assert.NotNil(t, clientset)
    51  	assert.Implements(t, (*apiclient.Clientset)(nil), clientset)
    52  }
    53  
    54  func TestNewConnection_TLSWithStrictValidation(t *testing.T) {
    55  	tlsConfig := apiclient.TLSConfiguration{
    56  		DisableTLS:       false,
    57  		StrictValidation: true,
    58  		Certificates:     nil,
    59  	}
    60  
    61  	conn, err := apiclient.NewConnection("example.com:443", 10, &tlsConfig)
    62  
    63  	require.NoError(t, err)
    64  	assert.NotNil(t, conn)
    65  }
    66  
    67  func TestNewConnection_TLSWithStrictValidationAndCertificates(t *testing.T) {
    68  	tlsConfig := apiclient.TLSConfiguration{
    69  		DisableTLS:       false,
    70  		StrictValidation: true,
    71  		Certificates:     nil,
    72  	}
    73  
    74  	conn, err := apiclient.NewConnection("example.com:443", 10, &tlsConfig)
    75  
    76  	require.NoError(t, err)
    77  	assert.NotNil(t, conn)
    78  }
    79  
    80  func TestNewConnection_InsecureConnection(t *testing.T) {
    81  	// Create a TLS configuration with TLS disabled
    82  	tlsConfig := apiclient.TLSConfiguration{
    83  		DisableTLS:       true,
    84  		StrictValidation: false,
    85  		Certificates:     nil,
    86  	}
    87  
    88  	conn, err := apiclient.NewConnection("example.com:80", 10, &tlsConfig)
    89  
    90  	require.NoError(t, err)
    91  	assert.NotNil(t, conn)
    92  }