Esempio n. 1
0
// Special function to dig into nested tags and replace variables with their value there too.
func substituteTagContent(ts *tag.TagSpec, test, global, orig *Test) {
	if ts.Content != nil {
		ocs := ts.Content.String()
		ncs := substitute(ocs, test, global, orig)
		if ncs != ocs {
			if nc, err := tag.MakeContent(ncs); err == nil {
				ts.Content = nc
			} else {
				errorf("Tag AA text content or attribute value is malformed after variable substitution! %s\nocs=%s\nncs=%s", err.Error(), ocs, ncs)
			}
		}
	}
	for _, sub := range ts.Sub {
		substituteTagContent(sub, test, global, orig)
	}
}
Esempio n. 2
0
// Replace all variables in test with their appropriate values.
func substituteVariables(test, global, orig *Test) {
	// test.Url = substitute(test.Url, test, global, orig) done in prepare test

	for k, v := range test.Header {
		test.Header[k] = substitute(v, test, global, orig)
	}
	for i, c := range test.RespCond {
		test.RespCond[i].Val = substitute(c.Val, test, global, orig)
	}
	for i, c := range test.BodyCond {
		test.BodyCond[i].Val = substitute(c.Val, test, global, orig)
	}
	for i, c := range test.CookieCond {
		test.CookieCond[i].Val = substitute(c.Val, test, global, orig)
	}

	for k, vl := range test.Param {
		tracef("Param %s: %v", k, vl)
		sl := make([]string, len(vl))
		for i, v := range vl {
			sl[i] = substitute(v, test, global, orig)
		}
		test.Param[k] = sl
	}

	tracef("Replacing tag content")
	for i, tc := range test.Tag {
		if tc.Spec.Content != nil {
			ocs := tc.Spec.Content.String()
			ncs := substitute(ocs, test, global, orig)
			if ocs != ncs {
				if nc, err := tag.MakeContent(ncs); err == nil {
					test.Tag[i].Spec.Content = nc
				} else {
					errorf("Tag text content or attribute value is malformed after variable substitution! %s", err.Error())
				}
			}
		}
		for j, subts := range tc.Spec.Sub {
			tracef("Replacing sub tag content %d", j)
			substituteTagContent(subts, test, global, orig)
		}
	}
}