|
18 | 18 |
|
19 | 19 | import com.cloud.agent.api.Answer; |
20 | 20 | import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; |
| 21 | +import com.cloud.utils.Pair; |
21 | 22 | import com.cloud.storage.Storage; |
22 | 23 | import com.cloud.utils.script.Script; |
23 | 24 | import com.cloud.vm.VirtualMachine; |
@@ -83,6 +84,8 @@ public void testExecuteWithVmExistsNull() throws Exception { |
83 | 84 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
84 | 85 |
|
85 | 86 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 87 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 88 | + .thenReturn(new Pair<>(0, "success")); |
86 | 89 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
87 | 90 | .thenReturn(0); // Mount success |
88 | 91 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())) |
@@ -126,6 +129,8 @@ public void testExecuteWithVmExistsTrue() throws Exception { |
126 | 129 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
127 | 130 |
|
128 | 131 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 132 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 133 | + .thenReturn(new Pair<>(0, "success")); |
129 | 134 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
130 | 135 | .thenReturn(0); // Mount success |
131 | 136 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())) |
@@ -165,6 +170,8 @@ public void testExecuteWithVmExistsFalse() throws Exception { |
165 | 170 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
166 | 171 |
|
167 | 172 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 173 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 174 | + .thenReturn(new Pair<>(0, "success")); |
168 | 175 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
169 | 176 | .thenReturn(0); // Mount success |
170 | 177 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())) |
@@ -207,6 +214,8 @@ public void testExecuteWithCifsMountType() throws Exception { |
207 | 214 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
208 | 215 |
|
209 | 216 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 217 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 218 | + .thenReturn(new Pair<>(0, "success")); |
210 | 219 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
211 | 220 | .thenReturn(0); // Mount success |
212 | 221 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())) |
@@ -251,8 +260,8 @@ public void testExecuteWithMountFailure() throws Exception { |
251 | 260 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
252 | 261 |
|
253 | 262 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
254 | | - scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
255 | | - .thenReturn(1); // Mount failure |
| 263 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 264 | + .thenReturn(new Pair<>(1, "Failed")); |
256 | 265 |
|
257 | 266 | Answer result = wrapper.execute(command, libvirtComputingResource); |
258 | 267 |
|
@@ -290,6 +299,8 @@ public void testExecuteWithBackupFileNotFound() throws Exception { |
290 | 299 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
291 | 300 |
|
292 | 301 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 302 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 303 | + .thenReturn(new Pair<>(0, "success")); |
293 | 304 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
294 | 305 | .thenReturn(0); // Mount success |
295 | 306 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())) |
@@ -339,8 +350,8 @@ public void testExecuteWithCorruptBackupFile() throws Exception { |
339 | 350 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
340 | 351 |
|
341 | 352 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
342 | | - scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
343 | | - .thenReturn(0); // Mount success |
| 353 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 354 | + .thenReturn(new Pair<>(0, "success")); |
344 | 355 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())) |
345 | 356 | .thenAnswer(invocation -> { |
346 | 357 | String command = invocation.getArgument(0); |
@@ -390,6 +401,8 @@ public void testExecuteWithRsyncFailure() throws Exception { |
390 | 401 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
391 | 402 |
|
392 | 403 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 404 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 405 | + .thenReturn(new Pair<>(0, "success")); |
393 | 406 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
394 | 407 | .thenAnswer(invocation -> { |
395 | 408 | String command = invocation.getArgument(0); |
@@ -449,6 +462,8 @@ public void testExecuteWithAttachVolumeFailure() throws Exception { |
449 | 462 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
450 | 463 |
|
451 | 464 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 465 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 466 | + .thenReturn(new Pair<>(0, "success")); |
452 | 467 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
453 | 468 | .thenAnswer(invocation -> { |
454 | 469 | String command = invocation.getArgument(0); |
@@ -551,6 +566,10 @@ public void testExecuteWithMultipleVolumes() throws Exception { |
551 | 566 | filesMock.when(() -> Files.createTempDirectory(anyString())).thenReturn(tempPath); |
552 | 567 |
|
553 | 568 | try (MockedStatic<Script> scriptMock = mockStatic(Script.class)) { |
| 569 | + Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong())) |
| 570 | + .thenReturn(new Pair<>(0, "success")); |
| 571 | + scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
| 572 | + .thenReturn(0); // Mount success |
554 | 573 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())) |
555 | 574 | .thenReturn(0); // All commands success |
556 | 575 | scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString(), anyInt(), any(Boolean.class))) |
|
0 commit comments