Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions application/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package application
import (
"context"

"io/ioutil"

"fmt"

"time"
Expand All @@ -13,6 +11,9 @@ import (
"github.com/argoproj/argo-cd/server/repository"
"github.com/argoproj/argo-cd/util/git"

"os"
"path"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -53,10 +54,7 @@ func (m *Manager) tryRefreshAppStatus(app *v1alpha1.Application) (*v1alpha1.Appl
return nil, err
}

appRepoPath, err := ioutil.TempDir("", app.Name)
if err != nil {
return nil, fmt.Errorf("unable to create temp repository directory for app '%s'", app.Name)
}
appRepoPath := path.Join(os.TempDir(), app.Name)

err = m.gitClient.CloneOrFetch(repo.Repo, repo.Username, repo.Password, appRepoPath)
if err != nil {
Expand Down
45 changes: 43 additions & 2 deletions application/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import (

"time"

"context"

"github.com/argoproj/argo-cd/application"
appMocks "github.com/argoproj/argo-cd/application/mocks"
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/server/repository"
repoMocks "github.com/argoproj/argo-cd/server/repository/mock"
gitMocks "github.com/argoproj/argo-cd/util/git/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -20,10 +27,12 @@ func TestManager(t *testing.T) {
TargetRevision: "master",
RepoURL: "http://my-git-repo.git",
}
gitClientMock := gitMocks.Client{}
appComparatorMock := appMocks.AppComparator{}
repoServiceMock := repoMocks.RepositoryServiceServer{}
manager := application.NewAppManager(&gitClientMock, &repoServiceMock, &appComparatorMock, refreshTimeout)

t.Run("NeedRefreshAppStatus", func(t *testing.T) {

manager := application.NewAppManager(nil, nil, nil, refreshTimeout)
t.Run("TestReturnsTrueIfAppWasNotCompared", func(t *testing.T) {
needRefresh := manager.NeedRefreshAppStatus(&v1alpha1.Application{
Spec: v1alpha1.ApplicationSpec{Source: appSource},
Expand Down Expand Up @@ -70,4 +79,36 @@ func TestManager(t *testing.T) {
assert.True(t, needRefresh)
})
})

t.Run("RefreshAppStatus", func(t *testing.T) {
repo := v1alpha1.Repository{
Repo: "https://testRepo/repo.git",
Username: "user",
Password: "test",
}
app := v1alpha1.Application{
Spec: v1alpha1.ApplicationSpec{Source: appSource},
Status: v1alpha1.ApplicationStatus{},
}

repoServiceMock.On("Get", context.Background(), &repository.RepoQuery{
Repo: appSource.RepoURL,
}).Return(&repo, nil)
var repoPath string
gitClientMock.On("CloneOrFetch", repo.Repo, repo.Username, repo.Password, mock.MatchedBy(func(receivedRepoPath string) bool {
repoPath = receivedRepoPath
return true
})).Return(nil)
gitClientMock.On("Checkout", mock.MatchedBy(func(receivedRepoPath string) bool {
return repoPath == receivedRepoPath
}), appSource.TargetRevision).Return(nil)

appComparatorMock.On("CompareAppState", mock.MatchedBy(func(receivedRepoPath string) bool {
return repoPath == receivedRepoPath
}), &app).Return(&v1alpha1.ComparisonResult{
Status: v1alpha1.ComparisonStatusEqual,
}, nil)
updatedAppStatus := manager.RefreshAppStatus(&app)
assert.Equal(t, updatedAppStatus.ComparisonResult.Status, v1alpha1.ComparisonStatusEqual)
})
}
33 changes: 33 additions & 0 deletions application/mocks/AppComparator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 150 additions & 0 deletions server/repository/mock/RepositoryServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions util/git/mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.