Skip to content

Commit

Permalink
add unit test and linter fix
Browse files Browse the repository at this point in the history
Signed-off-by: Atif Ali <[email protected]>
  • Loading branch information
aali309 committed Feb 7, 2025
1 parent 2628a14 commit 3e5b8c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
22 changes: 21 additions & 1 deletion reposerver/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,27 @@ func TestCache_GetManifests(t *testing.T) {
assert.Equal(t, "my-source-type", value.ManifestResponse.SourceType)
assert.Equal(t, "my-revision1", value.ManifestResponse.Revision)
})
mockCache.AssertCacheCalledTimes(t, &mocks.CacheCallCounts{ExternalSets: 2, ExternalGets: 8})
t.Run("expect tag resolution for refs/tags", func(t *testing.T) {
// Set up test with a tag reference
tagRef := "refs/tags/v1.0.0"
res := &CachedManifestResponse{
ManifestResponse: &apiclient.ManifestResponse{
SourceType: "my-source-type",
Revision: tagRef,
},
}

err = cache.SetManifests(tagRef, &v1alpha1.ApplicationSource{}, q.RefSources, q, "my-namespace", "", "my-app-label-key", "my-app-label-value", res, nil, "")
require.NoError(t, err)

// Get manifests should attempt to resolve the tag
err = cache.GetManifests(tagRef, &v1alpha1.ApplicationSource{}, q.RefSources, q, "my-namespace", "", "my-app-label-key", "my-app-label-value", value, nil, "")
require.NoError(t, err)

// Should fall back to tag reference if resolution fails
assert.Equal(t, tagRef, value.ManifestResponse.Revision)
})
mockCache.AssertCacheCalledTimes(t, &mocks.CacheCallCounts{ExternalSets: 3, ExternalGets: 9})
}

func TestCache_GetAppDetails(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestAnnotatedTagInStatusSyncRevision(t *testing.T) {
assert.Len(t, app.Status.Sync.Revision, 40)
assert.NotContains(t, app.Status.Sync.Revision, "refs/tags/")
}).
And(func(app *Application) {
And(func(_ *Application) {
// Get deployment directly from k8s
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).
Get(context.Background(), "nginx-deployment", metav1.GetOptions{})
Expand Down Expand Up @@ -183,21 +183,21 @@ func TestAutomatedSelfHealingAgainstAnnotatedTag(t *testing.T) {
AddAnnotatedTag("my-annotated-tag", "Updated commit").
Refresh(RefreshTypeHard).
Then().
Expect(SyncStatusIs(SyncStatusCodeSynced)). // Argo CD should sync to the new commit
Expect(SyncStatusIs(SyncStatusCodeSynced)).
When().
// Make a manual change to the live resource
And(func() {
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).
Get(context.Background(), "nginx-deployment", metav1.GetOptions{})
require.NoError(t, err)
deployment.Spec.Replicas = pointer.Int32(2)
deployment.Spec.Replicas = ptr.To(int32(2))
_, err = fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).
Update(context.Background(), deployment, metav1.UpdateOptions{})
require.NoError(t, err)
}).Then().
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
// Verify manual change is NOT reverted (selfHeal=false)
And(func(app *Application) {
And(func(_ *Application) {
assert.Eventually(t, func() bool {
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).
Get(context.Background(), "nginx-deployment", metav1.GetOptions{})
Expand Down

0 comments on commit 3e5b8c9

Please sign in to comment.