Skip to content

Commit

Permalink
add a unit test to verify the nil return value
Browse files Browse the repository at this point in the history
  • Loading branch information
jared-logan-patrick-ct committed Oct 15, 2024
1 parent 9874680 commit 7188f6b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
38 changes: 38 additions & 0 deletions internal/pkg/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package argocd
import (
"bytes"
"context"
"log"
"os"
"strings"
"testing"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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")
}
}
16 changes: 16 additions & 0 deletions internal/pkg/testutils/testutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testutils

import (
"io"
"os"

log "github.com/sirupsen/logrus"
)

// Quiet suppresses logs when running go test.
func Quiet() func() {
log.SetOutput(io.Discard)
return func() {
log.SetOutput(os.Stdout)
}
}

0 comments on commit 7188f6b

Please sign in to comment.