@@ -25,12 +25,12 @@ func TestCheckAutomationStatusIsGoal(t *testing.T) {
2525 Processes : []ProcessStatus {
2626 {
2727 Name : "a" ,
28- Plan : []string {"FCV" },
28+ Plan : []string {},
2929 LastGoalVersionAchieved : 1 ,
3030 },
3131 {
3232 Name : "b" ,
33- Plan : []string {"FCV" },
33+ Plan : []string {},
3434 LastGoalVersionAchieved : 1 ,
3535 },
3636 },
@@ -48,12 +48,12 @@ func TestCheckAutomationStatusIsGoal(t *testing.T) {
4848 Processes : []ProcessStatus {
4949 {
5050 Name : "a" ,
51- Plan : []string {"FCV" },
51+ Plan : []string {},
5252 LastGoalVersionAchieved : 0 ,
5353 },
5454 {
5555 Name : "b" ,
56- Plan : []string {"FCV" },
56+ Plan : []string {},
5757 LastGoalVersionAchieved : 1 ,
5858 },
5959 },
@@ -70,12 +70,12 @@ func TestCheckAutomationStatusIsGoal(t *testing.T) {
7070 Processes : []ProcessStatus {
7171 {
7272 Name : "a" ,
73- Plan : []string {"FCV" , " something-else" },
73+ Plan : []string {"something-else" },
7474 LastGoalVersionAchieved : 0 ,
7575 },
7676 {
7777 Name : "b" ,
78- Plan : []string {"FCV" , automationAgentKubeUpgradePlan },
78+ Plan : []string {automationAgentKubeUpgradePlan },
7979 LastGoalVersionAchieved : 1 ,
8080 },
8181 },
@@ -93,12 +93,12 @@ func TestCheckAutomationStatusIsGoal(t *testing.T) {
9393 Processes : []ProcessStatus {
9494 {
9595 Name : "a" ,
96- Plan : []string {"X" , "Y" },
96+ Plan : []string {},
9797 LastGoalVersionAchieved : 1 ,
9898 },
9999 {
100100 Name : "b" ,
101- Plan : []string {"Y" , "Z" },
101+ Plan : []string {},
102102 LastGoalVersionAchieved : 1 ,
103103 },
104104 },
@@ -119,3 +119,151 @@ func TestCheckAutomationStatusIsGoal(t *testing.T) {
119119 })
120120 }
121121}
122+
123+ func TestCheckAutomationStatusIsGoal_AuthenticationTransitions (t * testing.T ) {
124+ logger := zap .NewNop ().Sugar ()
125+
126+ tests := []struct {
127+ name string
128+ automationStatus * AutomationStatus
129+ relevantProcesses []string
130+ expectedReady bool
131+ expectedMessage string
132+ }{
133+ {
134+ name : "should wait for UpdateAuth move to complete" ,
135+ automationStatus : & AutomationStatus {
136+ GoalVersion : 5 ,
137+ Processes : []ProcessStatus {
138+ {
139+ Name : "rs0_0" ,
140+ LastGoalVersionAchieved : 5 ,
141+ Plan : []string {"UpdateAuth" },
142+ },
143+ },
144+ },
145+ relevantProcesses : []string {"rs0_0" },
146+ expectedReady : false ,
147+ expectedMessage : "authentication transitions in progress for 1 processes" ,
148+ },
149+ {
150+ name : "should wait for InitiateReplSet move to complete" ,
151+ automationStatus : & AutomationStatus {
152+ GoalVersion : 3 ,
153+ Processes : []ProcessStatus {
154+ {
155+ Name : "rs0_0" ,
156+ LastGoalVersionAchieved : 3 ,
157+ Plan : []string {"InitiateReplSet" },
158+ },
159+ },
160+ },
161+ relevantProcesses : []string {"rs0_0" },
162+ expectedReady : false ,
163+ expectedMessage : "authentication transitions in progress for 1 processes" ,
164+ },
165+ {
166+ name : "should be ready when authentication transitions are complete" ,
167+ automationStatus : & AutomationStatus {
168+ GoalVersion : 5 ,
169+ Processes : []ProcessStatus {
170+ {
171+ Name : "rs0_0" ,
172+ LastGoalVersionAchieved : 5 ,
173+ Plan : []string {}, // Empty plan means all moves completed
174+ },
175+ },
176+ },
177+ relevantProcesses : []string {"rs0_0" },
178+ expectedReady : true ,
179+ expectedMessage : "processes that reached goal state: [rs0_0]" ,
180+ },
181+ {
182+ name : "should wait for multiple processes with auth transitions" ,
183+ automationStatus : & AutomationStatus {
184+ GoalVersion : 7 ,
185+ Processes : []ProcessStatus {
186+ {
187+ Name : "rs0_0" ,
188+ LastGoalVersionAchieved : 7 ,
189+ Plan : []string {}, // This process completed
190+ },
191+ {
192+ Name : "rs0_1" ,
193+ LastGoalVersionAchieved : 7 ,
194+ Plan : []string {"RestartMongod" }, // Auth-related move in progress
195+ },
196+ },
197+ },
198+ relevantProcesses : []string {"rs0_0" , "rs0_1" },
199+ expectedReady : false ,
200+ expectedMessage : "authentication transitions in progress for 1 processes" ,
201+ },
202+ {
203+ name : "should ignore non-authentication moves in progress" ,
204+ automationStatus : & AutomationStatus {
205+ GoalVersion : 4 ,
206+ Processes : []ProcessStatus {
207+ {
208+ Name : "rs0_0" ,
209+ LastGoalVersionAchieved : 4 ,
210+ Plan : []string {"SomeOtherMove" }, // Non-auth move
211+ },
212+ },
213+ },
214+ relevantProcesses : []string {"rs0_0" },
215+ expectedReady : true ,
216+ expectedMessage : "processes that reached goal state: [rs0_0]" ,
217+ },
218+ }
219+
220+ for _ , tt := range tests {
221+ t .Run (tt .name , func (t * testing.T ) {
222+ ready , message := checkAutomationStatusIsGoal (
223+ tt .automationStatus ,
224+ tt .relevantProcesses ,
225+ logger ,
226+ )
227+
228+ assert .Equal (t , tt .expectedReady , ready , "Ready state should match expected" )
229+ assert .Contains (t , message , tt .expectedMessage , "Message should contain expected text" )
230+
231+ if tt .expectedReady {
232+ t .Logf ("✅ Process correctly marked as ready: %s" , message )
233+ } else {
234+ t .Logf ("⏳ Process correctly waiting for auth transition: %s" , message )
235+ }
236+ })
237+ }
238+ }
239+
240+ func TestIsAuthenticationTransitionMove (t * testing.T ) {
241+ authMoves := []string {
242+ "RestartMongod" ,
243+ "UpdateAuth" ,
244+ "UpdateConfig" ,
245+ "WaitForHealthy" ,
246+ "InitiateReplSet" ,
247+ }
248+
249+ nonAuthMoves := []string {
250+ "SomeOtherMove" ,
251+ "CreateIndex" ,
252+ "DropCollection" ,
253+ "BackupDatabase" ,
254+ }
255+
256+ for _ , move := range authMoves {
257+ t .Run ("auth_move_" + move , func (t * testing.T ) {
258+ assert .True (t , isAuthenticationTransitionMove (move ),
259+ "Move %s should be recognized as authentication transition" , move )
260+ })
261+ }
262+
263+ for _ , move := range nonAuthMoves {
264+ t .Run ("non_auth_move_" + move , func (t * testing.T ) {
265+ assert .False (t , isAuthenticationTransitionMove (move ),
266+ "Move %s should not be recognized as authentication transition" , move )
267+ })
268+ }
269+ }
0 commit comments