// UninstallPlugin uninstall the given plugin of the given version // If version is not specified, it uninstalls all the versions of given plugin func UninstallPlugin(pluginName string, version string) { pluginsHome, err := common.GetPrimaryPluginsInstallDir() if err != nil { logger.Fatalf("Failed to uninstall plugin %s. %s", pluginName, err.Error()) } if !common.DirExists(filepath.Join(pluginsHome, pluginName, version)) { logger.Errorf("Plugin %s not found.", strings.TrimSpace(pluginName+" "+version)) os.Exit(0) } var failed bool pluginsDir := filepath.Join(pluginsHome, pluginName) filepath.Walk(pluginsDir, func(dir string, info os.FileInfo, err error) error { if err == nil && info.IsDir() && dir != pluginsDir && strings.HasPrefix(filepath.Base(dir), version) { if err := uninstallVersionOfPlugin(dir, pluginName, filepath.Base(dir)); err != nil { logger.Errorf("Failed to uninstall plugin %s %s. %s", pluginName, version, err.Error()) failed = true } } return nil }) if failed { os.Exit(1) } if version == "" { if err := os.RemoveAll(pluginsDir); err != nil { logger.Fatalf("Failed to remove directory %s. %s", pluginsDir, err.Error()) } } }
func printValidationFailures(validationErrors validationErrors) { logger.Errorf("Validation failed. The following steps have errors") for _, errs := range validationErrors { for _, e := range errs { logger.Errorf(e.Error()) } } }
func (handler *Handler) killPlugin(pluginID string) { plugin := handler.pluginsMap[pluginID] logger.Debug("Killing Plugin %s %s\n", plugin.descriptor.Name, plugin.descriptor.Version) err := plugin.pluginCmd.Process.Kill() if err != nil { logger.Errorf("Failed to kill plugin %s %s. %s\n", plugin.descriptor.Name, plugin.descriptor.Version, err.Error()) } handler.removePlugin(pluginID) }
func (handler *Handler) NotifyPlugins(message *gauge_messages.Message) { for id, plugin := range handler.pluginsMap { err := plugin.sendMessage(message) if err != nil { logger.Errorf("Unable to connect to plugin %s %s. %s\n", plugin.descriptor.Name, plugin.descriptor.Version, err.Error()) handler.killPlugin(id) } } }
func executeAndGetStatus(runner *runner.TestRunner, message *gauge_messages.Message) *gauge_messages.ProtoExecutionResult { response, err := conn.GetResponseForGaugeMessage(message, runner.Connection) if err != nil { return &gauge_messages.ProtoExecutionResult{Failed: proto.Bool(true), ErrorMessage: proto.String(err.Error())} } if response.GetMessageType() == gauge_messages.Message_ExecutionStatusResponse { executionResult := response.GetExecutionStatusResponse().GetExecutionResult() if executionResult == nil { errMsg := "ProtoExecutionResult obtained is nil" logger.Errorf(errMsg) return errorResult(errMsg) } return executionResult } errMsg := fmt.Sprintf("Expected ExecutionStatusResponse. Obtained: %s", response.GetMessageType()) logger.Errorf(errMsg) return errorResult(errMsg) }
func (e *specExecutor) skipSpecForError(err error) { logger.Errorf(err.Error()) validationError := validation.NewValidationError(&gauge.Step{LineNo: e.specification.Heading.LineNo, LineText: e.specification.Heading.Value}, err.Error(), e.specification.FileName, nil) for _, scenario := range e.specification.Scenarios { e.errMap.ScenarioErrs[scenario] = []*validation.StepValidationError{validationError} } e.errMap.SpecErrs[e.specification] = []*validation.StepValidationError{validationError} e.skipSpec() }
func getDataTableRows(rowCount int) indexRange { if TableRows == "" { return indexRange{start: 0, end: rowCount - 1} } indexes, err := getDataTableRowsRange(TableRows, rowCount) if err != nil { logger.Errorf("Table rows validation failed. %s\n", err.Error()) } return indexes }
func (e *parallelExecution) startStream(s *gauge.SpecCollection, reporter reporter.Reporter, resChan chan *result.SuiteResult) { defer e.wg.Done() runner, err := runner.StartRunnerAndMakeConnection(e.manifest, reporter, make(chan bool)) if err != nil { logger.Errorf("Failed to start runner. %s", err.Error()) resChan <- &result.SuiteResult{UnhandledErrors: []error{fmt.Errorf("Failed to start runner. %s", err.Error())}} return } e.startSpecsExecutionWithRunner(s, resChan, runner, reporter) }
func (e *parallelExecution) startSpecsExecution(s *gauge.SpecCollection, reporter reporter.Reporter, resChan chan *result.SuiteResult) { defer e.wg.Done() runner, err := runner.StartRunnerAndMakeConnection(e.manifest, reporter, make(chan bool)) if err != nil { logger.Errorf("Failed to start runner. %s", err.Error()) logger.Debug("Skipping %d specifications", s.Size()) resChan <- &result.SuiteResult{UnhandledErrors: []error{streamExecError{specsSkipped: s.SpecNames(), message: fmt.Sprintf("Failed to start runner. %s", err.Error())}}} return } e.startSpecsExecutionWithRunner(s, resChan, runner, reporter) }
func printRefactoringSummary(refactoringResult *refactoringResult) { exitCode := 0 if !refactoringResult.Success { exitCode = 1 for _, err := range refactoringResult.Errors { logger.Errorf("%s \n", err) } } for _, warning := range refactoringResult.warnings { logger.Warning("%s \n", warning) } logger.Info("%d specifications changed.\n", len(refactoringResult.specsChanged)) logger.Info("%d concepts changed.\n", len(refactoringResult.conceptsChanged)) logger.Info("%d files in code changed.\n", len(refactoringResult.runnerFilesChanged)) os.Exit(exitCode) }
// HandleUpdateResult handles the result of plugin Installation func HandleUpdateResult(result InstallResult, pluginName string, exitIfFailure bool) bool { if result.Warning != "" { logger.Warning(result.Warning) } if result.Skipped { return true } if !result.Success { logger.Errorf("Failed to update plugin '%s'.\nReason: %s", pluginName, result.getMessage()) if exitIfFailure { os.Exit(1) } return false } logger.Info("Successfully updated plugin '%s'.", pluginName) return true }
func HandleParseResult(results ...*ParseResult) { var failed = false for _, result := range results { if !result.Ok { logger.Errorf(result.Error()) failed = true } if result.Warnings != nil { for _, warning := range result.Warnings { logger.Warning("%s : %v", result.FileName, warning) } } } if failed { os.Exit(1) } }
func addPluginToTheProject(pluginName string, pluginArgs map[string]string, manifest *manifest.Manifest) error { if !plugin.IsPluginInstalled(pluginName, pluginArgs["version"]) { logger.Info("Plugin %s %s is not installed. Downloading the plugin.... \n", pluginName, pluginArgs["version"]) result := InstallPlugin(pluginName, pluginArgs["version"]) if !result.Success { logger.Errorf(result.getMessage()) } } pd, err := plugin.GetPluginDescriptor(pluginName, pluginArgs["version"]) if err != nil { return err } if plugin.IsPluginAdded(manifest, pd) { return fmt.Errorf("Plugin %s is already added.", pd.Name) } manifest.Plugins = append(manifest.Plugins, pd.ID) return manifest.Save() }
func printExecutionStatus(suiteResult *result.SuiteResult, errMap *validation.ValidationErrMaps) int { nSkippedScenarios := len(errMap.ScenarioErrs) nSkippedSpecs := len(errMap.SpecErrs) nExecutedSpecs := len(suiteResult.SpecResults) - nSkippedSpecs nFailedSpecs := suiteResult.SpecsFailedCount nPassedSpecs := nExecutedSpecs - nFailedSpecs nExecutedScenarios := 0 nFailedScenarios := 0 nPassedScenarios := 0 for _, specResult := range suiteResult.SpecResults { nExecutedScenarios += specResult.ScenarioCount nFailedScenarios += specResult.ScenarioFailedCount } nExecutedScenarios -= nSkippedScenarios nPassedScenarios = nExecutedScenarios - nFailedScenarios if nExecutedScenarios < 0 { nExecutedScenarios = 0 } if nPassedScenarios < 0 { nPassedScenarios = 0 } logger.Info("Specifications:\t%d executed\t%d passed\t%d failed\t%d skipped", nExecutedSpecs, nPassedSpecs, nFailedSpecs, nSkippedSpecs) logger.Info("Scenarios:\t%d executed\t%d passed\t%d failed\t%d skipped", nExecutedScenarios, nPassedScenarios, nFailedScenarios, nSkippedScenarios) logger.Info("\nTotal time taken: %s", time.Millisecond*time.Duration(suiteResult.ExecutionTime)) for _, unhandledErr := range suiteResult.UnhandledErrors { logger.Errorf(unhandledErr.Error()) } exitCode := 0 if suiteResult.IsFailed || (nSkippedSpecs+nSkippedScenarios) > 0 { exitCode = 1 } return exitCode }
// SaveFile saves contents at the given path func SaveFile(fileName string, content string, backup bool) { err := common.SaveFile(fileName, content, backup) if err != nil { logger.Errorf("Failed to refactor '%s': %s\n", fileName, err.Error()) } }