Skip to content

Commit

Permalink
fix: improve message
Browse files Browse the repository at this point in the history
  • Loading branch information
pasha-codefresh committed Oct 24, 2024
1 parent d07e389 commit 0a39544
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
3 changes: 1 addition & 2 deletions acr_controller/service/acr_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"context"
"encoding/json"
"errors"
"sync"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 31 additions & 2 deletions acr_controller/service/acr_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package service

import (
"context"
"io"
"os"
"testing"

"github.com/argoproj/argo-cd/v2/acr_controller/application/mocks"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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")

Check failure on line 329 in acr_controller/service/acr_service_test.go

View workflow job for this annotation

GitHub Actions / Lint Go code

expected-actual: need to reverse actual and expected values (testifylint)
})
}

0 comments on commit 0a39544

Please sign in to comment.