Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: variables parsing #205

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ func check(tc TestCase, stepNumber int, assertion string, executorResult Executo
return &Failure{Value: RemoveNotPrintableChar(fmt.Sprintf("invalid assertion '%s' len:'%d'", assertion, len(assert)))}, nil
}

var executorResultKeys []string
for k := range executorResult {
executorResultKeys = append(executorResultKeys, k)
}

actual, ok := executorResult[assert[0]]
if !ok {
if assert[1] == "ShouldNotExist" {
return nil, nil
}
return &Failure{Value: RemoveNotPrintableChar(fmt.Sprintf("key '%s' does not exist in result of executor: %+v", assert[0], executorResult))}, nil
return &Failure{Value: RemoveNotPrintableChar(fmt.Sprintf("key '%s' does not exist in result of executor: %v", assert[0], executorResultKeys))}, nil
} else if assert[1] == "ShouldNotExist" {
return &Failure{Value: RemoveNotPrintableChar(fmt.Sprintf("key '%s' should not exist in result of executor. Value: %+v", assert[0], actual))}, nil
}
Expand Down
7 changes: 6 additions & 1 deletion executors/readfile/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ type Result struct {

// ZeroValueResult return an empty implemtation of this executor result
func (Executor) ZeroValueResult() venom.ExecutorResult {
r, _ := executors.Dump(Result{})
r, _ := executors.Dump(Result{
Md5sum: make(map[string]string),
Size: make(map[string]int64),
ModTime: make(map[string]int64),
Mod: make(map[string]string),
})
return r
}

Expand Down
20 changes: 16 additions & 4 deletions process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (v *Venom) parseTestCase(ts *TestSuite, tc *TestCase) ([]string, []string,

for k := range dumpE {
extractedVars = append(extractedVars, tc.Name+"."+k)
if strings.HasSuffix(k, "__type__") && dumpE[k] == "Map" {
// go-dump doesnt dump the map name, here is a workaround
k = strings.TrimSuffix(k, "__type__")
extractedVars = append(extractedVars, tc.Name+"."+k)
}
}
}

Expand All @@ -70,7 +75,9 @@ func (v *Venom) parseTestCase(ts *TestSuite, tc *TestCase) ([]string, []string,

for k, v := range dumpE {
if strings.HasPrefix(k, "vars.") {
extractedVars = append(extractedVars, tc.Name+"."+strings.Split(k[5:], ".")[0])
s := tc.Name + "." + strings.Split(k[5:], ".")[0]
extractedVars = append(extractedVars, s)

continue
}
if strings.HasPrefix(k, "extracts.") {
Expand Down Expand Up @@ -99,16 +106,16 @@ func (v *Venom) parseTestCase(ts *TestSuite, tc *TestCase) ([]string, []string,
}
}

s := varRegEx.FindString(v)

for i := 0; i < len(extractedVars); i++ {
s := varRegEx.FindString(v)
prefix := "{{." + extractedVars[i]
if strings.HasPrefix(s, prefix) {
found = true
break
}
}
if !found {
s := varRegEx.FindString(v)
s = strings.Replace(s, "{{.", "", -1)
s = strings.Replace(s, "}}", "", -1)
vars = append(vars, s)
Expand Down Expand Up @@ -173,13 +180,18 @@ func ProcessVariableAssigments(tcName string, tcVars H, stepIn TestStep, l Logge
return nil, false, nil
}

var tcVarsKeys []string
for k := range tcVars {
tcVarsKeys = append(tcVarsKeys, k)
}

for varname, assigment := range stepAssignment.Assignments {
l.Debugf("Processing %s assignment", varname)
varValue, has := tcVars[assigment.From]
if !has {
varValue, has = tcVars[tcName+"."+assigment.From]
if !has {
err := fmt.Errorf("%s reference not found in %v", assigment.From, tcVars)
err := fmt.Errorf("%s reference not found in %s", assigment.From, strings.Join(tcVarsKeys, "\n"))
l.Errorf("%v", err)
return nil, true, err
}
Expand Down