mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
Signed-off-by: Zadkiel AHARONIAN <hello@zadkiel.fr> Signed-off-by: Oliver Gondža <ogondza@gmail.com> Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Zadkiel AHARONIAN <hello@zadkiel.fr> Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
This commit is contained in:
@@ -2060,8 +2060,15 @@ func (s *Server) Sync(ctx context.Context, syncReq *application.ApplicationSyncR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var source *v1alpha1.ApplicationSource
|
||||
if !a.Spec.HasMultipleSources() {
|
||||
source = ptr.To(a.Spec.GetSource())
|
||||
}
|
||||
|
||||
op := v1alpha1.Operation{
|
||||
Sync: &v1alpha1.SyncOperation{
|
||||
Source: source,
|
||||
Revision: revision,
|
||||
Prune: syncReq.GetPrune(),
|
||||
DryRun: syncReq.GetDryRun(),
|
||||
|
||||
@@ -2053,6 +2053,7 @@ func TestSyncAndTerminate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, app)
|
||||
assert.NotNil(t, app.Operation)
|
||||
assert.Equal(t, testApp.Spec.GetSource(), *app.Operation.Sync.Source)
|
||||
|
||||
events, err := appServer.kubeclientset.CoreV1().Events(appServer.ns).List(t.Context(), metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
@@ -2131,8 +2132,63 @@ func TestSyncGit(t *testing.T) {
|
||||
assert.Equal(t, "Unknown user initiated sync locally", events.Items[1].Message)
|
||||
}
|
||||
|
||||
func TestSync_WithRefresh(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
appServer := newTestAppServer(t)
|
||||
testApp := newTestApp()
|
||||
testApp.Spec.SyncPolicy = &v1alpha1.SyncPolicy{
|
||||
Retry: &v1alpha1.RetryStrategy{
|
||||
Refresh: true,
|
||||
},
|
||||
}
|
||||
testApp.Spec.Source.RepoURL = "https://github.com/argoproj/argo-cd.git"
|
||||
createReq := application.ApplicationCreateRequest{
|
||||
Application: testApp,
|
||||
}
|
||||
app, err := appServer.Create(ctx, &createReq)
|
||||
require.NoError(t, err)
|
||||
app, err = appServer.Sync(ctx, &application.ApplicationSyncRequest{Name: &app.Name})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, app)
|
||||
assert.NotNil(t, app.Operation)
|
||||
assert.True(t, app.Operation.Retry.Refresh)
|
||||
}
|
||||
|
||||
func TestRollbackApp(t *testing.T) {
|
||||
testApp := newTestApp()
|
||||
testApp.Status.History = []v1alpha1.RevisionHistory{{
|
||||
ID: 1,
|
||||
Revision: "abc",
|
||||
Revisions: []string{"abc"},
|
||||
Source: *testApp.Spec.Source.DeepCopy(),
|
||||
Sources: []v1alpha1.ApplicationSource{*testApp.Spec.Source.DeepCopy()},
|
||||
}}
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
||||
updatedApp, err := appServer.Rollback(t.Context(), &application.ApplicationRollbackRequest{
|
||||
Name: &testApp.Name,
|
||||
Id: ptr.To(int64(1)),
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotNil(t, updatedApp.Operation)
|
||||
assert.NotNil(t, updatedApp.Operation.Sync)
|
||||
assert.NotNil(t, updatedApp.Operation.Sync.Source)
|
||||
assert.Equal(t, testApp.Status.History[0].Source, *updatedApp.Operation.Sync.Source)
|
||||
assert.Equal(t, testApp.Status.History[0].Sources, updatedApp.Operation.Sync.Sources)
|
||||
assert.Equal(t, testApp.Status.History[0].Revision, updatedApp.Operation.Sync.Revision)
|
||||
assert.Equal(t, testApp.Status.History[0].Revisions, updatedApp.Operation.Sync.Revisions)
|
||||
}
|
||||
|
||||
func TestRollbackApp_WithRefresh(t *testing.T) {
|
||||
testApp := newTestApp()
|
||||
testApp.Spec.SyncPolicy = &v1alpha1.SyncPolicy{
|
||||
Retry: &v1alpha1.RetryStrategy{
|
||||
Refresh: true,
|
||||
},
|
||||
}
|
||||
|
||||
testApp.Status.History = []v1alpha1.RevisionHistory{{
|
||||
ID: 1,
|
||||
Revision: "abc",
|
||||
@@ -2148,9 +2204,8 @@ func TestRollbackApp(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotNil(t, updatedApp.Operation)
|
||||
assert.NotNil(t, updatedApp.Operation.Sync)
|
||||
assert.NotNil(t, updatedApp.Operation.Sync.Source)
|
||||
assert.Equal(t, "abc", updatedApp.Operation.Sync.Revision)
|
||||
assert.NotNil(t, updatedApp.Operation.Retry)
|
||||
assert.False(t, updatedApp.Operation.Retry.Refresh, "refresh should never be set on rollback")
|
||||
}
|
||||
|
||||
func TestUpdateAppProject(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user