Exemple #1
0
func ExecuteSpecs(inParallel bool, args []string) int {
	if checkUpdatesDuringExecution && config.CheckUpdates() {
		i := &install.UpdateFacade{}
		i.BufferUpdateDetails()
		defer i.PrintUpdateBuffer()
	}

	env.LoadEnv(false)
	specsToExecute, conceptsDictionary := parseSpecs(args)
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		logger.Fatal(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, reporter.Current(), errMap})
	result := execution.start()
	execution.finish()
	exitCode := printExecutionStatus(result, errMap)
	return exitCode
}
Exemple #2
0
func InstallAllPlugins() {
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		logger.Fatal(err.Error())
	}
	installPluginsFromManifest(manifest)
}
Exemple #3
0
func InstallPluginZip(zipFile string, pluginName string) {
	if err := installPluginFromZip(zipFile, pluginName); err != nil {
		logger.Fatal("Failed to install plugin. %s\n", err.Error())
	} else {
		logger.Info("Successfully installed plugin from file.")
	}
}
Exemple #4
0
func DownloadAndInstallPlugin(plugin, version, messageFormat string) {
	err := downloadAndInstall(plugin, version, fmt.Sprintf(messageFormat, plugin))
	if err != nil {
		logger.Fatal(err.Error())
	}
	os.Exit(0)
}
Exemple #5
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.Fatal(err.Error())
	}
}
Exemple #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.Fatal("Failed to load the default environment. %s\n", err.Error())
		}
	}

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

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

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

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

	if err != nil {
		logger.Fatal("Failed to initialize. %s", err.Error())
	}
	logger.Info("\nSuccessfully initialized the project. Run specifications with \"gauge specs/\"")
}
Exemple #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.Fatal("Failed to start gauge API: %s", err.Error())
	}
	return nil
}
Exemple #9
0
func runAPIServiceIndefinitely(port int, wg *sync.WaitGroup) {
	wg.Add(1)
	startChan := &runner.StartChannels{RunnerChan: make(chan *runner.TestRunner), ErrorChan: make(chan error), KillChan: make(chan bool)}
	go StartAPIService(port, startChan)
	select {
	case runner := <-startChan.RunnerChan:
		runner.Kill()
	case err := <-startChan.ErrorChan:
		logger.Fatal(err.Error())
	}
}
Exemple #10
0
func RunInBackground(apiPort string) {
	var port int
	var err error
	if apiPort != "" {
		port, err = strconv.Atoi(apiPort)
		if err != nil {
			logger.Fatal(fmt.Sprintf("Invalid port number: %s", apiPort))
		}
		os.Setenv(common.APIPortEnvVariableName, apiPort)
	} else {
		env.LoadEnv(false)
		port, err = conn.GetPortFromEnvironmentVariable(common.APIPortEnvVariableName)
		if err != nil {
			logger.Fatal(fmt.Sprintf("Failed to start API Service. %s \n", err.Error()))
		}
	}
	var wg sync.WaitGroup
	runAPIServiceIndefinitely(port, &wg)
	wg.Wait()
}
Exemple #11
0
func InstallPluginZip(zipFile string, pluginName string) {
	tempDir := common.GetTempDir()
	unzippedPluginDir, err := common.UnzipArchive(zipFile, tempDir)
	defer common.Remove(tempDir)
	if err != nil {
		common.Remove(tempDir)
		logger.Fatal("Failed to install plugin. %s\n", err.Error())
	}
	logger.Info("Plugin unzipped to => %s\n", unzippedPluginDir)

	hasPluginJSON := common.FileExists(filepath.Join(unzippedPluginDir, pluginJSON))
	if hasPluginJSON {
		err = installPluginFromDir(unzippedPluginDir)
	} else {
		err = installRunnerFromDir(unzippedPluginDir, pluginName)
	}
	if err != nil {
		common.Remove(tempDir)
		logger.Fatal("Failed to install plugin. %s\n", err.Error())
	}
	logger.Info("Successfully installed plugin from file.")
}
Exemple #12
0
// SetWorkingDir sets the current working directory to specified location
func SetWorkingDir(workingDir string) {
	targetDir, err := filepath.Abs(workingDir)
	if err != nil {
		logger.Fatal("Unable to set working directory : %s", err.Error())
	}

	if !common.DirExists(targetDir) {
		err = os.Mkdir(targetDir, 0777)
		if err != nil {
			logger.Fatal("Unable to set working directory : %s", err.Error())
		}
	}

	err = os.Chdir(targetDir)
	if err != nil {
		logger.Fatal("Unable to set working directory : %s", err.Error())
	}

	_, err = os.Getwd()
	if err != nil {
		logger.Fatal("Unable to set working directory : %s", err.Error())
	}
}
Exemple #13
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.Fatal(err.Error())
	}
	if err := addPluginToTheProject(pluginName, additionalArgs, manifest); err != nil {
		logger.Fatal(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)
	}
}
Exemple #14
0
func ParseAndValidateSpecs(args []string) {
	env.LoadEnv(false)
	specsToExecute, conceptsDictionary := parseSpecs(args)
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		logger.Fatal(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)
}
Exemple #15
0
func handleUninstallFailure(err error, pluginName string) {
	logger.Error("%s plugin uninstallation failed", pluginName)
	logger.Fatal(err.Error())
}