@@ -18,7 +18,6 @@ import (
18
18
"context"
19
19
"testing"
20
20
21
- "github.com/argoproj-labs/argocd-agent/internal/cache"
22
21
argoapp "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
23
22
"github.com/sirupsen/logrus"
24
23
"github.com/stretchr/testify/assert"
@@ -79,23 +78,23 @@ func TestRevertUserInitiatedDeletion(t *testing.T) {
79
78
},
80
79
}
81
80
mgr := & fakeManager [* argoapp.Application ]{}
82
- sc := cache . NewSourceCache ()
83
- ok := RevertUserInitiatedDeletion (context .Background (), app , sc . Application , mgr , newLogger ())
81
+ deletions := NewDeletionTracker ()
82
+ ok := RevertUserInitiatedDeletion (context .Background (), app , deletions , mgr , newLogger ())
84
83
requires .False (ok )
85
84
requires .Nil (mgr .created )
86
85
87
- // With annotation but cache miss -> no recreate
86
+ // With annotation but valid deletion -> no recreate
88
87
app .Annotations = map [string ]string {SourceUIDAnnotation : string (types .UID ("u1" ))}
89
88
mgr = & fakeManager [* argoapp.Application ]{}
90
- ok = RevertUserInitiatedDeletion (context .Background (), app , sc .Application , mgr , newLogger ())
89
+ deletions .MarkExpected (types .UID ("u1" ))
90
+ ok = RevertUserInitiatedDeletion (context .Background (), app , deletions , mgr , newLogger ())
91
91
requires .False (ok )
92
92
requires .Nil (mgr .created )
93
93
94
- // With annotation and cache hit -> recreate
94
+ // With annotation and invalid deletion -> recreate
95
95
app .Annotations = map [string ]string {SourceUIDAnnotation : string (types .UID ("u2" ))}
96
- sc .Application .Set (types .UID ("u2" ), argoapp.ApplicationSpec {})
97
96
mgr = & fakeManager [* argoapp.Application ]{}
98
- ok = RevertUserInitiatedDeletion (context .Background (), app , sc . Application , mgr , newLogger ())
97
+ ok = RevertUserInitiatedDeletion (context .Background (), app , deletions , mgr , newLogger ())
99
98
requires .True (ok )
100
99
requires .NotNil (mgr .created )
101
100
requires .Equal (types .UID ("u2" ), mgr .created .GetUID ())
@@ -112,22 +111,22 @@ func TestRevertUserInitiatedDeletion(t *testing.T) {
112
111
Namespace : "argocd" ,
113
112
},
114
113
}
115
- sc := cache . NewSourceCache ()
114
+ deletions := NewDeletionTracker ()
116
115
mgr := & fakeManager [* argoapp.AppProject ]{}
117
- ok := RevertUserInitiatedDeletion (context .Background (), proj , sc . AppProject , mgr , newLogger ())
116
+ ok := RevertUserInitiatedDeletion (context .Background (), proj , deletions , mgr , newLogger ())
118
117
requires .False (ok )
119
118
requires .Nil (mgr .created )
120
119
121
120
proj .Annotations = map [string ]string {SourceUIDAnnotation : string (types .UID ("p1" ))}
122
121
mgr = & fakeManager [* argoapp.AppProject ]{}
123
- ok = RevertUserInitiatedDeletion (context .Background (), proj , sc .AppProject , mgr , newLogger ())
122
+ deletions .MarkExpected (types .UID ("p1" ))
123
+ ok = RevertUserInitiatedDeletion (context .Background (), proj , deletions , mgr , newLogger ())
124
124
requires .False (ok )
125
125
requires .Nil (mgr .created )
126
126
127
127
proj .Annotations = map [string ]string {SourceUIDAnnotation : string (types .UID ("p2" ))}
128
- sc .AppProject .Set (types .UID ("p2" ), argoapp.AppProjectSpec {})
129
128
mgr = & fakeManager [* argoapp.AppProject ]{}
130
- ok = RevertUserInitiatedDeletion (context .Background (), proj , sc . AppProject , mgr , newLogger ())
129
+ ok = RevertUserInitiatedDeletion (context .Background (), proj , deletions , mgr , newLogger ())
131
130
requires .True (ok )
132
131
requires .NotNil (mgr .created )
133
132
requires .Equal (types .UID ("p2" ), mgr .created .GetUID ())
@@ -144,22 +143,22 @@ func TestRevertUserInitiatedDeletion(t *testing.T) {
144
143
Namespace : "argocd" ,
145
144
},
146
145
}
147
- sc := cache . NewSourceCache ()
146
+ deletions := NewDeletionTracker ()
148
147
mgr := & fakeManager [* corev1.Secret ]{}
149
- ok := RevertUserInitiatedDeletion (context .Background (), repo , sc . Repository , mgr , newLogger ())
148
+ ok := RevertUserInitiatedDeletion (context .Background (), repo , deletions , mgr , newLogger ())
150
149
requires .False (ok )
151
150
requires .Nil (mgr .created )
152
151
153
152
repo .Annotations = map [string ]string {SourceUIDAnnotation : string (types .UID ("r1" ))}
154
153
mgr = & fakeManager [* corev1.Secret ]{}
155
- ok = RevertUserInitiatedDeletion (context .Background (), repo , sc .Repository , mgr , newLogger ())
154
+ deletions .MarkExpected (types .UID ("r1" ))
155
+ ok = RevertUserInitiatedDeletion (context .Background (), repo , deletions , mgr , newLogger ())
156
156
requires .False (ok )
157
157
requires .Nil (mgr .created )
158
158
159
159
repo .Annotations = map [string ]string {SourceUIDAnnotation : string (types .UID ("r2" ))}
160
- sc .Repository .Set (types .UID ("r2" ), map [string ][]byte {"k" : {}})
161
160
mgr = & fakeManager [* corev1.Secret ]{}
162
- ok = RevertUserInitiatedDeletion (context .Background (), repo , sc . Repository , mgr , newLogger ())
161
+ ok = RevertUserInitiatedDeletion (context .Background (), repo , deletions , mgr , newLogger ())
163
162
requires .True (ok )
164
163
requires .NotNil (mgr .created )
165
164
requires .Equal (types .UID ("r2" ), mgr .created .GetUID ())
0 commit comments