diff --git a/pkg/affected_apps/argocd_matcher.go b/pkg/affected_apps/argocd_matcher.go index f02af778..e2a1181b 100644 --- a/pkg/affected_apps/argocd_matcher.go +++ b/pkg/affected_apps/argocd_matcher.go @@ -16,13 +16,22 @@ type ArgocdMatcher struct { func NewArgocdMatcher(vcsToArgoMap pkg.VcsToArgoMap, repo *repo.Repo) *ArgocdMatcher { log.Debug().Msgf("looking for %s repos", repo.CloneURL) repoApps := vcsToArgoMap.GetAppsInRepo(repo.CloneURL) - log.Debug().Msgf("found %d apps", repoApps.Count()) + if repoApps == nil { + log.Debug().Msg("found no apps") + } else { + log.Debug().Msgf("found %d apps", repoApps.Count()) + } + return &ArgocdMatcher{ appsDirectory: repoApps, } } func (a *ArgocdMatcher) AffectedApps(ctx context.Context, changeList []string) (AffectedItems, error) { + if a.appsDirectory == nil { + return AffectedItems{}, nil + } + appsSlice := a.appsDirectory.FindAppsBasedOnChangeList(changeList) return AffectedItems{Applications: appsSlice}, nil } diff --git a/pkg/affected_apps/argocd_matcher_test.go b/pkg/affected_apps/argocd_matcher_test.go new file mode 100644 index 00000000..4ce77298 --- /dev/null +++ b/pkg/affected_apps/argocd_matcher_test.go @@ -0,0 +1,40 @@ +package affected_apps + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "github.com/zapier/kubechecks/pkg" + repo2 "github.com/zapier/kubechecks/pkg/repo" +) + +func TestCreateNewMatcherWithNilVcsMap(t *testing.T) { + // setup + var ( + vcsMap pkg.VcsToArgoMap + repo repo2.Repo + ) + + // run test + matcher := NewArgocdMatcher(vcsMap, &repo) + + // verify results + require.Nil(t, matcher.appsDirectory) +} + +func TestFindAffectedAppsWithNilAppsDirectory(t *testing.T) { + // setup + var ( + ctx = context.TODO() + changeList = []string{"/go.mod"} + ) + + matcher := ArgocdMatcher{} + items, err := matcher.AffectedApps(ctx, changeList) + + // verify results + require.NoError(t, err) + require.Len(t, items.Applications, 0) + require.Len(t, items.ApplicationSets, 0) +}