-
Notifications
You must be signed in to change notification settings - Fork 66
/
processor-custom-code.go
76 lines (64 loc) · 2.52 KB
/
processor-custom-code.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package agentExec
import (
"github.com/aaronchen2k/deeptest/internal/agent/exec/domain"
"github.com/aaronchen2k/deeptest/internal/agent/exec/utils/exec"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
"github.com/aaronchen2k/deeptest/internal/pkg/domain"
scriptHelper "github.com/aaronchen2k/deeptest/internal/pkg/helper/script"
commonUtils "github.com/aaronchen2k/deeptest/pkg/lib/comm"
logUtils "github.com/aaronchen2k/deeptest/pkg/lib/log"
uuid "github.com/satori/go.uuid"
"time"
)
type ProcessorCustomCode struct {
ID uint `json:"id" yaml:"id"`
ProcessorEntityBase
TenantId consts.TenantId `json:"tenantId"`
Content string `gorm:"type:longtext;" json:"content" yaml:"content"`
Desc string `json:"desc" yaml:"desc"`
}
func (entity ProcessorCustomCode) Run(processor *Processor, session *Session) (err error) {
defer func() {
if errX := recover(); errX != nil {
processor.Error(session, errX)
}
}()
logUtils.Infof("print entity")
startTime := time.Now()
processor.Result = &agentDomain.ScenarioExecResult{
ID: int(entity.ProcessorID),
Name: entity.Name,
ProcessorCategory: entity.ProcessorCategory,
ProcessorType: entity.ProcessorType,
StartTime: &startTime,
ParentId: int(entity.ParentID),
ScenarioId: processor.ScenarioId,
ProcessorId: processor.ID,
LogId: uuid.NewV4(),
ParentLogId: processor.Parent.Result.LogId,
Round: processor.Round,
}
scriptBase := domain.ScriptBase{
Content: entity.Content,
}
err = ExecScript(&scriptBase, session.TenantId, processor.ProjectId, session.ExecUuid)
scriptHelper.GenResultMsg(&scriptBase)
//scriptBase.VariableSettings = VariableSettings
for _, item := range *GetGojaVariables(session.ExecUuid) {
SetVariable(processor.ParentId, item.Name, item.Value, item.ValueType, consts.Public, session.ExecUuid)
}
processor.Result.Summary = scriptBase.ResultStatus.String()
processor.AddResultToParent()
result := false
if scriptBase.ResultStatus == consts.Pass {
result = true
}
detail := map[string]interface{}{"name": entity.Name, "content": entity.Content, "result": result, "output": scriptBase.Output}
processor.Result.Detail = commonUtils.JsonEncode(detail)
execUtils.SendExecMsg(*processor.Result, consts.Processor, session.WsMsg)
stat := CountScriptAssertionStat(session.ExecUuid, scriptBase.Output, processor.Result)
execUtils.SendStatMsg(stat, session.WsMsg)
endTime := time.Now()
processor.Result.EndTime = &endTime
return
}