|
25 | 25 | import org.junit.runner.RunWith; |
26 | 26 | import org.mockito.InjectMocks; |
27 | 27 | import org.mockito.MockedConstruction; |
| 28 | +import org.mockito.MockedStatic; |
28 | 29 | import org.mockito.Mockito; |
29 | 30 | import org.mockito.Spy; |
30 | 31 | import org.mockito.junit.MockitoJUnitRunner; |
@@ -138,4 +139,27 @@ public void deleteBrRemovesTheBridgeCreatedForVlan() throws InternalErrorExcepti |
138 | 139 | Assert.assertEquals("breth1-100", createdBridge); |
139 | 140 | Mockito.verify(driver).deleteVnetBr(createdBridge, true); |
140 | 141 | } |
| 142 | + |
| 143 | + private Script deleteVxlanBridge(String vxlanPif) { |
| 144 | + Mockito.doReturn(vxlanPif).when(driver).getVxlanPif("5000"); |
| 145 | + try (MockedStatic<Script> script = Mockito.mockStatic(Script.class); |
| 146 | + MockedConstruction<Script> commands = Mockito.mockConstruction(Script.class)) { |
| 147 | + script.when(() -> Script.runSimpleBashScript("ls /sys/class/net/brvx-5000")).thenReturn("brif"); |
| 148 | + script.when(() -> Script.runSimpleBashScript("ls /sys/class/net/brvx-5000/brif | tr '\n' ' '")).thenReturn("vxlan5000 "); |
| 149 | + driver.deleteVnetBr("brvx-5000", true); |
| 150 | + return commands.constructed().get(0); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + @Test |
| 155 | + public void deleteVnetBrPassesThePifFromTheVxlanDevice() { |
| 156 | + Script command = deleteVxlanBridge("eth0"); |
| 157 | + Mockito.verify(command).add("-p", "eth0"); |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + public void deleteVnetBrKeepsTheParsedPifWhenTheVxlanDeviceHasNone() { |
| 162 | + Script command = deleteVxlanBridge(null); |
| 163 | + Mockito.verify(command).add("-p", "vx"); |
| 164 | + } |
141 | 165 | } |
0 commit comments