From aba9b852b651a085e48b8ced5afec8a8660d8305 Mon Sep 17 00:00:00 2001 From: rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:17:02 +0800 Subject: [PATCH] feat: auto locate to the last testcase --- cmd/service.go | 18 ++- console/atest-ui/src/App.vue | 117 ++++++++++++------- console/atest-ui/src/views/SecretManager.vue | 12 +- console/atest-ui/src/views/StoreManager.vue | 4 + console/atest-ui/src/views/cache.ts | 20 +++- 5 files changed, 120 insertions(+), 51 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index 1f95e68b..0bb2488b 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -45,6 +45,7 @@ Mirror Images: docker.m.daocloud.io/linuxsuren/api-testing`, flags.StringVarP(&opt.version, "version", "", version.GetVersion(), "The version of the service image") flags.StringVarP(&opt.localStorage, "local-storage", "", "/var/data/atest", "The local storage path which will be mounted into the container") + flags.StringVarP(&opt.secretServer, "secret-server", "", "", "The secret server URL") return } @@ -58,6 +59,7 @@ type serviceOption struct { mode string localStorage string pull string + secretServer string stdOut io.Writer } @@ -213,7 +215,7 @@ func (o *serviceOption) getContainerService() (service Service, err error) { clientPath = client } service = newContainerService(o.Execer, clientPath, - o.image, o.version, o.pull, o.localStorage, o.stdOut) + o.image, o.version, o.pull, o.localStorage, o.secretServer, o.stdOut) } return } @@ -319,13 +321,14 @@ type containerService struct { tag string pull string localStorage string + secretServer string stdOut io.Writer errOut io.Writer } const defaultImage = "ghcr.io/linuxsuren/api-testing" -func newContainerService(execer fakeruntime.Execer, client, image, tag, pull, localStorage string, writer io.Writer) (svc Service) { +func newContainerService(execer fakeruntime.Execer, client, image, tag, pull, localStorage string, secretServer string, writer io.Writer) (svc Service) { if tag == "" { tag = "latest" } @@ -341,6 +344,7 @@ func newContainerService(execer fakeruntime.Execer, client, image, tag, pull, lo tag: tag, pull: pull, localStorage: localStorage, + secretServer: secretServer, stdOut: writer, errOut: writer, } @@ -398,14 +402,20 @@ func (s *containerService) exist() bool { } func (s *containerService) getStartArgs() []string { - return []string{"run", "--name=" + s.name, + args := []string{"run", "--name=" + s.name, "--restart=always", "-d", fmt.Sprintf("--pull=%s", s.pull), "--network=host", "-v", s.localStorage + ":/var/www/data", "-v", "/root/.config/atest:/root/.config/atest", - s.image + ":" + s.tag} + s.image + ":" + s.tag, + "atest", "server"} + if s.secretServer != "" { + args = append(args, "--secret-server="+s.secretServer) + } + args = append(args, "--console-path=/var/www/html") + return args } type podmanService struct { diff --git a/console/atest-ui/src/App.vue b/console/atest-ui/src/App.vue index d102de2c..33a53aee 100644 --- a/console/atest-ui/src/App.vue +++ b/console/atest-ui/src/App.vue @@ -10,6 +10,7 @@ import { ElTree } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus' import { Edit, Share } from '@element-plus/icons-vue' import type { Suite } from './types' +import { GetLastTestCaseLocation, SetLastTestCaseLocation } from './views/cache' import { useI18n } from 'vue-i18n' const { t } = useI18n() @@ -18,6 +19,7 @@ interface Tree { id: string label: string parent: string + parentID: string store: string children?: Tree[] } @@ -50,12 +52,14 @@ const handleNodeClick = (data: Tree) => { id: data.label + item.name, label: item.name, store: data.store, - parent: data.label + parent: data.label, + parentID: data.id } as Tree) }) } }) } else { + SetLastTestCaseLocation(data.parentID, data.id) testCaseName.value = data.label testSuite.value = data.parent store.value = data.store @@ -74,46 +78,34 @@ function loadTestSuites(storeName: string) { 'X-Store-Name': storeName }, } - fetch('/server.Runner/GetSuites', requestOptions) - .then((response) => response.json()) - .then((d) => { - if (!d.data) { - return - } - Object.keys(d.data).map((k) => { - let suite = { - id: k, - label: k, - store: storeName, - children: [] as Tree[] - } as Tree - - d.data[k].data.forEach((item: any) => { - suite.children?.push({ - id: k + item, - label: item, + return async () => { + await fetch('/server.Runner/GetSuites', requestOptions) + .then((response) => response.json()) + .then((d) => { + if (!d.data) { + return + } + Object.keys(d.data).map((k) => { + let suite = { + id: k, + label: k, store: storeName, - parent: k - } as Tree) + children: [] as Tree[] + } as Tree + + d.data[k].data.forEach((item: any) => { + suite.children?.push({ + id: k + item, + label: item, + store: storeName, + parent: k, + parentID: suite.id + } as Tree) + }) + data.value.push(suite) }) - data.value.push(suite) }) - - if (data.value.length > 0) { - const firstItem = data.value[0] - if (firstItem.children && firstItem.children.length > 0) { - const child = firstItem.children[0].id - - currentNodekey.value = child - treeRef.value!.setCurrentKey(child) - treeRef.value!.setCheckedKeys([child], false) - } - - viewName.value = 'testsuite' - testSuite.value = firstItem.label - store.value = firstItem.store - } - }) + } } interface Store { @@ -128,17 +120,52 @@ function loadStores() { } fetch('/server.Runner/GetStores', requestOptions) .then((response) => response.json()) - .then((d) => { + .then(async (d) => { stores.value = d.data data.value = [] as Tree[] - d.data.forEach((item: any) => { + for (const item of d.data) { if (item.ready) { - loadTestSuites(item.name) + await loadTestSuites(item.name)() + } + } + + if (data.value.length > 0) { + const key = GetLastTestCaseLocation() + + let targetSuite = {} as Tree + let targetChild = {} as Tree + if (key.suite !== '' && key.testcase !== '') { + for (var i = 0; i < data.value.length; i++) { + const item = data.value[i] + if (item.id === key.suite && item.children) { + for (var j = 0; j < item.children.length; j++) { + const child = item.children[j] + if (child.id === key.testcase) { + targetSuite = item + targetChild = child + break + } + } + break + } + } + } + + if (!targetChild.id || targetChild.id === '') { + targetSuite = data.value[0] + if (targetSuite.children && targetSuite.children.length > 0) { + targetChild = targetSuite.children[0] + } } - }) - if (data.value.length === 0) { + viewName.value = 'testsuite' + currentNodekey.value = targetChild.id + treeRef.value!.setCurrentKey(targetChild.id) + treeRef.value!.setCheckedKeys([targetChild.id], false) + testSuite.value = targetSuite.label + store.value = targetSuite.store + } else { viewName.value = "" } }) @@ -278,6 +305,8 @@ const viewName = ref('') @node-click="handleNodeClick" data-intro="This is the test suite tree. You can click the test suite to edit it." /> + + @@ -391,8 +420,6 @@ const viewName = ref('') - -