diff --git a/pkg/app_watcher/app_watcher_test.go b/pkg/app_watcher/app_watcher_test.go index 4af7425c..9f9c7380 100644 --- a/pkg/app_watcher/app_watcher_test.go +++ b/pkg/app_watcher/app_watcher_test.go @@ -86,9 +86,10 @@ func TestApplicationUpdated(t *testing.T) { assert.Equal(t, len(ctrl.vcsToArgoMap.GetMap()), 2) oldAppDirectory := ctrl.vcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo.git") + assert.Equal(t, oldAppDirectory.AppsCount(), 1) + newAppDirectory := ctrl.vcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo-3.git") - assert.Equal(t, oldAppDirectory.Count(), 1) - assert.Equal(t, newAppDirectory.Count(), 0) + assert.Equal(t, newAppDirectory.AppsCount(), 0) // _, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications("default").Update(ctx, &v1alpha1.Application{ ObjectMeta: metav1.ObjectMeta{Name: "test-app-1", Namespace: "default"}, @@ -102,8 +103,8 @@ func TestApplicationUpdated(t *testing.T) { time.Sleep(time.Second * 1) oldAppDirectory = ctrl.vcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo.git") newAppDirectory = ctrl.vcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo-3.git") - assert.Equal(t, oldAppDirectory.Count(), 0) - assert.Equal(t, newAppDirectory.Count(), 1) + assert.Equal(t, oldAppDirectory.AppsCount(), 0) + assert.Equal(t, newAppDirectory.AppsCount(), 1) } func TestApplicationDeleted(t *testing.T) { @@ -119,7 +120,7 @@ func TestApplicationDeleted(t *testing.T) { assert.Equal(t, len(ctrl.vcsToArgoMap.GetMap()), 2) appDirectory := ctrl.vcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo.git") - assert.Equal(t, appDirectory.Count(), 1) + assert.Equal(t, appDirectory.AppsCount(), 1) // err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications("default").Delete(ctx, "test-app-1", metav1.DeleteOptions{}) if err != nil { @@ -128,7 +129,7 @@ func TestApplicationDeleted(t *testing.T) { time.Sleep(time.Second * 1) appDirectory = ctrl.vcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo.git") - assert.Equal(t, appDirectory.Count(), 0) + assert.Equal(t, appDirectory.AppsCount(), 0) } // TestIsGitRepo will test various URLs against the isGitRepo function. diff --git a/pkg/appdir/vcstoargomap_test.go b/pkg/appdir/vcstoargomap_test.go index 95a5d088..350f6504 100644 --- a/pkg/appdir/vcstoargomap_test.go +++ b/pkg/appdir/vcstoargomap_test.go @@ -26,7 +26,7 @@ func TestAddApp(t *testing.T) { v2a.AddApp(app1) appDir := v2a.GetAppsInRepo("https://github.com/argoproj/argo-cd.git") - assert.Equal(t, appDir.Count(), 1) + assert.Equal(t, appDir.AppsCount(), 1) assert.Equal(t, len(appDir.appDirs["test-app-1"]), 1) // Assertions to verify the behavior here. @@ -41,7 +41,7 @@ func TestAddApp(t *testing.T) { } v2a.AddApp(app2) - assert.Equal(t, appDir.Count(), 2) + assert.Equal(t, appDir.AppsCount(), 2) assert.Equal(t, len(appDir.appDirs["test-app-2"]), 1) } @@ -73,12 +73,12 @@ func TestDeleteApp(t *testing.T) { v2a.AddApp(app2) appDir := v2a.GetAppsInRepo("https://github.com/argoproj/argo-cd.git") - assert.Equal(t, appDir.Count(), 2) + assert.Equal(t, appDir.AppsCount(), 2) assert.Equal(t, len(appDir.appDirs["test-app-1"]), 1) assert.Equal(t, len(appDir.appDirs["test-app-2"]), 1) v2a.DeleteApp(app2) - assert.Equal(t, appDir.Count(), 1) + assert.Equal(t, appDir.AppsCount(), 1) assert.Equal(t, len(appDir.appDirs["test-app-2"]), 0) } @@ -86,14 +86,13 @@ func TestVcsToArgoMap_AddAppSet(t *testing.T) { type args struct { app *v1alpha1.ApplicationSet } - tests := []struct { + tests := map[string]struct { name string fields VcsToArgoMap args args expectedCount int }{ - { - name: "normal process, expect to get the appset stored in the map", + "normal process, expect to get the appset stored in the map": { fields: NewVcsToArgoMap("dummyuser"), args: args{ app: &v1alpha1.ApplicationSet{ @@ -112,8 +111,7 @@ func TestVcsToArgoMap_AddAppSet(t *testing.T) { }, expectedCount: 1, }, - { - name: "invalid appset", + "invalid appset": { fields: NewVcsToArgoMap("vcs-username"), args: args{ app: &v1alpha1.ApplicationSet{