@@ -316,6 +316,48 @@ var _ = Describe("MysqlBackup controller", func() {
316316 Expect (c .Delete (context .TODO (), cluster .Unwrap ())).To (Succeed ())
317317 })
318318 })
319+
320+ When ("candidate node is setted to wrong node" , func () {
321+ BeforeEach (func () {
322+ backup .Spec .CandidateNode = cluster .GetPodHostname (3 )
323+ // create a cluster and a backup
324+ Expect (c .Create (context .TODO (), backup .Unwrap ())).To (Succeed ())
325+ Expect (c .Create (context .TODO (), cluster .Unwrap ())).To (Succeed ())
326+
327+ // first reconcile request for the backup
328+ Eventually (requests , timeout ).Should (Receive (Equal (expectedRequest )))
329+ testutil .DrainChan (requests )
330+ })
331+
332+ AfterEach (func () {
333+ Expect (c .Delete (context .TODO (), backup .Unwrap ())).To (Succeed ())
334+ c .Delete (context .TODO (), cluster .Unwrap ())
335+ })
336+
337+ It ("should skip creating job" , func () {
338+ job := & batch.Job {}
339+ Expect (c .Get (context .TODO (), jobKey , job )).NotTo (Succeed ())
340+ })
341+
342+ When ("candidate node update to master" , func () {
343+ BeforeEach (func () {
344+ backup .Spec .CandidateNode = cluster .GetPodHostname (0 )
345+ // update backup
346+ Expect (c .Update (context .TODO (), backup .Unwrap ())).To (Succeed ())
347+
348+ // first reconcile request for the backup
349+ Eventually (requests , timeout ).Should (Receive (Equal (expectedRequest )))
350+ testutil .DrainChan (requests )
351+ })
352+
353+ It ("should take backup from master" , func () {
354+ job := & batch.Job {}
355+ Expect (c .Get (context .TODO (), jobKey , job )).To (Succeed ())
356+ Expect (job .Spec .Template .Spec .Containers [0 ].Args ).To (ContainElement (Equal (cluster .GetPodHostname (0 ))))
357+ })
358+ })
359+
360+ })
319361})
320362
321363func refreshFn (c client.Client , backupKey types.NamespacedName ) func () * api.MysqlBackup {
0 commit comments