Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add debug to new version #336

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/affected_apps/argocd_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func logCounts(repoApps *appdir.AppDirectory) {
if repoApps == nil {
log.Debug().Msg("found no apps")
} else {
log.Debug().Msgf("found %d apps", repoApps.Count())
log.Debug().Int("apps", repoApps.AppsCount()).
Int("app files", repoApps.AppFilesCount()).
Int("app dirs", repoApps.AppDirsCount()).
Msg("mapped apps")
}
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/app_watcher/app_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion pkg/appdir/app_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ func NewAppDirectory() *AppDirectory {
}
}

func (d *AppDirectory) Count() int {
func (d *AppDirectory) AppsCount() int {
return len(d.appsMap)
}

func (d *AppDirectory) AppFilesCount() int {
return len(d.appFiles)
}

func (d *AppDirectory) AppDirsCount() int {
return len(d.appDirs)
}

func (d *AppDirectory) Union(other *AppDirectory) *AppDirectory {
var join AppDirectory
join.appsMap = mergeMaps(d.appsMap, other.appsMap, takeFirst[v1alpha1.Application])
Expand Down
16 changes: 7 additions & 9 deletions pkg/appdir/vcstoargomap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}

Expand Down Expand Up @@ -73,27 +73,26 @@ 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)
}

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{
Expand All @@ -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{
Expand Down
Loading