Explorar o código

update test case

reghao %!s(int64=2) %!d(string=hai) anos
pai
achega
1c96726f90

+ 0 - 175
manager/src/test/java/BuildTest.java

@@ -1,175 +0,0 @@
-import cn.reghao.devops.common.build.model.constant.RepoAuthType;
-import cn.reghao.devops.common.build.tool.repo.GitImpl;
-import cn.reghao.devops.common.docker.DockerImpl;
-import cn.reghao.devops.common.ws.WsClient;
-import cn.reghao.devops.manager.app.model.po.config.build.RepoAuthConfig;
-import cn.reghao.devops.manager.app.model.vo.ChartData;
-import cn.reghao.devops.model.NginxLog;
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
-import cn.reghao.jutil.jdk.text.TextFile;
-import com.github.dockerjava.api.command.InspectContainerResponse;
-import com.github.dockerjava.api.model.Container;
-import org.junit.Test;
-
-import java.text.ParseException;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.*;
-import java.util.regex.Pattern;
-
-/**
- * @author reghao
- * @date 2022-05-07 09:32:40
- */
-public class BuildTest {
-    @Test
-    public void gitTest() throws Exception {
-        String repo = "https://codeup.aliyun.com/5f1f8daf6207a1a8b17f6742/FrontEnd/iquizoo.admin.git";
-        RepoAuthConfig repoAuthConfig = new RepoAuthConfig();
-        repoAuthConfig.setAuthType(RepoAuthType.http.getName());
-        repoAuthConfig.setUsername("azygjs");
-        repoAuthConfig.setPassword("6wNSPZH4");
-
-        GitImpl git = new GitImpl(repoAuthConfig.getRepoAuth());
-        List<String> list = git.remoteBranches(repo);
-        System.out.println();
-    }
-
-    @Test
-    public void dockerListTest() {
-        Pattern pattern = Pattern.compile("^\\S*$");
-        String str = "dfa   safd";
-        String str1 = "dfasafd";
-        boolean matched = pattern.matcher(str).matches();
-        System.out.println();
-    }
-
-    @Test
-    public void dockerBuildTest() throws Exception {
-        DockerImpl docker = new DockerImpl();
-        String repoTag = "file:12345678";
-        String compileHome = "/home/reghao/code/aha/tnb/file/file-service";
-        docker.build(repoTag, compileHome);
-    }
-
-    @Test
-    public void dockerTest() {
-        DockerImpl docker = new DockerImpl();
-        InspectContainerResponse containerInfo = docker.ps("dnkt-admin");
-
-        List<Container> list = docker.ps(true);
-        list.forEach(container -> {
-            container.getId();
-        });
-    }
-
-    @Test
-    public void wsTest() throws InterruptedException {
-        String url = "wss://devops.reghao.cn/ws/log/pull?token=12345678";
-        url = "wss://devops.reghao.cn/ws/message?token=12345678";
-
-        WsClient wsClient = new WsClient(url);
-        wsClient.connect();
-
-        Thread.sleep(3600_000);
-    }
-
-    @Test
-    public void test() throws ParseException {
-        Map<String, Integer> map = new TreeMap<>();
-
-        TextFile textFile = new TextFile();
-        String filePath = "/home/reghao/Downloads/api.iquizoo.com.access.log";
-        List<String> list = textFile.read(filePath);
-        for (String line : list) {
-            String address = line.split(" - ")[0];
-            String date = line.split("- \\[")[1].split("]")[0];
-            LocalDateTime localDateTime = DateTimeConverter.localDateTime1(date);
-            String dateTimeStr = DateTimeConverter.format(localDateTime);
-
-            String key = dateTimeStr;
-            Integer count = map.get(key);
-            if (count == null) {
-                map.put(key, 1);
-            } else {
-                int count1 = map.get(key) + 1;
-                map.put(key, count1);
-            }
-        }
-
-        List<Map.Entry<String, Integer>> list1 = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
-        //然后通过比较器来实现排序
-        Collections.sort(list1, new Comparator<Map.Entry<String, Integer>>() {
-            //升序排序
-            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
-                return o2.getKey().compareTo(o1.getKey());
-            }
-        });
-
-        for(Map.Entry<String, Integer> mapping : list1) {
-            String key = mapping.getKey();
-            int value = mapping.getValue();
-
-            ChartData chartData = new ChartData();
-            //chartData.setTotal(value);
-            Object obj1 = key;
-            Object obj2 = Integer.valueOf(-1);
-            List<Object> list2 = new ArrayList<>();
-            list2.add(obj1);
-            list2.add(obj2);
-            //chartData.setTime(List.of(list2));
-            System.out.println(mapping.getKey() + " -> " +mapping.getValue());
-        }
-    }
-
-    @Test
-    public void logTest() throws ParseException {
-        /*File file = new File("");
-        JsonConverter.jsonFileToObject(file, NginxLog.class);*/
-
-        TextFile textFile = new TextFile();
-        String filePath = "/home/reghao/Downloads/api.iquizoo.com.access1.log";
-        filePath = "/home/reghao/Downloads/api.iquizoo.com.access.log-20231107";
-        filePath = "/home/reghao/Downloads/api.iquizoo.com.access.log-20231108";
-
-        List<String> list = textFile.read(filePath);
-        List<NginxLog> nginxLogs = new ArrayList<>();
-        for (String line : list) {
-            if (!line.startsWith("{")) {
-                continue;
-            }
-
-            try {
-                NginxLog nginxLog = JsonConverter.jsonToObject(line, NginxLog.class);
-                nginxLogs.add(nginxLog);
-            } catch (Exception e) {
-                // e.printStackTrace();
-            }
-        }
-
-        Map<String, Integer> map = new TreeMap<>();
-        for (NginxLog nginxLog : nginxLogs) {
-            String date = nginxLog.getTimeIso8601();
-            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss+08:00")
-                    .withZone(ZoneId.of("UTC"));
-            LocalDateTime localDateTime = LocalDateTime.parse(date, formatter);
-            String dateTimeStr = DateTimeConverter.format(localDateTime);
-
-            String key = dateTimeStr;
-            Integer count = map.get(key);
-            if (count == null) {
-                map.put(key, 1);
-            } else {
-                int count1 = map.get(key) + 1;
-                map.put(key, count1);
-            }
-        }
-
-        System.out.println();
-        map.forEach((key, value) -> {
-            System.out.println(key + " -> " + value);
-        });
-    }
-}

