Example #1
0
func parseConfigJobs(config *Config, iniConfig *goini.RawConfig) error {
	config.Jobs = make(map[string]*Job)
	for name, section := range iniConfig.Sections() {
		// Don't try to parse a reserved section as a job.
		if name == "setup" || name == "teardown" || name == "global" {
			continue
		}

		job := new(Job)

		if err := jobOptions.Decode(section, job); err != nil {
			return fmt.Errorf("error parsing job %s: %v",
				strconv.Quote(name), err)
		} else {
			job.Name = name
			if config.Duration > 0 && job.Start > config.Duration {
				return fmt.Errorf("job %s starts after test finishes.",
					strconv.Quote(name))
			} else if job.Stop > 0 && config.Duration > 0 && job.Stop > config.Duration {
				return fmt.Errorf("job %s finishes after test finishes.",
					strconv.Quote(name))
			} else if len(job.Queries) == 0 && job.QueryLog == nil {
				return fmt.Errorf(
					"job %s does not specify either a query or a query log.",
					strconv.Quote(name))
			} else if len(job.Queries) > 0 && job.QueryLog != nil {
				return fmt.Errorf(
					"job %s cannot have both queries and a query log.",
					strconv.Quote(name))
			} else if len(job.Queries) > 1 && !job.MultiQueryAllowed {
				return fmt.Errorf("job %s must have only one query.",
					strconv.Quote(name))
			}

			// If neither the queue depth nor the rate has been set,
			// allow one query at a time.
			//
			if job.QueueDepth == 0 && job.Rate == 0 {
				job.QueueDepth = 1
			}

			config.Jobs[name] = job
		}
	}
	return nil
}
Example #2
0
func parseIniConfig(iniConfig *goini.RawConfig) (*Config, error) {
	var config = new(Config)

	if err := globalOptions.Decode(iniConfig.GlobalSection, config); err != nil {
		return nil, fmt.Errorf("Error parsing global section: %v", err)
	}
	if err := setupOptions.Decode(iniConfig.Sections()["setup"], &config.Setup); err != nil {
		return nil, fmt.Errorf("Error parsing setup section: %v", err)
	}
	if err := setupOptions.Decode(iniConfig.Sections()["teardown"], &config.Teardown); err != nil {
		return nil, fmt.Errorf("Error parsing teardown section: %v", err)
	}

	if err := parseConfigJobs(config, iniConfig); err != nil {
		return nil, err
	}

	return config, nil
}