github.com/argoproj/argo-cd/v3@v3.2.1/commitserver/commit/credentialtypehelper_test.go (about)

     1  package commit
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
     9  )
    10  
    11  func TestRepository_GetCredentialType(t *testing.T) {
    12  	tests := []struct {
    13  		name string
    14  		repo *v1alpha1.Repository
    15  		want string
    16  	}{
    17  		{
    18  			name: "Empty Repository",
    19  			repo: nil,
    20  			want: "",
    21  		},
    22  		{
    23  			name: "HTTPS Repository",
    24  			repo: &v1alpha1.Repository{
    25  				Repo:     "foo",
    26  				Password: "some-password",
    27  			},
    28  			want: "https",
    29  		},
    30  		{
    31  			name: "SSH Repository",
    32  			repo: &v1alpha1.Repository{
    33  				Repo:          "foo",
    34  				SSHPrivateKey: "some-key",
    35  			},
    36  			want: "ssh",
    37  		},
    38  		{
    39  			name: "GitHub App Repository",
    40  			repo: &v1alpha1.Repository{
    41  				Repo:                    "foo",
    42  				GithubAppPrivateKey:     "some-key",
    43  				GithubAppId:             1,
    44  				GithubAppInstallationId: 1,
    45  			},
    46  			want: "github-app",
    47  		},
    48  		{
    49  			name: "Google Cloud Repository",
    50  			repo: &v1alpha1.Repository{
    51  				Repo:                 "foo",
    52  				GCPServiceAccountKey: "some-key",
    53  			},
    54  			want: "cloud-source-repositories",
    55  		},
    56  	}
    57  	for _, tt := range tests {
    58  		t.Run(tt.name, func(t *testing.T) {
    59  			assert.Equal(t, tt.want, getCredentialType(tt.repo), "Repository.GetCredentialType()")
    60  		})
    61  	}
    62  }