Skip to content

Commit e68c996

Browse files
authored
fix: overwrite test case when creating duplicated (#531)
Co-authored-by: rick <[email protected]>
1 parent d003143 commit e68c996

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

console/atest-ui/src/views/TestSuite.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ const submitForm = async (formEl: FormInstance | undefined) => {
131131
}, () => {
132132
suiteCreatingLoading.value = false
133133
emit('updated', props.name, testCaseForm.name)
134+
}, (e) => {
135+
suiteCreatingLoading.value = false
136+
ElMessage.error('Oops, ' + e)
134137
}
135138
)
136139

console/atest-ui/src/views/net.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ limitations under the License.
1515
*/
1616
import { Cache } from './cache'
1717

18-
function DefaultResponseProcess(response: any) {
18+
async function DefaultResponseProcess(response: any) {
1919
if (!response.ok) {
2020
switch (response.status) {
2121
case 401:
2222
throw new Error("Unauthenticated")
2323
}
24-
throw new Error(response.statusText)
24+
25+
const message = await response.json().then((data :any) => data.message)
26+
throw new Error(message)
2527
} else {
2628
return response.json()
2729
}

pkg/testing/loader_file.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,15 @@ func (l *fileLoader) GetTestCase(suite, name string) (testcase TestCase, err err
349349
return
350350
}
351351

352-
func (l *fileLoader) CreateTestCase(suiteName string, testcase TestCase) (err error) {
352+
func (l *fileLoader) CreateTestCase(suiteName string, testcase TestCase) error {
353+
return l.createOrUpdate(suiteName, testcase, false)
354+
}
355+
356+
func (l *fileLoader) UpdateTestCase(suite string, testcase TestCase) error {
357+
return l.createOrUpdate(suite, testcase, true)
358+
}
359+
360+
func (l *fileLoader) createOrUpdate(suiteName string, testcase TestCase, update bool) (err error) {
353361
var suite *TestSuite
354362
var suiteFilepath string
355363
for i := range l.paths {
@@ -377,18 +385,14 @@ func (l *fileLoader) CreateTestCase(suiteName string, testcase TestCase) (err er
377385

378386
if !found {
379387
suite.Items = append(suite.Items, testcase)
388+
} else if !update {
389+
err = fmt.Errorf("test case %s already exists", testcase.Name)
390+
return
380391
}
381-
382392
err = SaveTestSuiteToFile(suite, suiteFilepath)
383393
}
384394
return
385395
}
386-
387-
func (l *fileLoader) UpdateTestCase(suite string, testcase TestCase) (err error) {
388-
err = l.CreateTestCase(suite, testcase)
389-
return
390-
}
391-
392396
func (l *fileLoader) DeleteTestCase(suiteName, testcase string) (err error) {
393397
var suite *TestSuite
394398
var suiteFilepath string

pkg/testing/loader_file_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 API Testing Authors.
2+
Copyright 2023-2024 API Testing Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -189,6 +189,12 @@ func TestSuite(t *testing.T) {
189189
})
190190
assert.NoError(t, err)
191191

192+
// should failed when creating duplicated test case
193+
err = writer.CreateTestCase("test", atest.TestCase{
194+
Name: "login",
195+
})
196+
assert.Error(t, err)
197+
192198
var suite atest.TestSuite
193199
suite, err = writer.GetTestSuite("test", false)
194200
if assert.NoError(t, err) {

0 commit comments

Comments
 (0)