Commit 318e4a90 authored by joliu's avatar joliu

fix utils tests bug

parent a9800d93
Pipeline #107 passed with stage
in 0 seconds
...@@ -4,7 +4,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -4,7 +4,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "cnf.utils") @ConfigurationProperties(prefix = "cnf.utils")
public class UtilsProperties { public class UtilsProperties {
private String passwd = "admin"; private String passwd = "Vudo3423";
public String getPasswd() { public String getPasswd() {
return passwd; return passwd;
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
top.ninwoo.utils.config.CNFUtilsAutoConfiguration
\ No newline at end of file
package top.ninwoo.utils; package top.ninwoo.utils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -10,6 +12,9 @@ import top.ninwoo.common.entity.DockerContainer; ...@@ -10,6 +12,9 @@ import top.ninwoo.common.entity.DockerContainer;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.util.DockerUtils; import top.ninwoo.utils.util.DockerUtils;
import java.util.ArrayList;
import java.util.List;
/** /**
* @Author joliu * @Author joliu
* @Description * @Description
...@@ -18,13 +23,23 @@ import top.ninwoo.utils.util.DockerUtils; ...@@ -18,13 +23,23 @@ import top.ninwoo.utils.util.DockerUtils;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class DockerUtilsTest { public class DockerUtilsTest {
private static String cid = null;
@Autowired @Autowired
DockerUtils dockerUtils; DockerUtils dockerUtils;
@Before
public void prepare() {
DockerContainer container = new DockerContainer();
container.setName("Router_4");
container.setImage("joliu/networktest");
container.setCommand("sh");
cid = dockerUtils.runDocker(container).getId();
}
@Test @Test
public void testGetDockerById() { public void testGetDockerById() {
DockerContainer dockerById = dockerUtils.getDockerById("123123"); DockerContainer dockerById = dockerUtils.getDockerById(cid);
Assert.isNull(dockerById); Assert.isTrue(dockerById != null);
} }
...@@ -32,6 +47,12 @@ public class DockerUtilsTest { ...@@ -32,6 +47,12 @@ public class DockerUtilsTest {
public void testExecInDocker() { public void testExecInDocker() {
final String s = final String s =
dockerUtils.execInDocker("Router_4", new String[]{"ifconfig"}); dockerUtils.execInDocker("Router_4", new String[]{"ifconfig"});
System.out.println(s); Assert.isTrue(!("".equals(s)));
}
@After
public void close() {
boolean result = dockerUtils.deleteDockerById(cid);
Assert.isTrue(result);
} }
} }
package top.ninwoo.utils;
/**
* @Author joliu
* @Description
* @Date Create in 下午10:50 2019/10/27
*/
public class EntityTests {
}
package top.ninwoo.utils;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.service.IptablesService;
/**
* @Author joliu
* @Description
* @Date Create in 下午3:15 2019/10/30
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class IptablesServiceTests {
@Autowired
IptablesService iptablesService;
}
...@@ -26,7 +26,7 @@ public class OsUtilsTests { ...@@ -26,7 +26,7 @@ public class OsUtilsTests {
System.out.println("CPU:" + osUtils.cpuUsage() + "%"); System.out.println("CPU:" + osUtils.cpuUsage() + "%");
System.out.println("MEM:" + osUtils.memoryUsage() + "%"); System.out.println("MEM:" + osUtils.memoryUsage() + "%");
int i = 0; int i = 0;
while(i < 10) { while(i++ < 10) {
System.out.println("NET:" + osUtils.networkUsage() + "%"); System.out.println("NET:" + osUtils.networkUsage() + "%");
} }
} }
......
package top.ninwoo.utils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
public class SpringMain {
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(CNFUtilsAutoConfiguration.class);
}
}
package top.ninwoo.utils;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.util.DockerUtils;
/**
* @Author joliu
* @Description 这个测试迁移到集群服务中
* @Date Create in 下午4:06 2019/10/30
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class TcUtilsTests {
@Autowired
DockerUtils dockerUtils;
@Before
public void init() {
// 创建两个容器
// 创建一个ovs网桥
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment