本文整理汇总了Golang中github.com/evergreen-ci/evergreen/plugin.PluginCommunicator.TaskPostTestLog方法的典型用法代码示例。如果您正苦于以下问题:Golang PluginCommunicator.TaskPostTestLog方法的具体用法?Golang PluginCommunicator.TaskPostTestLog怎么用?Golang PluginCommunicator.TaskPostTestLog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/evergreen-ci/evergreen/plugin.PluginCommunicator
的用法示例。
在下文中一共展示了PluginCommunicator.TaskPostTestLog方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SendJSONLogs
// SendJSONLogs is responsible for sending the specified logs
// to the API Server. If successful, it returns a log ID that can be used
// to refer to the log object in test results.
func SendJSONLogs(taskConfig *model.TaskConfig, pluginLogger plugin.Logger,
pluginCom plugin.PluginCommunicator, logs *model.TestLog) (string, error) {
pluginLogger.LogExecution(slogger.INFO, "Attaching test logs for %v", logs.Name)
logId, err := pluginCom.TaskPostTestLog(logs)
if err != nil {
return "", err
}
pluginLogger.LogTask(slogger.INFO, "Attach test logs succeeded")
return logId, nil
}
示例2: SendJSONResults
// SendJSONResults is responsible for sending the
// specified file to the API Server
func SendJSONResults(taskConfig *model.TaskConfig,
pluginLogger plugin.Logger, pluginCom plugin.PluginCommunicator,
results *task.TestResults) error {
for i, res := range results.Results {
if res.LogRaw != "" {
pluginLogger.LogExecution(slogger.INFO, "Attaching raw test logs")
testLogs := &model.TestLog{
Name: res.TestFile,
Task: taskConfig.Task.Id,
TaskExecution: taskConfig.Task.Execution,
Lines: []string{res.LogRaw},
}
id, err := pluginCom.TaskPostTestLog(testLogs)
if err != nil {
pluginLogger.LogExecution(slogger.ERROR, "Error posting raw logs from results: %v", err)
} else {
results.Results[i].LogId = id
}
// clear the logs from the TestResult struct after it has been saved in the test logs. Since they are
// being saved in the test_logs collection, we can clear them to prevent them from being saved in the task
// collection.
results.Results[i].LogRaw = ""
}
}
pluginLogger.LogExecution(slogger.INFO, "Attaching test results")
err := pluginCom.TaskPostResults(results)
if err != nil {
return err
}
pluginLogger.LogTask(slogger.INFO, "Attach test results succeeded")
return nil
}
示例3: Execute
// Execute parses the specified output files and sends the test results found in them
// back to the server.
func (pfCmd *ParseFilesCommand) Execute(pluginLogger plugin.Logger,
pluginCom plugin.PluginCommunicator, taskConfig *model.TaskConfig,
stop chan bool) error {
if err := plugin.ExpandValues(pfCmd, taskConfig.Expansions); err != nil {
msg := fmt.Sprintf("error expanding params: %v", err)
pluginLogger.LogTask(slogger.ERROR, "Error parsing gotest files: %v", msg)
return fmt.Errorf(msg)
}
// make sure the file patterns are relative to the task's working directory
for idx, file := range pfCmd.Files {
pfCmd.Files[idx] = filepath.Join(taskConfig.WorkDir, file)
}
// will be all files containing test results
outputFiles, err := pfCmd.AllOutputFiles()
if err != nil {
return fmt.Errorf("error obtaining names of output files: %v", err)
}
// make sure we're parsing something
if len(outputFiles) == 0 {
return fmt.Errorf("no files found to be parsed")
}
// parse all of the files
logs, results, err := ParseTestOutputFiles(outputFiles, stop, pluginLogger, taskConfig)
if err != nil {
return fmt.Errorf("error parsing output results: %v", err)
}
// ship all of the test logs off to the server
pluginLogger.LogTask(slogger.INFO, "Sending test logs to server...")
allResults := []TestResult{}
for idx, log := range logs {
logId := ""
if logId, err = pluginCom.TaskPostTestLog(&log); err != nil {
// continue on error to let the other logs be posted
pluginLogger.LogTask(slogger.ERROR, "Error posting log: %v", err)
}
// add all of the test results that correspond to that log to the
// full list of results
for _, result := range results[idx] {
result.LogId = logId
allResults = append(allResults, result)
}
}
pluginLogger.LogTask(slogger.INFO, "Finished posting logs to server")
// convert everything
resultsAsModel := ToModelTestResults(taskConfig.Task, allResults)
// ship the parsed results off to the server
pluginLogger.LogTask(slogger.INFO, "Sending parsed results to server...")
if err := pluginCom.TaskPostResults(&resultsAsModel); err != nil {
return fmt.Errorf("error posting parsed results to server: %v", err)
}
pluginLogger.LogTask(slogger.INFO, "Successfully sent parsed results to server")
return nil
}
示例4: Execute
func (self *RunTestCommand) Execute(pluginLogger plugin.Logger,
pluginCom plugin.PluginCommunicator, taskConfig *model.TaskConfig,
stop chan bool) error {
if err := plugin.ExpandValues(self, taskConfig.Expansions); err != nil {
msg := fmt.Sprintf("error expanding params: %v", err)
pluginLogger.LogTask(slogger.ERROR, "Error updating test configs: %v",
msg)
return fmt.Errorf(msg)
}
// define proper working directory
if self.WorkDir != "" {
self.WorkDir = filepath.Join(taskConfig.WorkDir, self.WorkDir)
} else {
self.WorkDir = taskConfig.WorkDir
}
pluginLogger.LogTask(slogger.INFO,
"Running tests with working dir '%v'", self.WorkDir)
if os.Getenv("GOPATH") == "" {
pluginLogger.LogTask(slogger.WARN, "No GOPATH; setting GOPATH to working dir")
err := os.Setenv("GOPATH", self.WorkDir)
if err != nil {
return err
}
}
var results []TestResult
allPassed := true
// run all tests, concat results. Hold onto failures until the end
for idx, test := range self.Tests {
// kill the execution if API server requests
select {
case <-stop:
return fmt.Errorf("command was stopped")
default:
// no stop signal
}
// update test directory
test.Dir = filepath.Join(self.WorkDir, test.Dir)
suiteName := getSuiteNameFromDir(idx, test.Dir)
parser := &VanillaParser{Suite: suiteName}
pluginLogger.LogTask(
slogger.INFO, "Running go test with '%v' in '%v'", test.Args, test.Dir)
if len(test.EnvironmentVariables) > 0 {
pluginLogger.LogTask(
slogger.INFO, "Adding environment variables to gotest: %#v",
test.EnvironmentVariables)
}
passed, err := RunAndParseTests(test, parser, pluginLogger, stop)
logLines := parser.Logs()
for _, log := range logLines {
pluginLogger.LogTask(slogger.INFO, ">>> %v", log)
}
pluginLogger.LogTask(slogger.INFO,
"Sending logs to API server (%v lines)", len(logLines))
testLog := &model.TestLog{
Name: suiteName,
Task: taskConfig.Task.Id,
TaskExecution: taskConfig.Task.Execution,
Lines: logLines,
}
logId, err := pluginCom.TaskPostTestLog(testLog)
if err != nil {
pluginLogger.LogTask(slogger.ERROR, "error posting test log: %v", err)
}
if passed != true {
allPassed = false
pluginLogger.LogTask(slogger.WARN, "Test suite failed, continuing...")
}
if err != nil {
pluginLogger.LogTask(slogger.ERROR,
"Error running and parsing test '%v': %v", test.Dir, err)
continue
}
// get the results of this individual test, and set the log id
// appropriately
testResults := parser.Results()
for _, result := range testResults {
result.LogId = logId
results = append(results, result)
}
}
pluginLogger.LogTask(slogger.INFO, "Sending go test results to server")
modelResults := ToModelTestResults(taskConfig.Task, results)
err := pluginCom.TaskPostResults(&modelResults)
if err != nil {
return fmt.Errorf("error posting results: %v", err)
}
//.........这里部分代码省略.........