From 0a3954438e64ec27cf6771075b378669af90e95b Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Thu, 24 Oct 2024 14:50:59 +0300 Subject: [PATCH] fix: improve message --- acr_controller/service/acr_service.go | 3 +- acr_controller/service/acr_service_test.go | 33 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/acr_controller/service/acr_service.go b/acr_controller/service/acr_service.go index e35dfc5766a65..12f73d77bd798 100644 --- a/acr_controller/service/acr_service.go +++ b/acr_controller/service/acr_service.go @@ -3,7 +3,6 @@ package service import ( "context" "encoding/json" - "errors" "sync" log "github.com/sirupsen/logrus" @@ -69,7 +68,7 @@ func (c *acrService) ChangeRevision(ctx context.Context, a *application.Applicat if getChangeRevision(app) != "" { log.Infof("Change revision already calculated for application %s", app.Name) - return errors.New("change revision already calculated") + return nil } revision, err := c.calculateRevision(ctx, app) diff --git a/acr_controller/service/acr_service_test.go b/acr_controller/service/acr_service_test.go index a2554d793693d..01ab9933543c0 100644 --- a/acr_controller/service/acr_service_test.go +++ b/acr_controller/service/acr_service_test.go @@ -2,6 +2,8 @@ package service import ( "context" + "io" + "os" "testing" "github.com/argoproj/argo-cd/v2/acr_controller/application/mocks" @@ -202,6 +204,30 @@ status: status: Synced ` + +// Rather dirty hack to capture stdout from PrintResource() and PrintResourceList() +func captureOutput(f func() error) (string, error) { + stdout := os.Stdout + r, w, err := os.Pipe() + if err != nil { + return "", err + } + os.Stdout = w + err = f() + w.Close() + if err != nil { + os.Stdout = stdout + return "", err + } + str, err := io.ReadAll(r) + os.Stdout = stdout + if err != nil { + return "", err + } + return string(str), err +} + + func newTestACRService(client *mocks.ApplicationClient) *acrService { fakeAppsClientset := apps.NewSimpleClientset(createTestApp(syncedAppWithHistory)) return &acrService{ @@ -296,7 +322,10 @@ func Test_ChangeRevision(r *testing.T) { assert.Equal(t, "new-revision", app.Status.OperationState.Operation.Sync.ChangeRevision) - err = acrService.ChangeRevision(context.TODO(), app) - require.Error(t, err, "change revision already calculated") + str, err := captureOutput(func() error { + return acrService.ChangeRevision(context.TODO(), app) + }) + require.NoError(t, err) + require.Equal(t, str, "Change revision already calculated for application guestbook") }) }