// Loads all the properties files available in the specified env directory func loadEnvironment(env string) error { envDir := filepath.Join(config.ProjectRoot, common.EnvDirectoryName) dirToRead := path.Join(envDir, env) if !common.DirExists(dirToRead) { return errors.New(fmt.Sprintf("%s is an invalid environment", env)) } isProperties := func(fileName string) bool { return filepath.Ext(fileName) == ".properties" } err := filepath.Walk(dirToRead, func(path string, info os.FileInfo, err error) error { if isProperties(path) { p, e := properties.Load(path) if e != nil { return errors.New(fmt.Sprintf("Failed to parse: %s. %s", path, e.Error())) } for k, v := range p { err := common.SetEnvVariable(k, v) if err != nil { return errors.New(fmt.Sprintf("%s: %s", path, err.Error())) } } } return nil }) return err }
func setEnvironmentProperties(properties map[string]string) error { for k, v := range properties { if err := common.SetEnvVariable(k, v); err != nil { return err } } return nil }
func setEnvVars() error { for name, value := range envVars { if !isPropertySet(name) { err := common.SetEnvVariable(name, value) if err != nil { return fmt.Errorf("%s", err.Error()) } } } return nil }
func startAPIService(port int) (error, *gaugeApiMessageHandler) { specInfoGatherer := new(specInfoGatherer) apiHandler := &gaugeApiMessageHandler{specInfoGatherer: specInfoGatherer} gaugeConnectionHandler, err := conn.NewGaugeConnectionHandler(port, apiHandler) if err != nil { return err, nil } if port == 0 { if err := common.SetEnvVariable(common.ApiPortEnvVariableName, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber())); err != nil { return errors.New(fmt.Sprintf("Failed to set Env variable %s. %s", common.ApiPortEnvVariableName, err.Error())), nil } } go gaugeConnectionHandler.HandleMultipleConnections() apiHandler.runner = specInfoGatherer.makeListOfAvailableSteps(nil) return nil, apiHandler }
func loadDefaultProperties() error { defaultProperties = make(map[string]string) defaultProperties["gauge_reports_dir"] = "reports" defaultProperties["overwrite_reports"] = "true" defaultProperties["screenshot_on_failure"] = "true" defaultProperties["logs_directory"] = "logs" for property, value := range defaultProperties { if !isPropertySet(property) { if err := common.SetEnvVariable(property, value); err != nil { return err } } } return nil }
func loadEnvFile(path string, info os.FileInfo, err error) error { if !isPropertiesFile(path) { return nil } properties, err := properties.Load(path) if err != nil { return fmt.Errorf("Failed to parse: %s. %s", path, err.Error()) } for property, value := range properties { if canOverwriteProperty(property) { err := common.SetEnvVariable(property, value) if err != nil { return fmt.Errorf("%s: %s", path, err.Error()) } } } return nil }
func StartAPIService(port int, startChannels *runner.StartChannels) { specInfoGatherer := new(infoGatherer.SpecInfoGatherer) apiHandler := &gaugeApiMessageHandler{specInfoGatherer: specInfoGatherer} gaugeConnectionHandler, err := conn.NewGaugeConnectionHandler(port, apiHandler) if err != nil { startChannels.ErrorChan <- err return } if port == 0 { if err := common.SetEnvVariable(common.ApiPortEnvVariableName, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber())); err != nil { startChannels.ErrorChan <- errors.New(fmt.Sprintf("Failed to set Env variable %s. %s", common.ApiPortEnvVariableName, err.Error())) return } } go gaugeConnectionHandler.HandleMultipleConnections() runner, err := specInfoGatherer.MakeListOfAvailableSteps(startChannels.KillChan) if err != nil { startChannels.ErrorChan <- err return } startChannels.RunnerChan <- runner }
// StartAPIService starts the Gauge API service func startAPIService(port int, startChannels *runner.StartChannels, sig *infoGatherer.SpecInfoGatherer) { apiHandler := &gaugeAPIMessageHandler{specInfoGatherer: sig} gaugeConnectionHandler, err := conn.NewGaugeConnectionHandler(port, apiHandler) if err != nil { startChannels.ErrorChan <- fmt.Errorf("Connection error. %s", err.Error()) return } if port == 0 { if err := common.SetEnvVariable(common.APIPortEnvVariableName, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber())); err != nil { startChannels.ErrorChan <- fmt.Errorf("Failed to set Env variable %s. %s", common.APIPortEnvVariableName, err.Error()) return } } go gaugeConnectionHandler.HandleMultipleConnections() runner, err := connectToRunner(startChannels.KillChan) if err != nil { startChannels.ErrorChan <- err return } startChannels.RunnerChan <- runner }
func setCurrentProjectEnvVariable() error { return common.SetEnvVariable(common.GaugeProjectRootEnv, ProjectRoot) }