+ 41 - 0
manager/src/test/java/DockerTest.java

@@ -0,0 +1,41 @@
+import cn.reghao.devops.common.docker.DockerImpl;
+import com.github.dockerjava.api.command.InspectContainerResponse;
+import com.github.dockerjava.api.model.Container;
+import org.junit.Test;
+
+import java.util.*;
+import java.util.regex.Pattern;
+
+/**
+ * @author reghao
+ * @date 2022-05-07 09:32:40
+ */
+public class DockerTest {
+    @Test
+    public void dockerListTest() {
+        Pattern pattern = Pattern.compile("^\\S*$");
+        String str = "dfa   safd";
+        String str1 = "dfasafd";
+        boolean matched = pattern.matcher(str).matches();
+        System.out.println();
+    }
+
+    @Test
+    public void dockerBuildTest() throws Exception {
+        DockerImpl docker = new DockerImpl();
+        String repoTag = "file:12345678";
+        String compileHome = "/home/reghao/code/aha/tnb/file/file-service";
+        docker.build(repoTag, compileHome);
+    }
+
+    @Test
+    public void dockerTest() {
+        DockerImpl docker = new DockerImpl();
+        InspectContainerResponse containerInfo = docker.ps("dnkt-admin");
+
+        List<Container> list = docker.ps(true);
+        list.forEach(container -> {
+            container.getId();
+        });
+    }
+}

+ 85 - 0
manager/src/test/java/GitTest.java

@@ -0,0 +1,85 @@
+import cn.reghao.devops.common.build.model.constant.RepoAuthType;
+import cn.reghao.devops.common.build.tool.repo.GitImpl;
+import cn.reghao.devops.manager.app.model.po.config.build.RepoAuthConfig;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author reghao
+ * @date 2022-05-07 09:32:40
+ */
+public class GitTest {
+    @Test
+    public void gitTest() throws Exception {
+        String repo = "https://git.reghao.cn/reghao/devops.git";
+        String username = "reghao";
+        String password = "gsh";
+
+        RepoAuthConfig repoAuthConfig = new RepoAuthConfig();
+        repoAuthConfig.setAuthType(RepoAuthType.http.getName());
+        repoAuthConfig.setUsername(username);
+        repoAuthConfig.setPassword(password);
+
+        GitImpl git = new GitImpl(repoAuthConfig.getRepoAuth());
+        List<String> list = git.remoteBranches(repo);
+        System.out.println();
+    }
+
+    @Test
+    public void repoTest() throws IOException, GitAPIException {
+        String localRepo = "/home/reghao/code/java/jutil/.git";
+        //checkout(localRepo);
+
+        Repository repo = new FileRepository(localRepo);
+        String branch = null;
+        String commit = null;
+        getLogsSinceCommit(repo, branch, commit);
+    }
+
+    private List<String> getLogsSinceCommit(Repository repository, String branch, String commit) throws IOException, GitAPIException {
+        if (branch == null) {
+            branch = repository.getBranch();
+        }
+
+        List<String> commits = new ArrayList<>();
+        Ref head = repository.findRef("refs/heads/" + branch);
+        if (head != null) {
+            try (RevWalk revWalk = new RevWalk(repository)) {
+                revWalk.markStart(revWalk.parseCommit(head.getObjectId()));
+                for (RevCommit revCommit : revWalk) {
+                    String commitId = revCommit.getId().getName();
+                    if (commitId.equals(commit)) {
+                        break;
+                    }
+
+                    long commitTime = revCommit.getCommitTime()*1000L;
+                    String fullMessage = revCommit.getFullMessage();
+                    commits.add(fullMessage);
+                    System.out.println("\nCommit-Message: " + fullMessage);
+                }
+                revWalk.dispose();
+            }
+        }
+
+        return commits;
+    }
+
+    private void checkout(String localRepo) throws IOException, GitAPIException {
+        Git git = Git.open(new File(localRepo));
+        String branch = git.getRepository().getBranch();
+        for (RevCommit revCommit : git.log().call()) {
+            String commitId = revCommit.getId().getName();
+            git.checkout().setStartPoint(revCommit);
+        }
+    }
+}