Beispiel #1
0
func InstallAllPlugins() {
	manifest, err := manifest.ProjectManifest()
	if err != nil {

		logger.Critical(fmt.Sprintf("manifest.json not found : --install-all requires manifest.json in working directory."))
	}
	installPluginsFromManifest(manifest)
}
Beispiel #2
0
// SetWorkingDir sets the current working directory to specified location
func SetWorkingDir(workingDir string) {
	targetDir, err := filepath.Abs(workingDir)
	if err != nil {
		logger.Critical("Unable to set working directory : %s\n", err.Error())
	}
	if !common.DirExists(targetDir) {
		err = os.Mkdir(targetDir, 0777)
		if err != nil {
			logger.Critical("Unable to set working directory : %s\n", err.Error())
		}
	}
	err = os.Chdir(targetDir)
	_, err = os.Getwd()
	if err != nil {
		logger.Critical("Unable to set working directory : %s\n", err.Error())
	}
}
Beispiel #3
0
func validateTagExpression(tagExpression string) {
	filter := &ScenarioFilterBasedOnTags{tagExpression: tagExpression}
	filter.replaceSpecialChar()
	_, err := filter.formatAndEvaluateExpression(make(map[string]bool, 0), func(a map[string]bool, b string) bool { return true })
	if err != nil {
		logger.Critical(err.Error())
		os.Exit(1)
	}
}
Beispiel #4
0
func getDataTableRows(rowCount int) indexRange {
	if TableRows == "" {
		return indexRange{start: 0, end: rowCount - 1}
	}
	indexes, err := getDataTableRowsRange(TableRows, rowCount)
	if err != nil {
		logger.Critical("Table rows validation failed. %s\n", err.Error())
	}
	return indexes
}
Beispiel #5
0
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.Critical(errMsg)
			return errorResult(errMsg)
		}
		return executionResult
	} else {
		errMsg := fmt.Sprintf("Expected ExecutionStatusResponse. Obtained: %s", response.GetMessageType())
		logger.Critical(errMsg)
		return errorResult(errMsg)
	}
}
Beispiel #6
0
// Loading default environment and loading user specified env
// this way user specified env variable can override default if required
func LoadEnv(shouldSkip bool) {
	err := loadEnvironment(envDefaultDirName)
	if err != nil {
		if !shouldSkip {
			logger.Critical("Failed to load the default environment. %s\n", err.Error())
			os.Exit(1)
		}
	}

	if ProjectEnv != envDefaultDirName {
		err := loadEnvironment(ProjectEnv)
		if err != nil {
			if !shouldSkip {
				logger.Critical("Failed to load the environment: %s. %s\n", ProjectEnv, err.Error())
				os.Exit(1)
			}
		}
		CurrentEnv = ProjectEnv
	}

}
Beispiel #7
0
// InitializeProject initializes a Gauge project with specified template
func InitializeProject(templateName string) {
	wd, err := os.Getwd()
	if err != nil {
		logger.Critical("Failed to find working directory. %s\n", err.Error())
	}
	config.ProjectRoot = wd

	exists, _ := common.UrlExists(getTemplateURL(templateName))

	if exists {
		err = initializeTemplate(templateName)
	} else {
		err = createProjectTemplate(templateName)
	}

	if err != nil {
		logger.Critical("Failed to initialize. %s\n", err.Error())
		return
	}
	logger.Info("\nSuccessfully initialized the project. Run specifications with \"gauge specs/\"")
}
Beispiel #8
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:
		logger.Critical("Failed to start gauge API: %s", err.Error())
		os.Exit(1)
	}
	return nil
}
Beispiel #9
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 {
		logger.Critical(err.Error())
	}
	if err := addPluginToTheProject(pluginName, additionalArgs, manifest); err != nil {
		logger.Critical(fmt.Sprintf("Failed to add plugin %s to project : %s\n", pluginName, err.Error()))
	} else {
		logger.Info("Plugin %s was successfully added to the project\n", pluginName)
	}
}
Beispiel #10
0
func CheckSpecs(args []string) {
	env.LoadEnv(false)
	specsToExecute, conceptsDictionary := parseSpecs(args)
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		logger.Critical(err.Error())
	}
	runner := startApi()
	errMap := validateSpecs(manifest, specsToExecute, runner, conceptsDictionary)
	runner.Kill()
	if len(errMap.stepErrs) > 0 {
		os.Exit(1)
	}
	logger.Info("No error found.")
	os.Exit(0)
}
Beispiel #11
0
func HandleParseResult(results ...*ParseResult) {
	var failed = false
	for _, result := range results {
		if !result.Ok {
			logger.Critical(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)
	}
}
Beispiel #12
0
func ExecuteSpecs(inParallel bool, args []string) int {
	i := &install.UpdateFacade{}
	i.BufferUpdateDetails()
	env.LoadEnv(false)
	specsToExecute, conceptsDictionary := parseSpecs(args)
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		logger.Critical(err.Error())
	}
	runner := startApi()
	errMap := validateSpecs(manifest, specsToExecute, runner, conceptsDictionary)
	pluginHandler := plugin.StartPlugins(manifest)
	parallelInfo := &parallelInfo{inParallel: inParallel, numberOfStreams: NumberOfExecutionStreams}
	if !parallelInfo.isValid() {
		os.Exit(1)
	}
	execution := newExecution(&executionInfo{manifest, specsToExecute, runner, pluginHandler, parallelInfo, logger.Current(), errMap})
	result := execution.start()
	execution.finish()
	exitCode := printExecutionStatus(result, errMap)
	i.PrintUpdateBuffer()
	return exitCode
}