From 7f974f18e026797e6355f0d81f5f9ebd24e61169 Mon Sep 17 00:00:00 2001 From: Jared Patrick Date: Tue, 15 Oct 2024 16:09:02 -0400 Subject: [PATCH] add a unit test to verify the nil return value --- internal/pkg/argocd/argocd_test.go | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/pkg/argocd/argocd_test.go b/internal/pkg/argocd/argocd_test.go index dc78cecc..3d461a2e 100644 --- a/internal/pkg/argocd/argocd_test.go +++ b/internal/pkg/argocd/argocd_test.go @@ -3,6 +3,7 @@ package argocd import ( "bytes" "context" + "log" "os" "strings" "testing" @@ -11,6 +12,7 @@ import ( argoappv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" "github.com/golang/mock/gomock" "github.com/wayfair-incubator/telefonistka/internal/pkg/mocks" + "github.com/wayfair-incubator/telefonistka/internal/pkg/testutils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -273,3 +275,39 @@ func TestFindArgocdAppByPathAnnotationRelative2(t *testing.T) { t.Errorf("App name is not right-app") } } + +func TestFindArgocdAppByPathAnnotationNotFound(t *testing.T) { + t.Parallel() + defer testutils.Quiet()() + ctx := context.Background() + ctrl := gomock.NewController(t) + defer ctrl.Finish() + mockApplicationClient := mocks.NewMockApplicationServiceClient(ctrl) + expectedResponse := &argoappv1.ApplicationList{ + Items: []argoappv1.Application{ + { + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + "argocd.argoproj.io/manifest-generate-paths": "wrong-path", + }, + Name: "right-app", + }, + Spec: argoappv1.ApplicationSpec{ + Source: &argoappv1.ApplicationSource{ + RepoURL: "", + Path: "right/", + }, + }, + }, + }, + } + + mockApplicationClient.EXPECT().List(gomock.Any(), gomock.Any()).Return(expectedResponse, nil) + app, err := findArgocdAppByManifestPathAnnotation(ctx, "right/path", "some-repo", mockApplicationClient) + if err != nil { + t.Errorf("Error: %v", err) + } + if app != nil { + log.Fatal("expected the application to be nil") + } +}