Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions console/atest-ui/src/components/EditButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script setup lang="ts">
import { nextTick, ref } from 'vue'
import { ElInput } from 'element-plus'
import type { InputInstance } from 'element-plus'

const props = defineProps({
value: String,
})

const emit = defineEmits(['changed'])
const inputVisible = ref(false)
const inputValue = ref('')
const InputRef = ref<InputInstance>()

const showInput = () => {
inputVisible.value = true
inputValue.value = props.value ?? ''
nextTick(() => {
InputRef.value!.input!.focus()
})
}

const handleInputConfirm = () => {
if (inputValue.value && props.value !== inputValue.value) {
emit('changed', inputValue.value)
}
inputVisible.value = false
inputValue.value = ''
}
</script>

<template>
<span class="flex gap-2">
<el-input
v-if="inputVisible"
ref="InputRef"
v-model="inputValue"
class="w-20"
style="width: 200px"
@keyup.enter="handleInputConfirm"
@blur="handleInputConfirm"
/>
<el-button v-else class="button-new-tag" size="small" @click="showInput">
{{ value }}
</el-button>
</span>
</template>
46 changes: 27 additions & 19 deletions console/atest-ui/src/views/TestCase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Pair, TestResult, TestCaseWithSuite, TestCase } from './types'
import { NewSuggestedAPIsQuery, CreateFilter, GetHTTPMethods, FlattenObject } from './types'
import { Cache } from './cache'
import { API } from './net'
import EditButton from '../components/EditButton.vue'
import type { RunTestCaseRequest } from './net'
import { UIAPI } from './net-vue'
import type { TestCaseResponse } from './cache'
Expand All @@ -23,7 +24,6 @@ import 'codemirror/addon/merge/merge.css'

import DiffMatchPatch from 'diff-match-patch';


