示例#1
0
func printExecutionStatus(suiteResult *result.SuiteResult, errMap *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

	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.Error(unhandledErr.Error())
	}
	exitCode := 0
	if suiteResult.IsFailed || (nSkippedSpecs+nSkippedScenarios) > 0 {
		exitCode = 1
	}
	return exitCode
}
示例#2
0
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.Error(result.getMessage())
		}
	}
	pd, err := plugin.GetPluginDescriptor(pluginName, pluginArgs["version"])
	if err != nil {
		return err
	}
	if plugin.IsPluginAdded(manifest, pd) {
		logger.Info("Plugin " + pd.Name + " is already added.")
		return nil
	}

	action := setupScope
	if err := plugin.SetEnvForPlugin(action, pd, manifest, pluginArgs); err != nil {
		return err
	}
	if _, err := plugin.StartPlugin(pd, action, true); err != nil {
		return err
	}
	manifest.Plugins = append(manifest.Plugins, pd.Id)
	return manifest.Save()
}
示例#3
0
文件: init.go 项目: mattdotmatt/gauge
// InitializeProject initializes a Gauge project with specified template
func InitializeProject(templateName string) {
	wd, err := os.Getwd()
	if err != nil {
		logger.Fatalf("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.Fatalf("Failed to initialize project. %s", err.Error())
	}
	logger.Info("Successfully initialized the project. Run specifications with \"gauge specs/\"\n")

	language := getTemplateLangauge(templateName)
	if !install.IsCompatiblePluginInstalled(language, true) {
		logger.Info("Compatible langauge plugin %s is not installed. Installing plugin...", language)

		install.HandleInstallResult(install.InstallPlugin(language, ""), language, true)
	}
}
示例#4
0
文件: init.go 项目: mattdotmatt/gauge
// ListTemplates lists all the Gauge templates available in GaugeTemplatesURL
func ListTemplates() {
	templatesURL := config.GaugeTemplatesUrl()
	_, err := common.UrlExists(templatesURL)
	if err != nil {
		logger.Fatalf("Gauge templates URL is not reachable: %s", err.Error())
	}
	tempDir := common.GetTempDir()
	defer util.Remove(tempDir)
	templatesPage, err := util.Download(templatesURL, tempDir, "", true)
	if err != nil {
		util.Remove(tempDir)
		logger.Fatalf("Error occurred while downloading templates list: %s", err.Error())
	}

	templatePageContents, err := common.ReadFileContents(templatesPage)
	if err != nil {
		util.Remove(tempDir)
		logger.Fatalf("Failed to read contents of file %s: %s", templatesPage, err.Error())
	}
	templates := getTemplateNames(templatePageContents)
	for _, template := range templates {
		logger.Info(template)
	}
	logger.Info("\nRun `gauge --init <template_name>` to create a new Gauge project.")
}
示例#5
0
func GetPluginsInfo() []PluginInfo {
	allPluginsWithVersion, err := GetAllInstalledPluginsWithVersion()
	if err != nil {
		logger.Info("No plugins found")
		logger.Info("Plugins can be installed with `gauge --install {plugin-name}`")
		os.Exit(0)
	}
	return allPluginsWithVersion
}
示例#6
0
func PrintUpdateInfoWithDetails() {
	updates := checkUpdates()
	if len(updates) > 0 {
		for _, update := range updates {
			logger.Info(fmt.Sprintf("%-10s\t\t%-10s\t%s", update.Name, update.CompatibleVersion, update.Message))
		}
	} else {
		logger.Info("No Updates available.")
	}
}
示例#7
0
// UpdatePlugins updates all the currently installed plugins to its latest version
func UpdatePlugins() {
	var failedPlugin []string
	for _, pluginInfo := range plugin.GetPluginsInfo() {
		logger.Info("Updating plugin '%s'", pluginInfo.Name)
		passed := HandleUpdateResult(InstallPlugin(pluginInfo.Name, ""), pluginInfo.Name, false)
		if !passed {
			failedPlugin = append(failedPlugin, pluginInfo.Name)
		}
		fmt.Println()
	}
	if len(failedPlugin) > 0 {
		logger.Fatalf("Failed to update '%s' plugins.", strings.Join(failedPlugin, ", "))
	}
	logger.Info("Successfully updated all the plugins.")
}
示例#8
0
func InstallPluginZip(zipFile string, pluginName string) {
	if err := installPluginFromZip(zipFile, pluginName); err != nil {
		logger.Warning("Failed to install plugin. Invalid zip file : %s\n", err)
	} else {
		logger.Info("Successfully installed plugin from file.")
	}
}
示例#9
0
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)
}
示例#10
0
func installPluginsFromManifest(manifest *manifest.Manifest) {
	pluginsMap := make(map[string]bool, 0)
	pluginsMap[manifest.Language] = true
	for _, plugin := range manifest.Plugins {
		pluginsMap[plugin] = false
	}

	for pluginName, isRunner := range pluginsMap {
		if !IsCompatiblePluginInstalled(pluginName, isRunner) {
			logger.Info("Compatible version of plugin %s not found. Installing plugin %s...", pluginName, pluginName)
			HandleInstallResult(InstallPlugin(pluginName, ""), pluginName, true)
		} else {
			logger.Info("Plugin %s is already installed.", pluginName)
		}
	}
}
示例#11
0
文件: install.go 项目: 0-T-0/gauge
func installPluginVersion(installDesc *installDescription, versionInstallDescription *versionInstallDescription) installResult {
	if common.IsPluginInstalled(installDesc.Name, versionInstallDescription.Version) {
		return installSuccess(fmt.Sprintf("Plugin %s %s is already installed.", installDesc.Name, versionInstallDescription.Version))
	}

	logger.Info("Installing Plugin => %s %s\n", installDesc.Name, versionInstallDescription.Version)
	downloadLink, err := getDownloadLink(versionInstallDescription.DownloadUrls)
	if err != nil {
		return installError(fmt.Sprintf("Could not get download link: %s", err.Error()))
	}

	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)
	unzippedPluginDir, err := util.DownloadAndUnzip(downloadLink, tempDir)
	if err != nil {
		return installError(err.Error())
	}

	if err := runInstallCommands(versionInstallDescription.Install, unzippedPluginDir); err != nil {
		return installError(fmt.Sprintf("Failed to Run install command. %s.", err.Error()))
	}
	err = copyPluginFilesToGauge(installDesc, versionInstallDescription, unzippedPluginDir)
	if err != nil {
		installError(err.Error())
	}
	return installSuccess("")
}
示例#12
0
// InstallPluginFromZipFile installs plugin from given zip file
func InstallPluginFromZipFile(zipFile string, pluginName string) InstallResult {
	tempDir := common.GetTempDir()
	defer common.Remove(tempDir)
	unzippedPluginDir, err := common.UnzipArchive(zipFile, tempDir)
	if err != nil {
		return installError(err)
	}

	gp, err := parsePluginJSON(unzippedPluginDir, pluginName)
	if err != nil {
		return installError(err)
	}

	if err = runPlatformCommands(gp.PreInstall, unzippedPluginDir); err != nil {
		return installError(err)
	}

	pluginInstallDir, err := getPluginInstallDir(gp.ID, getVersionedPluginDirName(zipFile))
	if err != nil {
		return installError(err)
	}

	// copy files to gauge plugin install location
	logger.Info("Installing plugin %s %s", gp.ID, filepath.Base(pluginInstallDir))
	if _, err = common.MirrorDir(unzippedPluginDir, pluginInstallDir); err != nil {
		return installError(err)
	}

	if err = runPlatformCommands(gp.PostInstall, pluginInstallDir); err != nil {
		return installError(err)
	}
	return installSuccess("")
}
示例#13
0
文件: install.go 项目: 0-T-0/gauge
func runInstallCommands(installCommands platformSpecificCommand, workingDir string) error {
	command := []string{}
	switch runtime.GOOS {
	case "windows":
		command = installCommands.Windows
		break
	case "darwin":
		command = installCommands.Darwin
		break
	default:
		command = installCommands.Linux
		break
	}

	if len(command) == 0 {
		return nil
	}

	logger.Info("Running plugin install command => %s\n", command)
	cmd, err := common.ExecuteCommand(command, workingDir, os.Stdout, os.Stderr)

	if err != nil {
		return err
	}

	return cmd.Wait()
}
示例#14
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.")
	}
}
示例#15
0
// InstallPlugin download and install the latest plugin(if version not specified) of given plugin name
func InstallPlugin(pluginName, version string) InstallResult {
	logger.Info("Gathering metadata for %s", pluginName)
	installDescription, result := getInstallDescription(pluginName, false)
	defer util.RemoveTempDir()
	if !result.Success {
		return result
	}
	return installPluginWithDescription(installDescription, version)
}
示例#16
0
func Validate(args []string) {
	runner := startAPI()
	_, errMap := ValidateSpecs(args, runner)
	runner.Kill()
	if len(errMap.StepErrs) > 0 {
		os.Exit(1)
	}
	logger.Info("No error found.")
}
示例#17
0
文件: install.go 项目: 0-T-0/gauge
func UpdatePlugins() {
	var failedPlugin []string
	for _, pluginInfo := range plugin.GetPluginsInfo() {
		logger.Info("Updating plugin '%s'", pluginInfo.Name)
		err := downloadAndInstall(pluginInfo.Name, "", fmt.Sprintf("Successfully updated plugin => %s", pluginInfo.Name))
		if err != nil {
			logger.Error(err.Error())
			failedPlugin = append(failedPlugin, pluginInfo.Name)
		}
		fmt.Println()
	}
	if len(failedPlugin) > 0 {
		logger.Error("Failed to update '%s' plugins.", strings.Join(failedPlugin, ", "))
		os.Exit(1)
	}
	logger.Info("Successfully updated all the plugins.")
	os.Exit(0)
}
示例#18
0
func parseSpecs(args []string) ([]*gauge.Specification, *gauge.ConceptDictionary) {
	conceptsDictionary, conceptParseResult := parser.CreateConceptsDictionary(false, args)
	parser.HandleParseResult(conceptParseResult)
	specsToExecute, _ := filter.GetSpecsToExecute(conceptsDictionary, args)
	if len(specsToExecute) == 0 {
		logger.Info("No specifications found in %s.", strings.Join(args, ", "))
		os.Exit(0)
	}
	return specsToExecute, conceptsDictionary
}
示例#19
0
func (groupFilter *specsGroupFilter) filter(specs []*parser.Specification) []*parser.Specification {
	if groupFilter.group == -1 {
		return specs
	}
	logger.Info("Using the -g flag will make the distribution strategy 'eager'. The --strategy setting will be overridden.")
	if groupFilter.group < 1 || groupFilter.group > groupFilter.execStreams {
		return make([]*parser.Specification, 0)
	}
	return DistributeSpecs(sortSpecsList(specs), groupFilter.execStreams)[groupFilter.group-1].Specs
}
示例#20
0
文件: install.go 项目: 0-T-0/gauge
func UninstallPlugin(pluginName string, version string) {
	pluginsDir, err := common.GetPrimaryPluginsInstallDir()
	if err != nil {
		handleUninstallFailure(err, pluginName)
	}
	pluginInfo := pluginName
	if version != "" {
		pluginInfo = fmt.Sprintf("%s(%s)", pluginName, version)
	}
	pluginInstallationDir := path.Join(pluginsDir, pluginName, version)
	if common.DirExists(pluginInstallationDir) {
		if err = os.RemoveAll(pluginInstallationDir); err != nil {
			handleUninstallFailure(err, pluginInfo)
		} else {
			logger.Info("%s plugin uninstalled successfully", pluginInfo)
		}
	} else {
		logger.Info("%s plugin is not installed", pluginInfo)
	}
}
示例#21
0
func waitToPrint(messageChan chan string, printChan chan bool, message string, wg *sync.WaitGroup) {
	select {
	case <-printChan:
		if message != "" {
			logger.Info(message)
		}
		wg.Done()
	case message = <-messageChan:
		waitToPrint(messageChan, printChan, message, wg)
	}
}
示例#22
0
func (e *parallelExecution) run() *result.SuiteResult {
	var suiteResults []*result.SuiteResult
	nStreams := e.getNumberOfStreams()
	logger.Info("Executing in %s parallel streams.", strconv.Itoa(nStreams))
	if isLazy() {
		suiteResults = e.lazyExecution(nStreams)
	} else {
		suiteResults = e.eagerExecution(nStreams)
	}
	e.aggregateResult = e.aggregateResults(suiteResults)
	return e.aggregateResult
}
示例#23
0
文件: install.go 项目: 0-T-0/gauge
func installPluginsFromManifest(manifest *manifest.Manifest) {
	pluginsMap := make(map[string]bool, 0)
	pluginsMap[manifest.Language] = true
	for _, plugin := range manifest.Plugins {
		pluginsMap[plugin] = false
	}

	for pluginName, isRunner := range pluginsMap {
		if !isCompatiblePluginInstalled(pluginName, "", isRunner) {
			logger.Info("Compatible version of plugin %s not found. Installing plugin %s...", pluginName, pluginName)
			installResult := InstallPlugin(pluginName, "")
			if installResult.Success {
				logger.Info("Successfully installed the plugin %s.", pluginName)
			} else {
				logger.Error("Failed to install the %s plugin.", pluginName)
			}
		} else {
			logger.Info("Plugin %s is already installed.", pluginName)
		}
	}
}
示例#24
0
文件: install.go 项目: 0-T-0/gauge
func downloadAndInstall(plugin, version string, successMessage string) error {
	result := InstallPlugin(plugin, version)
	if !result.Success {
		return fmt.Errorf("%s : %s\n", plugin, result.getMessage())
	}
	if result.Warning != "" {
		logger.Warning(result.Warning)
		return nil
	}
	logger.Info(successMessage)
	return nil
}
示例#25
0
文件: install.go 项目: 0-T-0/gauge
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.Fatalf("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.Fatalf("Failed to install plugin. %s\n", err.Error())
	}
	logger.Info("Successfully installed plugin from file.")
}
示例#26
0
func installPluginFromZip(zipFile string, language string) error {
	unzippedPluginDir, err := common.UnzipArchive(zipFile)
	if err != nil {
		return fmt.Errorf("Failed to unzip plugin-zip file %s.", err.Error())
	}
	logger.Info("Plugin unzipped to => %s\n", unzippedPluginDir)

	hasPluginJSON := common.FileExists(filepath.Join(unzippedPluginDir, pluginJSON))
	if hasPluginJSON {
		return installPluginFromDir(unzippedPluginDir)
	}
	return installRunnerFromDir(unzippedPluginDir, language)
}
示例#27
0
文件: install.go 项目: 0-T-0/gauge
func copyPluginFilesToGaugeInstallDir(unzippedPluginDir string, pluginID string, version string) error {
	logger.Info("Installing Plugin => %s %s\n", pluginID, version)

	pluginsDir, err := common.GetPrimaryPluginsInstallDir()
	if err != nil {
		return err
	}
	versionedPluginDir := path.Join(pluginsDir, pluginID, version)
	if common.DirExists(versionedPluginDir) {
		return fmt.Errorf("Plugin %s %s already installed at %s", pluginID, version, versionedPluginDir)
	}
	_, err = common.MirrorDir(unzippedPluginDir, versionedPluginDir)
	return err
}
示例#28
0
文件: execute.go 项目: 0-T-0/gauge
func Validate(args []string) {
	specsToExecute, conceptsDictionary := parseSpecs(args)
	manifest, err := manifest.ProjectManifest()
	if err != nil {
		logger.Fatalf(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)
}
示例#29
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)
}
示例#30
0
// 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
}