in daisy_test_runner/main.go [197:297]
func createTestSuite(ctx context.Context, path string, varMap map[string]string, regex *regexp.Regexp) (*TestSuite, error) {
var t TestSuite
b, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("%s: %v", path, err)
}
templ, err := testTemplate.Parse(string(b))
if err != nil {
return nil, fmt.Errorf("%s: %v", path, err)
}
var buf bytes.Buffer
if err := templ.Execute(&buf, varMap); err != nil {
return nil, fmt.Errorf("%s: %v", path, err)
}
if *printTemplate {
fmt.Println(buf.String())
return nil, nil
}
if err := json.Unmarshal(buf.Bytes(), &t); err != nil {
return nil, daisy.JSONError(path, buf.Bytes(), err)
}
if *projects != "" {
t.Projects = strings.Split(*projects, ",")
}
if len(t.Projects) == 0 {
return nil, errors.New("no projects provided")
}
if *zone != "" {
t.Zone = *zone
}
if *oauth != "" {
t.OAuthPath = *oauth
}
if *ce != "" {
t.ComputeEndpoint = *ce
}
if *parallelCount != 0 {
t.TestParallelCount = *parallelCount
}
if t.TestParallelCount == 0 {
t.TestParallelCount = defaultParallelCount
}
fmt.Printf("[TestRunner] Creating test cases for test suite %q\n", t.Name)
for name, test := range t.Tests {
test.id = uuid.New().String()
if test.TestTimeout == "" {
test.timeout = defaultTimeout
} else {
d, err := time.ParseDuration(test.TestTimeout)
if err != nil {
test.timeout = defaultTimeout
} else {
test.timeout = d
}
}
if regex != nil && !regex.MatchString(name) {
continue
}
fmt.Printf(" - Creating test case for %q\n", name)
wfPath := filepath.Join(filepath.Dir(path), test.Path)
for k, v := range test.Vars {
varMap[k] = v
}
zone := t.Zone
if test.Zone != "" {
zone = test.Zone
}
oauthPath := t.OAuthPath
if test.OAuthPath != "" {
oauthPath = test.OAuthPath
}
computeEndpoint := t.ComputeEndpoint
if test.ComputeEndpoint != "" {
computeEndpoint = test.ComputeEndpoint
}
rand.Seed(time.Now().UnixNano())
test.logger = &logger{}
w, err := createTestCase(ctx, test.logger, wfPath, t.Projects[rand.Intn(len(t.Projects))], zone, oauthPath, computeEndpoint, varMap)
if err != nil {
return nil, err
}
test.w = w
}
return &t, nil
}