window.diff_match_patch = DiffMatchPatch;
window.DIFF_DELETE = -1;
window.DIFF_INSERT = 1;
Expand Down Expand Up @@ -380,25 +380,25 @@ function downloadResponseFile(){
API.DownloadResponseFile({
body: testResult.value.body
}, (e) => {
if (e && e.data) {
try {
const bytes = atob(e.data);
const blob = new Blob([bytes], { type: 'mimeType' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = e.filename.substring("isFilePath-".length);

document.body.appendChild(link);
link.click();

window.URL.revokeObjectURL(link.href);
document.body.removeChild(link);
} catch (error) {
console.error('Error during file download:', error);
if (e && e.data) {
try {
const bytes = atob(e.data);
const blob = new Blob([bytes], { type: 'mimeType' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = e.filename.substring("isFilePath-".length);

document.body.appendChild(link);
link.click();

window.URL.revokeObjectURL(link.href);
document.body.removeChild(link);
} catch (error) {
console.error('Error during file download:', error);
}
} else {
console.error('No data to download.');
}
} else {
console.error('No data to download.');
}
})
}

Expand Down Expand Up @@ -877,6 +877,13 @@ Magic.Keys(() => {
duplicateTestCase()
}
}, ['Alt+KeyO'])

const renameTestCase = (name: string) => {
const suiteName = props.suite
API.RenameTestCase(suiteName, suiteName, props.name, name, (d) => {
emit('updated', suiteName, name)
})
}
</script>

<template>
Expand All @@ -894,6 +901,7 @@ Magic.Keys(() => {
<el-button type="primary" @click="openCodeDialog">{{ t('button.generateCode') }}</el-button>
<el-button type="primary" v-if="!isHistoryTestCase && Cache.GetCurrentStore().kind.name == 'atest-store-orm'" @click="openHistoryDialog">{{ t('button.viewHistory') }}</el-button>
<span v-if="isHistoryTestCase" style="margin-left: 15px;">{{ t('tip.runningAt') }}{{ HistoryTestCaseCreateTime }}</span>
<EditButton :value="props.name" @changed="renameTestCase"/>
</div>
<div>
<el-row>
Expand Down
9 changes: 8 additions & 1 deletion console/atest-ui/src/views/TestSuite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Edit, CopyDocument, Delete } from '@element-plus/icons-vue'
import type { FormInstance, FormRules } from 'element-plus'
import type { Suite, TestCase, Pair } from './types'
import { NewSuggestedAPIsQuery, GetHTTPMethods } from './types'
import EditButton from '../components/EditButton.vue'
import { Cache } from './cache'
import { useI18n } from 'vue-i18n'
import { API } from './net'
Expand Down Expand Up @@ -252,11 +253,17 @@ const duplicateTestSuite = () => {
}
const testSuiteDuplicateDialog = ref(false)
const targetSuiteDuplicateName = ref('')

const renameTestSuite = (name: string) => {
API.RenameTestSuite(props.name, name, (d) => {
emit('updated', name)
})
}
</script>

<template>
<div class="common-layout">
{{ t('tip.testsuite') }}<el-text class="mx-1" type="primary">{{ suite.name }}</el-text>
{{ t('tip.testsuite') }}<EditButton :value="suite.name" @changed="renameTestSuite"/>

<table style="width: 100%">
<tr>
Expand Down
43 changes: 41 additions & 2 deletions console/atest-ui/src/views/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ function DuplicateTestSuite(sourceSuiteName: string, targetSuiteName: string,
.then(callback).catch(errHandle)
}

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)
}

function ImportTestSuite(source: ImportSource, callback: (d: any) => void,
errHandle?: (e: any) => void | null) {
const requestOptions = {
Expand Down Expand Up @@ -367,6 +385,27 @@ function DuplicateTestCase(sourceSuiteName: string, targetSuiteName: string,
.then(callback).catch(errHandle)
}

function RenameTestCase(sourceSuiteName: string, targetSuiteName: string,
sourceTestCaseName: string, targetTestCaseName: string,
callback: (d: any) => void, errHandle?: ((reason: any) => PromiseLike<never>) | undefined | null ) {
const requestOptions = {
method: 'POST',
headers: {
'X-Store-Name': Cache.GetCurrentStore().name,
'X-Auth': getToken()
},
body: JSON.stringify({
sourceSuiteName: sourceSuiteName,
targetSuiteName: targetSuiteName,
sourceCaseName: sourceTestCaseName,
targetCaseName: targetTestCaseName,
})
}
fetch(`/api/v1/suites/${sourceSuiteName}/cases/${sourceTestCaseName}/rename`, requestOptions)
.then(DefaultResponseProcess)
.then(callback).catch(errHandle)
}

interface GenerateRequest {
suiteName: string
name: string
Expand Down Expand Up @@ -734,8 +773,8 @@ function DownloadResponseFile(testcase,
export const API = {
DefaultResponseProcess,
GetVersion,
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite, DuplicateTestSuite, GetTestSuiteYaml,
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, RunTestCase, BatchRunTestCase,
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,
Expand Down
2 changes: 1 addition & 1 deletion e2e/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ atest extension --output /usr/local/bin --registry ghcr.io mongodb

echo "start to run server"
nohup atest server --tls-grpc --cert-file test.pem --key-file test.key&
cmd="atest run -p test-suite-common.yaml"
cmd="atest run -p test-suite-common.yaml --request-ignore-error"

echo "start to run testing: $cmd"
kind=orm target=mysql:3306 driver=mysql $cmd
Expand Down
3 changes: 2 additions & 1 deletion e2e/test-suite-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ param:
caseName: "{{randAlpha 6}}"
gRPCSuiteName: "{{randAlpha 6}}"
gRPCCaseName: "{{randAlpha 6}}"
store: "{{randAlpha 3}}"
store: |
{{randAlpha 6}}-{{env "kind"}}
server: |
{{default "http://localhost:8080" (env "SERVER")}}
items:
Expand Down
2 changes: 0 additions & 2 deletions pkg/runner/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ func ammendHeaders(headers http.Header, body []byte) {
if val := headers.Get(util.ContentLength); val == "" {
headers.Add(util.ContentLength, strconv.Itoa(len(body)))
fmt.Printf("add content-length: %d\n", len(body))
} else {
fmt.Printf("content-length already exist: %s\n", val)
}
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/server/remote_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ func (s *server) DuplicateTestSuite(ctx context.Context, in *TestSuiteDuplicate)
return
}

func (s *server) RenameTestSuite(ctx context.Context, in *TestSuiteDuplicate) (reply *HelloReply, err error) {
reply = &HelloReply{}
loader := s.getLoader(ctx)
defer loader.Close()
err = loader.RenameTestSuite(in.SourceSuiteName, in.TargetSuiteName)
return
}

func (s *server) ListTestCase(ctx context.Context, in *TestSuiteIdentity) (result *Suite, err error) {
var items []testing.TestCase
loader := s.getLoader(ctx)
Expand Down Expand Up @@ -914,6 +922,14 @@ func (s *server) DuplicateTestCase(ctx context.Context, in *TestCaseDuplicate) (
return
}

func (s *server) RenameTestCase(ctx context.Context, in *TestCaseDuplicate) (result *HelloReply, err error) {
result = &HelloReply{}
loader := s.getLoader(ctx)
defer loader.Close()
err = loader.RenameTestCase(in.SourceSuiteName, in.SourceCaseName, in.TargetCaseName)
return
}

// code generator
func (s *server) ListCodeGenerator(ctx context.Context, in *Empty) (reply *SimpleList, err error) {
reply = &SimpleList{}
Expand Down
14 changes: 14 additions & 0 deletions pkg/server/remote_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ func TestUpdateTestCase(t *testing.T) {
testCase, err = server.GetTestCase(ctx, &TestCaseIdentity{Suite: "simple", Testcase: "get"})
assert.Nil(t, testCase)
assert.Error(t, err)

_, err = server.RenameTestCase(ctx, &TestCaseDuplicate{
SourceCaseName: "get",
SourceSuiteName: "simple",
TargetCaseName: "get2",
})
assert.Error(t, err)

// rename test suite
_, err = server.RenameTestSuite(ctx, &TestSuiteDuplicate{
SourceSuiteName: "simple",
TargetSuiteName: "simple2",
})
assert.NoError(t, err)
})
}

Expand Down
Loading
Loading