Skip to content

Commit

Permalink
test: added tests for consuming GitHub app credentials from a secret
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Lactin <[email protected]>
  • Loading branch information
dlactin committed Dec 7, 2023
1 parent ad6d8a1 commit 4b6edba
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ func Test_GetWriteBackConfig(t *testing.T) {
}

func Test_GetGitCreds(t *testing.T) {
t.Run("HTTP creds from a secret", func(t *testing.T) {
t.Run("HTTP user creds from a secret", func(t *testing.T) {
argoClient := argomock.ArgoCD{}
argoClient.On("UpdateSpec", mock.Anything, mock.Anything).Return(nil, nil)
secret := fixture.NewSecret("argocd-image-updater", "git-creds", map[string][]byte{
Expand Down Expand Up @@ -2090,11 +2090,52 @@ func Test_GetGitCreds(t *testing.T) {
creds, err := wbc.GetCreds(&app)
require.NoError(t, err)
require.NotNil(t, creds)
// Must have HTTPS creds
// Must have HTTPS user creds
_, ok := creds.(git.HTTPSCreds)
require.True(t, ok)
})

t.Run("HTTP GitHub App creds from a secret", func(t *testing.T) {
argoClient := argomock.ArgoCD{}
argoClient.On("UpdateSpec", mock.Anything, mock.Anything).Return(nil, nil)
secret := fixture.NewSecret("argocd-image-updater", "git-creds", map[string][]byte{
"githubAppID": []byte("12345678"),
"githubAppInstallationID": []byte("87654321"),
"githubAppPrivateKey": []byte("foo"),
})
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeClientsetWithResources(secret),
}
app := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "testapp",
Annotations: map[string]string{
"argocd-image-updater.argoproj.io/image-list": "nginx",
"argocd-image-updater.argoproj.io/write-back-method": "git:secret:argocd-image-updater/git-creds",
"argocd-image-updater.argoproj.io/git-credentials": "argocd-image-updater/git-creds",
},
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
RepoURL: "https://example.com/example",
TargetRevision: "main",
},
},
Status: v1alpha1.ApplicationStatus{
SourceType: v1alpha1.ApplicationSourceTypeKustomize,
},
}
wbc, err := getWriteBackConfig(&app, &kubeClient, &argoClient)
require.NoError(t, err)

creds, err := wbc.GetCreds(&app)
require.NoError(t, err)
require.NotNil(t, creds)
// Must have HTTPS GitHub App creds
_, ok := creds.(git.GitHubAppCreds)
require.True(t, ok)
})

t.Run("SSH creds from a secret", func(t *testing.T) {
argoClient := argomock.ArgoCD{}
argoClient.On("UpdateSpec", mock.Anything, mock.Anything).Return(nil, nil)
Expand Down

0 comments on commit 4b6edba

Please sign in to comment.