Exemplo n.º 1
0
// 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
}
Exemplo n.º 2
0
// 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
}
Exemplo n.º 3
0
// 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

}
Exemplo n.º 4
0
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)
	}

	if allPassed {
		return nil
	} else {
		return fmt.Errorf("test failures")
	}
}