func InitializeProject(language string) { wd, err := os.Getwd() if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Failed to find working directory. %s\n", err.Error()))) } config.ProjectRoot = wd err = createProjectTemplate(language) if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Failed to initialize. %s\n", err.Error()))) } logger.Log.Info("\nSuccessfully initialized the project. Run specifications with \"gauge specs/\"") }
func InstallAllPlugins() { manifest, err := manifest.ProjectManifest() if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("manifest.json not found : --install-all requires manifest.json in working directory."))) } installPluginsFromManifest(manifest) }
func ExecuteSpecs(inParallel bool, args []string) { env.LoadEnv(false) conceptsDictionary, conceptParseResult := parser.CreateConceptsDictionary(false) parser.HandleParseResult(conceptParseResult) specsToExecute, specsSkipped := filter.GetSpecsToExecute(conceptsDictionary, args) if len(specsToExecute) == 0 { printExecutionStatus(nil, 0) } parallelInfo := ¶llelInfo{inParallel: inParallel, numberOfStreams: NumberOfExecutionStreams} if !parallelInfo.isValid() { os.Exit(1) } manifest, err := manifest.ProjectManifest() if err != nil { execLogger.CriticalError(err) } runner := startApi() validateSpecs(manifest, specsToExecute, runner, conceptsDictionary) pluginHandler := plugin.StartPlugins(manifest) execution := newExecution(manifest, specsToExecute, runner, pluginHandler, parallelInfo, execLogger.Current()) result := execution.start() execution.finish() exitCode := printExecutionStatus(result, specsSkipped) os.Exit(exitCode) }
func SetWorkingDir(workingDir string) { targetDir, err := filepath.Abs(workingDir) if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Unable to set working directory : %s\n", err))) } if !common.DirExists(targetDir) { err = os.Mkdir(targetDir, 0777) if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Unable to set working directory : %s\n", err))) } } err = os.Chdir(targetDir) _, err = os.Getwd() if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Unable to set working directory : %s\n", err))) } }
func getDataTableRows(rowCount int) indexRange { if TableRows == "" { return indexRange{start: 0, end: rowCount - 1} } indexes, err := getDataTableRowsRange(TableRows, rowCount) if err != nil { execLogger.CriticalError(fmt.Errorf("Table rows validation failed. %s\n", err.Error())) } return indexes }
func RunInBackground(apiPort string) { var port int var err error if apiPort != "" { port, err = strconv.Atoi(apiPort) os.Setenv(common.ApiPortEnvVariableName, apiPort) if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Failed to parse the port number :", apiPort, "\n", err.Error()))) } } else { env.LoadEnv(false) port, err = conn.GetPortFromEnvironmentVariable(common.ApiPortEnvVariableName) if err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Failed to start API Service. %s \n", err.Error()))) } } var wg sync.WaitGroup runAPIServiceIndefinitely(port, &wg) wg.Wait() }
func startApi() *runner.TestRunner { startChan := &runner.StartChannels{RunnerChan: make(chan *runner.TestRunner), ErrorChan: make(chan error), KillChan: make(chan bool)} go api.StartAPIService(0, startChan) select { case runner := <-startChan.RunnerChan: return runner case err := <-startChan.ErrorChan: execLogger.CriticalError(errors.New(fmt.Sprintf("Failed to start gauge API. %s\n", err.Error()))) } return nil }
func AddPluginToProject(pluginName string, pluginArgs string) { additionalArgs := make(map[string]string) if pluginArgs != "" { // plugin args will be comma separated values // eg: version=1.0, foo_version = 2.41 args := strings.Split(pluginArgs, ",") for _, arg := range args { keyValuePair := strings.Split(arg, "=") if len(keyValuePair) == 2 { additionalArgs[strings.TrimSpace(keyValuePair[0])] = strings.TrimSpace(keyValuePair[1]) } } } manifest, err := manifest.ProjectManifest() if err != nil { execLogger.CriticalError(err) } if err := addPluginToTheProject(pluginName, additionalArgs, manifest); err != nil { execLogger.CriticalError(errors.New(fmt.Sprintf("Failed to add plugin %s to project : %s\n", pluginName, err.Error()))) } else { logger.Log.Info("Plugin %s was successfully added to the project\n", pluginName) } }
// Gets all steps list from the runner func (specInfoGatherer *SpecInfoGatherer) getStepsFromRunner(killChannel chan bool) (*runner.TestRunner, error) { steps := make([]string, 0) manifest, err := manifest.ProjectManifest() if err != nil { execLogger.CriticalError(err) } testRunner, connErr := runner.StartRunnerAndMakeConnection(manifest, &logger.Log, killChannel) if connErr == nil { steps = append(steps, requestForSteps(testRunner)...) logger.ApiLog.Debug("Steps got from runner: %v", steps) } else { logger.ApiLog.Error("Runner connection failed: %s", connErr) } specInfoGatherer.runnerStepValues = specInfoGatherer.convertToStepValues(steps) return testRunner, connErr }