Ejemplo n.º 1
0
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/\"")
}
Ejemplo n.º 2
0
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)
}
Ejemplo n.º 3
0
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 := &parallelInfo{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)
}
Ejemplo n.º 4
0
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)))
	}
}
Ejemplo n.º 5
0
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
}
Ejemplo n.º 6
0
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()
}
Ejemplo n.º 7
0
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
}
Ejemplo n.º 8
0
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)
	}
}
Ejemplo n.º 9
0
// 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
}