Skip to content

Commit

Permalink
create basic status updater test
Browse files Browse the repository at this point in the history
  • Loading branch information
bozerkins committed Jul 21, 2023
1 parent 36e2159 commit 2a96221
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/argo-watcher/argo_status_updater_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"
"testing"

"github.com/golang/mock/gomock"
"github.com/shini4i/argo-watcher/cmd/argo-watcher/mock"
"github.com/shini4i/argo-watcher/internal/models"
)

func TestArgoStatusUpdaterCheck(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

t.Run("Status Updater - ArgoCD cannot fetch app information", func(t *testing.T) {
// mocks
apiMock := mock.NewMockArgoApiInterface(ctrl)
metricsMock := mock.NewMockMetricsInterface(ctrl)
stateMock := mock.NewMockState(ctrl)

task := models.Task{
Id: "test-id",
App: "test-app",
}
// mock calls
apiMock.EXPECT().GetApplication(task.App).Return(nil, fmt.Errorf("Unexpected failure"))
metricsMock.EXPECT().AddFailedDeployment(task.App)
stateMock.EXPECT().SetTaskStatus(task.Id, models.StatusFailedMessage, "ArgoCD API Error: Unexpected failure")

// argo manager
argo := &Argo{}
argo.Init(stateMock, apiMock, metricsMock)

// argo updater
updater := &ArgoStatusUpdater{}
updater.Init(*argo, 1, "test-registry")

// run the rollout
updater.WaitForRollout(task)
})
}

0 comments on commit 2a96221

Please sign in to comment.