diff --git a/console/atest-ui/src/views/DataManager.vue b/console/atest-ui/src/views/DataManager.vue index 77698dc..39654dc 100644 --- a/console/atest-ui/src/views/DataManager.vue +++ b/console/atest-ui/src/views/DataManager.vue @@ -6,13 +6,14 @@ import type { Pair } from './types' import { ElMessage } from 'element-plus' import { Codemirror } from 'vue-codemirror' import HistoryInput from '../components/HistoryInput.vue' +import type { Ref } from 'vue' -const stores = ref([] as Store[]) +const stores: Ref = ref([]) const kind = ref('') const store = ref('') const sqlQuery = ref('') const queryResult = ref([] as any[]) -const queryResultAsJSON= ref('') +const queryResultAsJSON = ref('') const columns = ref([] as string[]) const queryTip = ref('') const loadingStores = ref(true) @@ -20,7 +21,10 @@ const dataFormat = ref('table') const dataFormatOptions = ['table', 'json'] const queryDataMeta = ref({} as QueryDataMeta) -const tablesTree = ref([]) +interface TreeItem { + label: string +} +const tablesTree = ref([] as TreeItem[]) watch(store, (s) => { kind.value = '' stores.value.forEach((e: Store) => { @@ -60,6 +64,7 @@ const queryTables = () => { watch(kind, (k) => { switch (k) { case 'atest-store-orm': + case 'atest-store-iotdb': queryTip.value = 'Enter SQL query' executeQuery() break; @@ -144,6 +149,7 @@ const executeQuery = async () => { const data = await API.DataQueryAsync(store.value, kind.value, queryDataMeta.value.currentDatabase, sqlQuery.value); switch (kind.value) { case 'atest-store-orm': + case 'atest-store-iotdb': ormDataHandler(data) success = true break; @@ -172,60 +178,64 @@ const executeQuery = async () => { diff --git a/console/atest-ui/src/views/__test__/store.spec.ts b/console/atest-ui/src/views/__test__/store.spec.ts index 49d3875..670e44b 100644 --- a/console/atest-ui/src/views/__test__/store.spec.ts +++ b/console/atest-ui/src/views/__test__/store.spec.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {SupportedExtension, SupportedExtensions} from "../store"; +import { SupportedExtension, SupportedExtensions } from "../store"; describe("SupportedExtensions", () => { test('length check', () => { const extensions = SupportedExtensions() - expect(extensions.length).toBe(6) + expect(extensions.length).toBe(7) }) for (const extension of SupportedExtensions()) { diff --git a/console/atest-ui/src/views/net.ts b/console/atest-ui/src/views/net.ts index a586917..49d2239 100644 --- a/console/atest-ui/src/views/net.ts +++ b/console/atest-ui/src/views/net.ts @@ -17,147 +17,147 @@ import { ca } from 'element-plus/es/locales.mjs' import { Cache } from './cache' async function DefaultResponseProcess(response: any) { - if (!response.ok) { - switch (response.status) { - case 401: - throw new Error("Unauthenticated") - } + if (!response.ok) { + switch (response.status) { + case 401: + throw new Error("Unauthenticated") + } - const message = await response.json().then((data :any) => data.message) - throw new Error(message) - } else { - return response.json() - } + const message = await response.json().then((data: any) => data.message) + throw new Error(message) + } else { + return response.json() + } } interface AppVersion { - version: string - commit: string - date: string + version: string + commit: string + date: string } function safeToggleFunc(toggle?: (e: boolean) => void) { - if (!toggle) { - return (e: boolean) => {} - } - return toggle + if (!toggle) { + return (e: boolean) => { } + } + return toggle } function GetVersion(callback?: (v: AppVersion) => void) { - const requestOptions = { - method: 'GET', - } - fetch('/api/v1/version', requestOptions) - .then(DefaultResponseProcess) - .then(emptyOrDefault(callback)) + const requestOptions = { + method: 'GET', + } + fetch('/api/v1/version', requestOptions) + .then(DefaultResponseProcess) + .then(emptyOrDefault(callback)) } interface TestSuite { - store: string - name: string - api: string - kind: string + store: string + name: string + api: string + kind: string } function CreateTestSuite(suite: TestSuite, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': suite.store, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - name: suite.name, - api: suite.api, - kind: suite.kind - }) - } + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': suite.store, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + name: suite.name, + api: suite.api, + kind: suite.kind + }) + } - fetch('/api/v1/suites', requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch('/api/v1/suites', requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } interface ImportSource { - store: string - url: string - kind: string + store: string + url: string + kind: string } function UpdateTestSuite(suite: any, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'PUT', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify(suite) - } - fetch(`/api/v1/suites/${suite.name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'PUT', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify(suite) + } + fetch(`/api/v1/suites/${suite.name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function GetTestSuite(name: string, - callback: (d: any) => void, errHandle?: (e: any) => void) { - const store = Cache.GetCurrentStore() - const requestOptions = { - headers: { - 'X-Store-Name': store.name, - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void) { + const store = Cache.GetCurrentStore() + const requestOptions = { + headers: { + 'X-Store-Name': store.name, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/suites/${name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/suites/${name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function DeleteTestSuite(name: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'DELETE', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'DELETE', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/suites/${name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/suites/${name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function ConvertTestSuite(suiteName: string, genertor: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - Generator: genertor, - TestSuite: suiteName - }) - } - fetch(`/api/v1/converters/convert`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + Generator: genertor, + TestSuite: suiteName + }) + } + fetch(`/api/v1/converters/convert`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function DuplicateTestSuite(sourceSuiteName: string, targetSuiteName: string, callback: (d: any) => void, errHandle?: (e: any) => void | null) { const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - sourceSuiteName: sourceSuiteName, - targetSuiteName: targetSuiteName, - }) + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + sourceSuiteName: sourceSuiteName, + targetSuiteName: targetSuiteName, + }) } fetch(`/api/v1/suites/${sourceSuiteName}/duplicate`, requestOptions) .then(DefaultResponseProcess) @@ -165,209 +165,209 @@ function DuplicateTestSuite(sourceSuiteName: string, targetSuiteName: string, } const RenameTestSuite = (sourceSuiteName: string, targetSuiteName: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) => { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - sourceSuiteName: sourceSuiteName, - targetSuiteName: targetSuiteName, - }) - } - fetch(`/api/v1/suites/${sourceSuiteName}/rename`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(errHandle) + callback: (d: any) => void, errHandle?: (e: any) => void | null) => { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + sourceSuiteName: sourceSuiteName, + targetSuiteName: targetSuiteName, + }) + } + fetch(`/api/v1/suites/${sourceSuiteName}/rename`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(errHandle) } function ImportTestSuite(source: ImportSource, callback: (d: any) => void, - errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-Store-Name': source.store, - 'X-Auth': getToken() - }, - body: JSON.stringify(source) - } + errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-Store-Name': source.store, + 'X-Auth': getToken() + }, + body: JSON.stringify(source) + } - fetch(`/api/v1/suites/import`, requestOptions). - then(DefaultResponseProcess).then(callback).catch(errHandle) + fetch(`/api/v1/suites/import`, requestOptions). + then(DefaultResponseProcess).then(callback).catch(errHandle) } export interface TestCase { - suiteName: string - name: string - request: any + suiteName: string + name: string + request: any } interface HistoryTestCase { - historyCaseID : string, - suiteName: string - caseName: string + historyCaseID: string, + suiteName: string + caseName: string } function CreateTestCase(testcase: TestCase, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - suiteName: testcase.suiteName, - data: { - name: testcase.name, - request: testcase.request - } - }) - } + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + suiteName: testcase.suiteName, + data: { + name: testcase.name, + request: testcase.request + } + }) + } - fetch(`/api/v1/suites/${testcase.suiteName}/cases`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/suites/${testcase.suiteName}/cases`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function UpdateTestCase(testcase: any, - callback: (d: any) => void, errHandle?: (e: any) => void | null, - toggle?: (e: boolean) => void) { + callback: (d: any) => void, errHandle?: (e: any) => void | null, + toggle?: (e: boolean) => void) { const requestOptions = { - method: 'PUT', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify(testcase) + method: 'PUT', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify(testcase) } safeToggleFunc(toggle)(true) fetch(`/api/v1/suites/${testcase.suiteName}/cases/${testcase.data.name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) - .finally(() => { - safeToggleFunc(toggle)(false) - }) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) + .finally(() => { + safeToggleFunc(toggle)(false) + }) } function GetTestCase(req: TestCase, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/suites/${req.suiteName}/cases/${req.name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/suites/${req.suiteName}/cases/${req.name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function ListTestCase(suite: string, store: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - headers: { - 'X-Store-Name': store, - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + headers: { + 'X-Store-Name': store, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/suites/${suite}/cases`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/suites/${suite}/cases`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function DeleteTestCase(testcase: TestCase, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { + callback: (d: any) => void, errHandle?: (e: any) => void | null) { const requestOptions = { - method: 'DELETE', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - suite: testcase.suiteName, - testcase: testcase.name - }) + method: 'DELETE', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + suite: testcase.suiteName, + testcase: testcase.name + }) } fetch(`/api/v1/suites/${testcase.suiteName}/cases/${testcase.name}`, requestOptions) - .then(callback).catch(emptyOrDefault(errHandle)) + .then(callback).catch(emptyOrDefault(errHandle)) } interface RunTestCaseRequest { - suiteName: string - name: string - parameters: any + suiteName: string + name: string + parameters: any } interface BatchRunTestCaseRequest { - count: number - interval: string - request: RunTestCaseRequest + count: number + interval: string + request: RunTestCaseRequest } function RunTestCase(request: RunTestCaseRequest, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - suite: request.suiteName, - testcase: request.name, - parameters: request.parameters - }) - } - fetch(`/api/v1/suites/${request.suiteName}/cases/${request.name}/run`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + suite: request.suiteName, + testcase: request.name, + parameters: request.parameters + }) + } + fetch(`/api/v1/suites/${request.suiteName}/cases/${request.name}/run`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } const BatchRunTestCase = (request: BatchRunTestCaseRequest, - callback: (d: any) => void, errHandle?: (e: any) => void | null) => { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'Accept': 'text/event-stream', - 'X-Auth': getToken() - }, - body: JSON.stringify({ - suiteName: request.request.suiteName, - caseName: request.request.name, - parameters: request.request.parameters, - count: request.count, - interval: request.interval, - }) - } - fetch(`/api/v1/batchRun`, requestOptions) - .then((response: any) => { - if (response.ok) { - const read = (reader: any) => { - reader.read().then((data: any) => { - if (data.done) { - return; + callback: (d: any) => void, errHandle?: (e: any) => void | null) => { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'Accept': 'text/event-stream', + 'X-Auth': getToken() + }, + body: JSON.stringify({ + suiteName: request.request.suiteName, + caseName: request.request.name, + parameters: request.request.parameters, + count: request.count, + interval: request.interval, + }) + } + fetch(`/api/v1/batchRun`, requestOptions) + .then((response: any) => { + if (response.ok) { + const read = (reader: any) => { + reader.read().then((data: any) => { + if (data.done) { + return; + } + + const value = data.value; + const chunk = new TextDecoder().decode(value, { stream: true }); + callback(JSON.parse(chunk).result.testCaseResult[0]); + read(reader); + }); + } + read(response.body.getReader()); + } else { + return DefaultResponseProcess(response) } - - const value = data.value; - const chunk = new TextDecoder().decode(value, { stream: true }); - callback(JSON.parse(chunk).result.testCaseResult[0]); - read(reader); - }); - } - read(response.body.getReader()); - } else { - return DefaultResponseProcess(response) - } - }).catch(emptyOrDefault(errHandle)) + }).catch(emptyOrDefault(errHandle)) } function DuplicateTestCase(sourceSuiteName: string, targetSuiteName: string, - sourceTestCaseName: string, targetTestCaseName: string, - callback: (d: any) => void, errHandle?: ((reason: any) => PromiseLike) | undefined | null ) { + sourceTestCaseName: string, targetTestCaseName: string, + callback: (d: any) => void, errHandle?: ((reason: any) => PromiseLike) | undefined | null) { const requestOptions = { method: 'POST', headers: { @@ -387,8 +387,8 @@ function DuplicateTestCase(sourceSuiteName: string, targetSuiteName: string, } function RenameTestCase(sourceSuiteName: string, targetSuiteName: string, - sourceTestCaseName: string, targetTestCaseName: string, - callback: (d: any) => void, errHandle?: ((reason: any) => PromiseLike) | undefined | null ) { + sourceTestCaseName: string, targetTestCaseName: string, + callback: (d: any) => void, errHandle?: ((reason: any) => PromiseLike) | undefined | null) { const requestOptions = { method: 'POST', headers: { @@ -408,217 +408,217 @@ function RenameTestCase(sourceSuiteName: string, targetSuiteName: string, } interface GenerateRequest { - suiteName: string - name: string - generator: string - id: string + suiteName: string + name: string + generator: string + id: string } function GenerateCode(request: GenerateRequest, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - TestSuite: request.suiteName, - TestCase: request.name, - Generator: request.generator - }) - } - fetch(`/api/v1/codeGenerators/generate`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + TestSuite: request.suiteName, + TestCase: request.name, + Generator: request.generator + }) + } + fetch(`/api/v1/codeGenerators/generate`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function HistoryGenerateCode(request: GenerateRequest, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - ID: request.id, - Generator: request.generator - }) - } - fetch(`/api/v1/codeGenerators/history/generate`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(errHandle) + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + ID: request.id, + Generator: request.generator + }) + } + fetch(`/api/v1/codeGenerators/history/generate`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(errHandle) } function ListCodeGenerator(callback: (d: any) => void, errHandle?: (e: any) => void | null) { - fetch('/api/v1/codeGenerators', { - headers: { - 'X-Auth': getToken() - }, - }).then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch('/api/v1/codeGenerators', { + headers: { + 'X-Auth': getToken() + }, + }).then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function PopularHeaders(callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - } - fetch(`/api/v1/popularHeaders`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + const requestOptions = { + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + } + fetch(`/api/v1/popularHeaders`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function CreateOrUpdateStore(payload: any, create: boolean, - callback: (d: any) => void, errHandle?: (e: any) => void | null, - toggle?: (e: boolean) => void) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Auth': getToken() - }, - body: JSON.stringify(payload) - } - - let api = '/api/v1/stores' - if (!create) { - api = `/api/v1/stores/${payload.name}` - requestOptions.method = "PUT" - } + callback: (d: any) => void, errHandle?: (e: any) => void | null, + toggle?: (e: boolean) => void) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Auth': getToken() + }, + body: JSON.stringify(payload) + } - safeToggleFunc(toggle)(true) - fetch(api, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)).finally(() => { - safeToggleFunc(toggle)(false) - }) + let api = '/api/v1/stores' + if (!create) { + api = `/api/v1/stores/${payload.name}` + requestOptions.method = "PUT" + } + + safeToggleFunc(toggle)(true) + fetch(api, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)).finally(() => { + safeToggleFunc(toggle)(false) + }) } function GetStores(callback: (d: any) => void, - errHandle?: (e: any) => void | null, final?: () => void | undefined | null) { - const requestOptions = { - headers: { - 'X-Auth': getToken() - }, - } - fetch('/api/v1/stores', requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)).finally(emptyOrDefault(final)) + errHandle?: (e: any) => void | null, final?: () => void | undefined | null) { + const requestOptions = { + headers: { + 'X-Auth': getToken() + }, + } + fetch('/api/v1/stores', requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)).finally(emptyOrDefault(final)) } function DeleteStore(name: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'DELETE', - headers: { - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'DELETE', + headers: { + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/stores/${name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/stores/${name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function VerifyStore(name: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Auth': getToken() - }, - body: JSON.stringify({ - name: name - }) - } - - const api = `/api/v1/stores/verify` - fetch(api, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Auth': getToken() + }, + body: JSON.stringify({ + name: name + }) + } + + const api = `/api/v1/stores/verify` + fetch(api, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } export interface Secret { - Name: string - Value: string + Name: string + Value: string } function GetSecrets(callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - headers: { - 'X-Auth': getToken() - }, - } - fetch(`/api/v1/secrets`, requestOptions) - .then(DefaultResponseProcess) - .then(callback) - .catch(emptyOrDefault(errHandle)) + const requestOptions = { + headers: { + 'X-Auth': getToken() + }, + } + fetch(`/api/v1/secrets`, requestOptions) + .then(DefaultResponseProcess) + .then(callback) + .catch(emptyOrDefault(errHandle)) } function FunctionsQuery(filter: string, kind: string, - callback: (d: any) => void, errHandle?: (e: any) => (PromiseLike | void | null | undefined) | undefined | null) { - const requestOptions = { - headers: { - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => (PromiseLike | void | null | undefined) | undefined | null) { + const requestOptions = { + headers: { + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/functions?name=${filter}&kind=${kind}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/functions?name=${filter}&kind=${kind}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)) } function DeleteSecret(name: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: "DELETE", - headers: { - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: "DELETE", + headers: { + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/secrets/${name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback) - .catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/secrets/${name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback) + .catch(emptyOrDefault(errHandle)) } function CreateOrUpdateSecret(payload: Secret, create: boolean, - callback: (d: any) => void, errHandle?: (e: any) => void | null, - toggle?: (e: boolean) => void) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Auth': getToken() - }, - body: JSON.stringify(payload) - } - - let api = `/api/v1/secrets` - if (!create) { - api = `/api/v1/secrets/${payload.Name}` - requestOptions.method = "PUT" - } + callback: (d: any) => void, errHandle?: (e: any) => void | null, + toggle?: (e: boolean) => void) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Auth': getToken() + }, + body: JSON.stringify(payload) + } - safeToggleFunc(toggle)(true) - fetch(api, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(emptyOrDefault(errHandle)).finally(() => { - safeToggleFunc(toggle)(false) - }) + let api = `/api/v1/secrets` + if (!create) { + api = `/api/v1/secrets/${payload.Name}` + requestOptions.method = "PUT" + } + + safeToggleFunc(toggle)(true) + fetch(api, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(emptyOrDefault(errHandle)).finally(() => { + safeToggleFunc(toggle)(false) + }) } function GetSuggestedAPIs(name: string, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/suggestedAPIs?name=${name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback) + fetch(`/api/v1/suggestedAPIs?name=${name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback) } function GetSwaggers(callback: (d: any) => void) { @@ -628,96 +628,96 @@ function GetSwaggers(callback: (d: any) => void) { } function ReloadMockServer(config: any) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Auth': getToken() - }, - body: JSON.stringify(config) - } - fetch(`/api/v1/mock/reload`, requestOptions) - .then(DefaultResponseProcess) + const requestOptions = { + method: 'POST', + headers: { + 'X-Auth': getToken() + }, + body: JSON.stringify(config) + } + fetch(`/api/v1/mock/reload`, requestOptions) + .then(DefaultResponseProcess) } function GetMockConfig(callback: (d: any) => void) { - const requestOptions = { - headers: { - 'X-Auth': getToken() + const requestOptions = { + headers: { + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/mock/config`, requestOptions) - .then(DefaultResponseProcess) - .then(callback) + fetch(`/api/v1/mock/config`, requestOptions) + .then(DefaultResponseProcess) + .then(callback) } function getToken() { - const token = sessionStorage.getItem('token') - if (!token) { - return '' - } - return token + const token = sessionStorage.getItem('token') + if (!token) { + return '' + } + return token } const GetTestSuiteYaml = (suite: string, callback: (d: any) => void, errHandle?: (e: any) => void | null) => { - const requestOptions = { - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() + const requestOptions = { + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/suites/${suite}/yaml`, requestOptions) - .then(DefaultResponseProcess) - .then(callback) - .catch(emptyOrDefault(errHandle)) + fetch(`/api/v1/suites/${suite}/yaml`, requestOptions) + .then(DefaultResponseProcess) + .then(callback) + .catch(emptyOrDefault(errHandle)) } function emptyOrDefault(fn: any) { if (fn) { return fn } - return () => {} + return () => { } } function GetHistoryTestCaseWithResult(req: HistoryTestCase, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/historyTestCaseWithResult/${req.historyCaseID}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(errHandle) + fetch(`/api/v1/historyTestCaseWithResult/${req.historyCaseID}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(errHandle) } function GetHistoryTestCase(req: HistoryTestCase, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + } } - } - fetch(`/api/v1/historyTestCase/${req.historyCaseID}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(errHandle) + fetch(`/api/v1/historyTestCase/${req.historyCaseID}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(errHandle) } function DeleteHistoryTestCase(req: HistoryTestCase, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { + callback: (d: any) => void, errHandle?: (e: any) => void | null) { const requestOptions = { - method: 'DELETE', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - ID : req.historyCaseID - }) + method: 'DELETE', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + ID: req.historyCaseID + }) } fetch(`/api/v1/historyTestCase/${req.historyCaseID}`, requestOptions) - .then(callback).catch(errHandle) + .then(callback).catch(errHandle) } function DeleteAllHistoryTestCase(suiteName: string, caseName: string, @@ -729,8 +729,8 @@ function DeleteAllHistoryTestCase(suiteName: string, caseName: string, 'X-Auth': getToken() }, body: JSON.stringify({ - suiteName : suiteName, - caseName: caseName, + suiteName: suiteName, + caseName: caseName, }) } fetch(`/api/v1/suites/${suiteName}/cases/${caseName}`, requestOptions) @@ -738,21 +738,21 @@ function DeleteAllHistoryTestCase(suiteName: string, caseName: string, } function GetTestCaseAllHistory(req: TestCase, - callback: (d: any) => void, errHandle?: (e: any) => void | null) { - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': Cache.GetCurrentStore().name, - 'X-Auth': getToken() - }, - body: JSON.stringify({ - suiteName: req.suiteName, - name: req.name - }) - } - fetch(`/api/v1/suites/${req.suiteName}/cases/${req.name}`, requestOptions) - .then(DefaultResponseProcess) - .then(callback).catch(errHandle) + callback: (d: any) => void, errHandle?: (e: any) => void | null) { + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': Cache.GetCurrentStore().name, + 'X-Auth': getToken() + }, + body: JSON.stringify({ + suiteName: req.suiteName, + name: req.name + }) + } + fetch(`/api/v1/suites/${req.suiteName}/cases/${req.name}`, requestOptions) + .then(DefaultResponseProcess) + .then(callback).catch(errHandle) } function DownloadResponseFile(testcase, @@ -775,57 +775,89 @@ function DownloadResponseFile(testcase, } var SBOM = (callback: (d: any) => void) => { - fetch(`/api/sbom`, {}) - .then(DefaultResponseProcess) - .then(callback) + fetch(`/api/sbom`, {}) + .then(DefaultResponseProcess) + .then(callback) } interface QueryObject { - sql: string - key: string + sql: string + key: string } var DataQueryAsync = (store: string, kind: string, currentDatabase: string, query: string) => { - const queryObj = {} as QueryObject; - switch (kind) { - case 'atest-store-orm': - queryObj['sql'] = query; - queryObj['key'] = currentDatabase; - break; - case 'atest-store-etcd': - queryObj['key'] = query; - break; - case 'atest-store-redis': - queryObj['key'] = query; - break; - } - const requestOptions = { - method: 'POST', - headers: { - 'X-Store-Name': store, - 'X-Database': currentDatabase - }, - body: JSON.stringify(queryObj) - } - return fetch(`/api/v1/data/query`, requestOptions) - .then(DefaultResponseProcess) + const queryObj = {} as QueryObject; + switch (kind) { + case 'atest-store-orm': + queryObj['sql'] = query; + queryObj['key'] = currentDatabase; + break; + case 'atest-store-iotdb': + queryObj['sql'] = query; + queryObj['key'] = currentDatabase; + break; + case 'atest-store-etcd': + queryObj['key'] = query; + break; + case 'atest-store-redis': + queryObj['key'] = query; + break; + } + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': store, + 'X-Database': currentDatabase + }, + body: JSON.stringify(queryObj) + } + return fetch(`/api/v1/data/query`, requestOptions) + .then(DefaultResponseProcess) } var DataQuery = (store: string, kind: string, currentDatabase: string, query: string, callback: (d: any) => void, errHandler: (d: any) => void) => { - DataQueryAsync(store, kind, currentDatabase, query).then(callback).catch(errHandler) + const queryObj = {} as QueryObject + switch (kind) { + case 'atest-store-orm': + queryObj['sql'] = query; + queryObj['key'] = currentDatabase; + break; + case 'atest-store-iotdb': + queryObj['sql'] = query; + queryObj['key'] = currentDatabase; + break; + case 'atest-store-etcd': + queryObj['key'] = query; + break; + case 'atest-store-redis': + queryObj['key'] = query; + break; + } + const requestOptions = { + method: 'POST', + headers: { + 'X-Store-Name': store, + 'X-Database': currentDatabase + }, + body: JSON.stringify(queryObj) + } + fetch(`/api/v1/data/query`, requestOptions) + .then(DefaultResponseProcess) + .then(callback) + .catch(errHandler) } export const API = { - DefaultResponseProcess, - GetVersion, - CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite, DuplicateTestSuite, RenameTestSuite, GetTestSuiteYaml, - CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, DuplicateTestCase, RenameTestCase, RunTestCase, BatchRunTestCase, - GetHistoryTestCaseWithResult, DeleteHistoryTestCase,GetHistoryTestCase, GetTestCaseAllHistory, DeleteAllHistoryTestCase, DownloadResponseFile, - GenerateCode, ListCodeGenerator, HistoryGenerateCode, - PopularHeaders, - CreateOrUpdateStore, GetStores, DeleteStore, VerifyStore, - FunctionsQuery, - GetSecrets, DeleteSecret, CreateOrUpdateSecret, - GetSuggestedAPIs, GetSwaggers, - ReloadMockServer, GetMockConfig, SBOM, DataQuery, DataQueryAsync, - getToken + DefaultResponseProcess, + GetVersion, + CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite, DuplicateTestSuite, RenameTestSuite, GetTestSuiteYaml, + CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, DuplicateTestCase, RenameTestCase, RunTestCase, BatchRunTestCase, + GetHistoryTestCaseWithResult, DeleteHistoryTestCase, GetHistoryTestCase, GetTestCaseAllHistory, DeleteAllHistoryTestCase, DownloadResponseFile, + GenerateCode, ListCodeGenerator, HistoryGenerateCode, + PopularHeaders, + CreateOrUpdateStore, GetStores, DeleteStore, VerifyStore, + FunctionsQuery, + GetSecrets, DeleteSecret, CreateOrUpdateSecret, + GetSuggestedAPIs, GetSwaggers, + ReloadMockServer, GetMockConfig, SBOM, DataQuery, DataQueryAsync, + getToken } diff --git a/console/atest-ui/src/views/store.ts b/console/atest-ui/src/views/store.ts index e326880..00915a9 100644 --- a/console/atest-ui/src/views/store.ts +++ b/console/atest-ui/src/views/store.ts @@ -83,6 +83,11 @@ const storeExtensions = [ }], link: 'https://github.com/LinuxSuRen/atest-ext-store-orm' }, + { + name: 'atest-store-iotdb', + params: [], + link: 'https://github.com/LinuxSuRen/atest-ext-store-iotdb' + }, { name: 'atest-store-etcd', params: [], diff --git a/extensions/README.md b/extensions/README.md index f6ca271..e7a27ae 100644 --- a/extensions/README.md +++ b/extensions/README.md @@ -8,6 +8,7 @@ Ports in extensions: | Store | [git](https://github.com/LinuxSuRen/atest-ext-store-git) | 4074 | | Store | [mongodb](https://github.com/LinuxSuRen/atest-ext-store-mongodb) | 4075 | | Store | [redis](https://github.com/LinuxSuRen/atest-ext-store-redis) | | +| Store | [iotdb](https://github.com/LinuxSuRen/atest-ext-store-iotdb) | | | Monitor | [docker-monitor](https://github.com/LinuxSuRen/atest-ext-monitor-docker) | | | Agent | [collector](https://github.com/LinuxSuRen/atest-ext-collector) | | | Secret | [Vault](https://github.com/LinuxSuRen/api-testing-vault-extension) | | @@ -20,6 +21,7 @@ Ports in extensions: * Finally, add the extension's name into function [SupportedExtensions](../console/atest-ui/src/views/store.ts). ## Naming conventions + Please follow the following conventions if you want to add a new store extension: `store-xxx` diff --git a/pkg/server/remote_server.go b/pkg/server/remote_server.go index 0feb59c..55e2564 100644 --- a/pkg/server/remote_server.go +++ b/pkg/server/remote_server.go @@ -1157,6 +1157,9 @@ func (s *server) GetStores(ctx context.Context, in *Empty) (reply *Stores, err e } for _, item := range stores { grpcStore := ToGRPCStore(item) + if item.Disabled { + continue + } storeStatus, sErr := s.VerifyStore(ctx, &SimpleQuery{Name: item.Name}) grpcStore.Ready = sErr == nil && storeStatus.Ready