Skip to content

Commit

Permalink
fix: history record generate code
Browse files Browse the repository at this point in the history
  • Loading branch information
SamYSF committed Sep 9, 2024
1 parent 6eb2483 commit 077533f
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 211 deletions.
48 changes: 33 additions & 15 deletions console/atest-ui/src/views/TestCase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,40 @@ function sendRequestWithParameter() {
function generateCode() {
const name = props.name
const suite = props.suite
const ID = props.historyCaseID
if (isHistoryTestCase.value == true){
API.HistoryGenerateCode({
ID: ID,
generator: currentCodeGenerator.value
}, (e) => {
ElMessage({
message: 'Code generated!',
type: 'success'
})
if (currentCodeGenerator.value === "gRPCPayload") {
currentCodeContent.value = JSON.stringify(JSON.parse(e.message), null, 4)
} else {
currentCodeContent.value = e.message
}
}, UIAPI.ErrorTip)
} else{
API.GenerateCode({
suiteName: suite,
name: name,
generator: currentCodeGenerator.value
}, (e) => {
ElMessage({
message: 'Code generated!',
type: 'success'
})
if (currentCodeGenerator.value === "gRPCPayload") {
currentCodeContent.value = JSON.stringify(JSON.parse(e.message), null, 4)
} else {
currentCodeContent.value = e.message
}
}, UIAPI.ErrorTip)
}
API.GenerateCode({
suiteName: suite,
name: name,
generator: currentCodeGenerator.value
}, (e) => {
ElMessage({
message: 'Code generated!',
type: 'success'
})
if (currentCodeGenerator.value === "gRPCPayload") {
currentCodeContent.value = JSON.stringify(JSON.parse(e.message), null, 4)
} else {
currentCodeContent.value = e.message
}
}, UIAPI.ErrorTip)
}
function copyCode() {
Expand Down
27 changes: 23 additions & 4 deletions console/atest-ui/src/views/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ interface GenerateRequest {
suiteName: string
name: string
generator: string
id: string
}

function GenerateCode(request: GenerateRequest,
Expand All @@ -335,16 +336,34 @@ function GenerateCode(request: GenerateRequest,
'X-Auth': getToken()
},
body: JSON.stringify({
TestSuite: request.suiteName,
TestCase: request.name,
Generator: request.generator
TestSuite: request.suiteName,
TestCase: request.name,
Generator: request.generator
})
}
fetch(`/api/v1/codeGenerators/generate`, requestOptions)
.then(DefaultResponseProcess)
.then(callback).catch(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)
}

function ListCodeGenerator(callback: (d: any) => void, errHandle?: (e: any) => void | null) {
fetch('/api/v1/codeGenerators', {
headers: {
Expand Down Expand Up @@ -681,7 +700,7 @@ export const API = {
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite,GetTestSuiteYaml,
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, RunTestCase,
GetHistoryTestCaseWithResult, DeleteHistoryTestCase,GetHistoryTestCase, GetTestCaseAllHistory, DeleteAllHistoryTestCase, DownloadResponseFile,
GenerateCode, ListCodeGenerator,
GenerateCode, ListCodeGenerator, HistoryGenerateCode,
PopularHeaders,
CreateOrUpdateStore, GetStores, DeleteStore, VerifyStore,
FunctionsQuery,
Expand Down
25 changes: 25 additions & 0 deletions pkg/server/remote_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,31 @@ func (s *server) GenerateCode(ctx context.Context, in *CodeGenerateRequest) (rep
return
}

func (s *server) HistoryGenerateCode(ctx context.Context, in *CodeGenerateRequest) (reply *CommonResult, err error) {
reply = &CommonResult{}
instance := generator.GetCodeGenerator(in.Generator)
if instance == nil {
reply.Success = false
reply.Message = fmt.Sprintf("generator '%s' not found", in.Generator)
} else {
loader := s.getLoader(ctx)
var result testing.HistoryTestCase
result, err = loader.GetHistoryTestCase(in.ID)
var testCase testing.TestCase
var suite testing.TestSuite
testCase = result.Data
suite.Name = result.SuiteName
suite.API = result.SuiteAPI
suite.Spec = result.SuiteSpec
suite.Param = result.SuiteParam

output, genErr := instance.Generate(&suite, &testCase)
reply.Success = genErr == nil
reply.Message = util.OrErrorMessage(genErr, output)
}
return
}

// converter
func (s *server) ListConverter(ctx context.Context, in *Empty) (reply *SimpleList, err error) {
reply = &SimpleList{}
Expand Down
Loading

0 comments on commit 077533f

Please sign in to comment.