How to use AppendError method of venom Package

Best Venom code snippet using venom.AppendError

process_testcase.go

Source:process_testcase.go Github

copy

Full Screen

1package venom2import (3 "context"4 "encoding/json"5 "fmt"6 "regexp"7 "strconv"8 "strings"9 "time"10 "github.com/ovh/cds/sdk/interpolate"11 "github.com/pkg/errors"12 "github.com/rockbears/yaml"13)14var varRegEx = regexp.MustCompile("{{.*}}")15// Parse the testcase to find unreplaced and extracted variables16func (v *Venom) parseTestCase(ts *TestSuite, tc *TestCase) ([]string, []string, error) {17 dvars, err := DumpStringPreserveCase(tc.Vars)18 if err != nil {19 return nil, nil, err20 }21 vars := []string{}22 extractedVars := []string{}23 // the value of each var can contains a double-quote -> "24 // if the value is not escaped, it will be used as is, and the json sent to unmarshall will be incorrect.25 // This also avoids injections into the json structure of a step26 for i := range dvars {27 dvars[i] = strings.ReplaceAll(dvars[i], "\"", "\\\"")28 }29 for _, rawStep := range tc.RawTestSteps {30 content, err := interpolate.Do(string(rawStep), dvars)31 if err != nil {32 return nil, nil, err33 }34 var step TestStep35 if err := yaml.Unmarshal([]byte(content), &step); err != nil {36 return nil, nil, errors.Wrapf(err, "unable to unmarshal teststep")37 }38 _, exec, err := v.GetExecutorRunner(context.Background(), step, tc.Vars)39 if err != nil {40 return nil, nil, err41 }42 defaultResult := exec.ZeroValueResult()43 if defaultResult != nil {44 dumpE, err := DumpString(defaultResult)45 if err != nil {46 return nil, nil, err47 }48 for k := range dumpE {49 var found bool50 for i := 0; i < len(vars); i++ {51 if vars[i] == k {52 found = true53 break54 }55 }56 if !found {57 extractedVars = append(extractedVars, k)58 }59 extractedVars = append(extractedVars, tc.Name+"."+k)60 if strings.HasSuffix(k, "__type__") && dumpE[k] == "Map" {61 // go-dump doesnt dump the map name, here is a workaround62 k = strings.TrimSuffix(k, "__type__")63 extractedVars = append(extractedVars, tc.Name+"."+k)64 }65 }66 }67 dumpE, err := DumpStringPreserveCase(step)68 if err != nil {69 return nil, nil, err70 }71 for k, v := range dumpE {72 if strings.HasPrefix(k, "vars.") {73 s := tc.Name + "." + strings.Split(k[5:], ".")[0]74 extractedVars = append(extractedVars, s)75 continue76 }77 if strings.HasPrefix(k, "range.") {78 continue79 }80 if strings.HasPrefix(k, "extracts.") {81 s := tc.Name + "." + strings.Split(k[9:], ".")[0]82 extractedVars = append(extractedVars, s)83 continue84 }85 if strings.HasPrefix(k, "info") {86 continue87 }88 if varRegEx.MatchString(v) {89 var found bool90 for i := 0; i < len(vars); i++ {91 if vars[i] == k {92 found = true93 break94 }95 }96 submatches := varRegEx.FindStringSubmatch(v)97 for submatcheIndex, s := range submatches {98 if submatcheIndex == 0 {99 continue100 }101 for i := 0; i < len(extractedVars); i++ {102 prefix := "{{." + extractedVars[i]103 if strings.HasPrefix(s, prefix) {104 found = true105 break106 }107 }108 if !found {109 vars = append(vars, s)110 s = strings.ReplaceAll(s, "{{ .", "")111 s = strings.ReplaceAll(s, "{{.", "")112 s = strings.ReplaceAll(s, "}}", "")113 vars = append(vars, s)114 }115 }116 }117 }118 }119 return vars, extractedVars, nil120}121func (v *Venom) runTestCase(ctx context.Context, ts *TestSuite, tc *TestCase) {122 ctx = context.WithValue(ctx, ContextKey("testcase"), tc.Name)123 tc.TestSuiteVars = ts.Vars.Clone()124 tc.Vars = ts.Vars.Clone()125 tc.Vars.Add("venom.testcase", tc.Name)126 tc.Vars.AddAll(ts.ComputedVars)127 tc.computedVars = H{}128 Info(ctx, "Starting testcase")129 for k, v := range tc.Vars {130 Debug(ctx, "Running testcase with variable %s: %+v", k, v)131 }132 defer Info(ctx, "Ending testcase")133 // ##### RUN Test Steps Here134 v.runTestSteps(ctx, tc, nil)135}136func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepResult) {137 results, err := testConditionalStatement(ctx, tc, tc.Skip, tc.Vars, "skipping testcase %q: %v")138 if err != nil {139 Error(ctx, "unable to evaluate \"skip\" assertions: %v", err)140 testStepResult := TestStepResult{}141 testStepResult.appendError(err)142 tc.TestStepResults = append(tc.TestStepResults, testStepResult)143 return144 }145 if len(results) > 0 {146 tc.Status = StatusSkip147 for _, s := range results {148 tc.Skipped = append(tc.Skipped, Skipped{Value: s})149 Warn(ctx, s)150 }151 return152 }153 var knowExecutors = map[string]struct{}{}154 var previousStepVars = H{}155 fromUserExecutor := tsIn != nil156 for stepNumber, rawStep := range tc.RawTestSteps {157 stepVars := tc.Vars.Clone()158 stepVars.AddAll(previousStepVars)159 stepVars.AddAllWithPrefix(tc.Name, tc.computedVars)160 stepVars.Add("venom.teststep.number", stepNumber)161 ranged, err := parseRanged(ctx, rawStep, stepVars)162 if err != nil {163 Error(ctx, "unable to parse \"range\" attribute: %v", err)164 tsIn.appendError(err)165 return166 }167 for rangedIndex, rangedData := range ranged.Items {168 tc.TestStepResults = append(tc.TestStepResults, TestStepResult{})169 tsResult := &tc.TestStepResults[len(tc.TestStepResults)-1]170 if ranged.Enabled {171 Debug(ctx, "processing range index: %d", rangedIndex)172 stepVars.Add("index", rangedIndex)173 stepVars.Add("key", rangedData.Key)174 stepVars.Add("value", rangedData.Value)175 }176 vars, err := DumpStringPreserveCase(stepVars)177 if err != nil {178 Error(ctx, "unable to dump testcase vars: %v", err)179 tsResult.appendError(err)180 return181 }182 for k, v := range vars {183 content, err := interpolate.Do(v, vars)184 if err != nil {185 tsResult.appendError(err)186 Error(ctx, "unable to interpolate variable %q: %v", k, err)187 return188 }189 vars[k] = content190 }191 // the value of each var can contains a double-quote -> "192 // if the value is not escaped, it will be used as is, and the json sent to unmarshall will be incorrect.193 // This also avoids injections into the json structure of a step194 for i := range vars {195 if strings.Contains(vars[i], `"`) {196 x := strconv.Quote(vars[i])197 x = strings.TrimPrefix(x, `"`)198 x = strings.TrimSuffix(x, `"`)199 vars[i] = x200 }201 }202 var content string203 for i := 0; i < 10; i++ {204 content, err = interpolate.Do(string(rawStep), vars)205 if err != nil {206 tsResult.appendError(err)207 Error(ctx, "unable to interpolate step: %v", err)208 return209 }210 if !strings.Contains(content, "{{") {211 break212 }213 }214 if ranged.Enabled {215 Info(ctx, "Step #%d-%d content is: %s", stepNumber, rangedIndex, content)216 } else {217 Info(ctx, "Step #%d content is: %s", stepNumber, content)218 }219 data, err := yaml.Marshal(rawStep)220 if err != nil {221 tsResult.appendError(err)222 Error(ctx, "unable to marshal raw: %v", err)223 }224 tsResult.Raw = data225 var step TestStep226 if err := yaml.Unmarshal([]byte(content), &step); err != nil {227 tsResult.appendError(err)228 Error(ctx, "unable to parse step #%d: %v", stepNumber, err)229 return230 }231 data2, err := yaml.JSONToYAML([]byte(content))232 if err != nil {233 tsResult.appendError(err)234 Error(ctx, "unable to marshal step #%d to json: %v", stepNumber, err)235 }236 tsResult.Interpolated = data2237 tsResult.Number = stepNumber238 tsResult.RangedIndex = rangedIndex239 tsResult.RangedEnable = ranged.Enabled240 tsResult.InputVars = vars241 tc.testSteps = append(tc.testSteps, step)242 var e ExecutorRunner243 ctx, e, err = v.GetExecutorRunner(ctx, step, tc.Vars)244 if err != nil {245 tsResult.appendError(err)246 Error(ctx, "unable to get executor: %v", err)247 break248 }249 if e != nil {250 _, known := knowExecutors[e.Name()]251 if !known {252 ctx, err = e.Setup(ctx, tc.Vars)253 if err != nil {254 tsResult.appendError(err)255 Error(ctx, "unable to setup executor: %v", err)256 break257 }258 knowExecutors[e.Name()] = struct{}{}259 defer func(ctx context.Context) {260 if err := e.TearDown(ctx); err != nil {261 tsResult.appendError(err)262 Error(ctx, "unable to teardown executor: %v", err)263 }264 }(ctx)265 }266 }267 printStepName := v.Verbose >= 1 && !fromUserExecutor268 v.setTestStepName(tsResult, e, step, &ranged, &rangedData, rangedIndex, printStepName)269 tsResult.Start = time.Now()270 // ##### RUN Test Step Here271 tsResult.Status = StatusRun272 result := v.RunTestStep(ctx, e, tc, tsResult, stepNumber, rangedIndex, step)273 if len(tsResult.Errors) > 0 || !tsResult.AssertionsApplied.OK {274 tsResult.Status = StatusFail275 } else {276 tsResult.Status = StatusPass277 }278 tsResult.End = time.Now()279 tsResult.Duration = tsResult.End.Sub(tsResult.Start).Seconds()280 mapResult := GetExecutorResult(result)281 previousStepVars.AddAll(H(mapResult))282 tc.testSteps = append(tc.testSteps, step)283 var isRequired bool284 if tsResult.Status == StatusFail {285 Error(ctx, "Errors: ")286 for _, e := range tsResult.Errors {287 Error(ctx, "%v", e)288 isRequired = isRequired || e.AssertionRequired289 }290 if isRequired {291 failure := newFailure(ctx, *tc, stepNumber, rangedIndex, "", fmt.Errorf("At least one required assertion failed, skipping remaining steps"))292 tsResult.appendFailure(*failure)293 v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, true)294 return295 }296 v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, false)297 continue298 }299 v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, false)300 allVars := tc.Vars.Clone()301 allVars.AddAll(tc.computedVars.Clone())302 tsResult.ComputedVars = tc.computedVars.Clone()303 assign, _, err := processVariableAssigments(ctx, tc.Name, allVars, rawStep)304 if err != nil {305 tsResult.appendError(err)306 Error(ctx, "unable to process variable assignments: %v", err)307 break308 }309 tc.computedVars.AddAll(assign)310 previousStepVars.AddAll(assign)311 }312 }313}314// Set test step name (defaults to executor name, excepted if it got a "name" attribute. in range, also print key)315func (v *Venom) setTestStepName(ts *TestStepResult, e ExecutorRunner, step TestStep, ranged *Range, rangedData *RangeData, rangedIndex int, print bool) {316 name := e.Name()317 if value, ok := step["name"]; ok {318 switch value := value.(type) {319 case string:320 name = value321 }322 }323 if ranged.Enabled {324 if rangedIndex == 0 {325 v.Print("\n")326 }327 name = fmt.Sprintf("%s (range=%s)", name, rangedData.Key)328 }329 ts.Name = name330 if print || ranged.Enabled {331 v.Print(" \t\t• %s", ts.Name)332 }333}334// Print a single step result (if verbosity is enabled)335func (v *Venom) printTestStepResult(tc *TestCase, ts *TestStepResult, tsIn *TestStepResult, ranged Range, stepNumber int, mustAssertionFailed bool) {336 fromUserExecutor := tsIn != nil337 if fromUserExecutor {338 tsIn.appendFailure(ts.Errors...)339 }340 if ranged.Enabled || v.Verbose >= 1 {341 if !fromUserExecutor { //Else print step status342 if len(ts.Errors) > 0 {343 v.Println(" %s", Red(StatusFail))344 for _, f := range ts.Errors {345 v.Println(" \t\t %s", Yellow(f.Value))346 }347 if mustAssertionFailed {348 skipped := len(tc.RawTestSteps) - stepNumber - 1349 if skipped == 1 {350 v.Println(" \t\t %s", Gray(fmt.Sprintf("%d other step was skipped", skipped)))351 } else {352 v.Println(" \t\t %s", Gray(fmt.Sprintf("%d other steps were skipped", skipped)))353 }354 }355 } else {356 v.Println(" %s", Green(StatusPass))357 }358 }359 }360}361// Parse and format range data to allow iterations over user data362func parseRanged(ctx context.Context, rawStep []byte, stepVars H) (Range, error) {363 //Load "range" attribute and perform actions depending on its typing364 var ranged Range365 if err := json.Unmarshal(rawStep, &ranged); err != nil {366 return ranged, fmt.Errorf("unable to parse range expression: %v", err)367 }368 switch ranged.RawContent.(type) {369 //Nil means this is not a ranged data, append an empty item to force at least one iteration and exit370 case nil:371 ranged.Items = append(ranged.Items, RangeData{})372 return ranged, nil373 //String needs to be parsed and possibly templated374 case string:375 Debug(ctx, "attempting to parse range expression")376 rawString := ranged.RawContent.(string)377 if len(rawString) == 0 {378 return ranged, fmt.Errorf("range expression has been specified without any data")379 }380 // Try parsing already templated data381 err := json.Unmarshal([]byte("{\"range\":"+rawString+"}"), &ranged)382 // ... or fallback383 if err != nil {384 //Try templating and escaping data385 Debug(ctx, "attempting to template range expression and parse it again")386 vars, err := DumpStringPreserveCase(stepVars)387 if err != nil {388 Warn(ctx, "failed to parse range expression when loading step variables: %v", err)389 break390 }391 for i := range vars {392 vars[i] = strings.ReplaceAll(vars[i], "\"", "\\\"")393 }394 content, err := interpolate.Do(string(rawStep), vars)395 if err != nil {396 Warn(ctx, "failed to parse range expression when templating variables: %v", err)397 break398 }399 //Try parsing data400 err = json.Unmarshal([]byte(content), &ranged)401 if err != nil {402 Warn(ctx, "failed to parse range expression when parsing data into raw string: %v", err)403 break404 }405 switch ranged.RawContent.(type) {406 case string:407 rawString = ranged.RawContent.(string)408 err := json.Unmarshal([]byte("{\"range\":"+rawString+"}"), &ranged)409 if err != nil {410 Warn(ctx, "failed to parse range expression when parsing raw string into data: %v", err)411 return ranged, fmt.Errorf("unable to parse range expression: unable to transform string data into a supported range expression type")412 }413 }414 }415 }416 //Format data417 switch t := ranged.RawContent.(type) {418 //Array-like data419 case []interface{}:420 Debug(ctx, "\"range\" data is array-like")421 for index, value := range ranged.RawContent.([]interface{}) {422 key := strconv.Itoa(index)423 ranged.Items = append(ranged.Items, RangeData{key, value})424 }425 //Number data426 case float64:427 Debug(ctx, "\"range\" data is number-like")428 upperBound := int(ranged.RawContent.(float64))429 for i := 0; i < upperBound; i++ {430 key := strconv.Itoa(i)431 ranged.Items = append(ranged.Items, RangeData{key, i})432 }433 //Map-like data434 case map[string]interface{}:435 Debug(ctx, "\"range\" data is map-like")436 for key, value := range ranged.RawContent.(map[string]interface{}) {437 ranged.Items = append(ranged.Items, RangeData{key, value})438 }439 //Unsupported data format440 default:441 return ranged, fmt.Errorf("\"range\" was provided an unsupported type %T", t)442 }443 ranged.Enabled = true444 ranged.RawContent = nil445 return ranged, nil446}447func processVariableAssigments(ctx context.Context, tcName string, tcVars H, rawStep json.RawMessage) (H, bool, error) {448 var stepAssignment AssignStep449 var result = make(H)450 if err := yaml.Unmarshal(rawStep, &stepAssignment); err != nil {451 Error(ctx, "unable to parse assignements (%s): %v", string(rawStep), err)452 return nil, false, err453 }454 if len(stepAssignment.Assignments) == 0 {455 return nil, false, nil456 }457 var tcVarsKeys []string458 for k := range tcVars {459 tcVarsKeys = append(tcVarsKeys, k)460 }461 for varname, assigment := range stepAssignment.Assignments {462 Debug(ctx, "Processing %s assignment", varname)463 varValue, has := tcVars[assigment.From]464 if !has {465 varValue, has = tcVars[tcName+"."+assigment.From]466 if !has {467 if assigment.Default == nil {468 err := fmt.Errorf("%s reference not found in %s", assigment.From, strings.Join(tcVarsKeys, "\n"))469 Info(ctx, "%v", err)470 return nil, true, err471 }472 varValue = assigment.Default473 }474 }475 if assigment.Regex == "" {476 Info(ctx, "Assign '%s' value '%s'", varname, varValue)477 result.Add(varname, varValue)478 } else {479 regex, err := regexp.Compile(assigment.Regex)480 if err != nil {481 Warn(ctx, "unable to compile regexp %q", assigment.Regex)482 return nil, true, err483 }484 varValueS, ok := varValue.(string)485 if !ok {486 Warn(ctx, "%q is not a string value", varname)487 result.Add(varname, "")488 continue489 }490 submatches := regex.FindStringSubmatch(varValueS)491 if len(submatches) == 0 {492 Warn(ctx, "%s: %q doesn't match anything in %q", varname, regex, varValue)493 result.Add(varname, "")494 continue495 }496 Info(ctx, "Assign %q from regexp %q, values %q", varname, regex, submatches)497 result.Add(varname, submatches[len(submatches)-1])498 }499 }500 return result, true, nil501}...

Full Screen

Full Screen

types.go

Source:types.go Github

copy

Full Screen

...118// Skipped contains data related to a skipped test.119type Skipped struct {120 Value string `xml:",cdata" json:"value" yaml:"value,omitempty"`121}122func (tc *TestCase) AppendError(err error) {123 tc.Errors = append(tc.Errors, Failure{Value: RemoveNotPrintableChar(err.Error())})124}125// Failure contains data related to a failed test.126type Failure struct {127 TestcaseClassname string `xml:"-" json:"-" yaml:"-"`128 TestcaseName string `xml:"-" json:"-" yaml:"-"`129 TestcaseLineNumber int `xml:"-" json:"-" yaml:"-"`130 StepNumber int `xml:"-" json:"-" yaml:"-"`131 Assertion string `xml:"-" json:"-" yaml:"-"`132 AssertionRequired bool `xml:"-" json:"-" yaml:"-"`133 Error error `xml:"-" json:"-" yaml:"-"`134 Value string `xml:",cdata" json:"value" yaml:"value,omitempty"`135 Type string `xml:"type,attr,omitempty" json:"type" yaml:"type,omitempty"`136 Message string `xml:"message,attr,omitempty" json:"message" yaml:"message,omitempty"`...

Full Screen

Full Screen

process_teststep.go

Source:process_teststep.go Github

copy

Full Screen

1package venom2import (3 "context"4 "encoding/json"5 "fmt"6 "os"7 "path"8 "time"9 "github.com/gosimple/slug"10 "github.com/ovh/cds/sdk/interpolate"11)12type dumpFile struct {13 Variables H `json:"variables"`14 TestStep TestStep `json:"step"`15 Result interface{} `json:"result"`16}17// RunTestStep executes a venom testcase is a venom context18func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase, tsResult *TestStepResult, stepNumber int, rangedIndex int, step TestStep) interface{} {19 ctx = context.WithValue(ctx, ContextKey("executor"), e.Name())20 var assertRes AssertionsApplied21 var retry int22 var result interface{}23 for retry = 0; retry <= e.Retry() && !assertRes.OK; retry++ {24 if retry > 1 && !assertRes.OK {25 Debug(ctx, "Sleep %d, it's %d attempt", e.Delay(), retry)26 time.Sleep(time.Duration(e.Delay()) * time.Second)27 }28 var err error29 result, err = v.runTestStepExecutor(ctx, e, tc, tsResult, step)30 if err != nil {31 // we save the failure only if it's the last attempt32 if retry == e.Retry() {33 failure := newFailure(ctx, *tc, stepNumber, rangedIndex, "", err)34 tsResult.appendFailure(*failure)35 }36 continue37 }38 Debug(ctx, "result of runTestStepExecutor: %+v", result)39 mapResult := GetExecutorResult(result)40 mapResultString, _ := DumpString(result)41 if v.Verbose >= 2 {42 fdump := dumpFile{43 Result: result,44 TestStep: step,45 Variables: AllVarsFromCtx(ctx),46 }47 output, err := json.MarshalIndent(fdump, "", " ")48 if err != nil {49 Error(ctx, "unable to marshal result: %v", err)50 }51 oDir := v.OutputDir52 if oDir == "" {53 oDir = "."54 }55 filename := path.Join(oDir, fmt.Sprintf("%s.%s.step.%d.%d.dump.json", slug.Make(StringVarFromCtx(ctx, "venom.testsuite.shortName")), slug.Make(tc.Name), stepNumber, rangedIndex))56 if err := os.WriteFile(filename, []byte(output), 0644); err != nil {57 return fmt.Errorf("Error while creating file %s: %v", filename, err)58 }59 tc.computedVerbose = append(tc.computedVerbose, fmt.Sprintf("writing %s", filename))60 }61 for ninfo, i := range e.Info() {62 info, err := interpolate.Do(i, mapResultString)63 if err != nil {64 Error(ctx, "unable to parse %q: %v", i, err)65 continue66 }67 if info == "" {68 continue69 }70 filename := StringVarFromCtx(ctx, "venom.testsuite.filename")71 lineNumber := findLineNumber(filename, tc.originalName, stepNumber, i, ninfo+1)72 if lineNumber > 0 {73 info += fmt.Sprintf(" (%s:%d)", filename, lineNumber)74 } else if tc.IsExecutor {75 filename = StringVarFromCtx(ctx, "venom.executor.filename")76 originalName := StringVarFromCtx(ctx, "venom.executor.name")77 lineNumber = findLineNumber(filename, originalName, stepNumber, i, ninfo+1)78 if lineNumber > 0 {79 info += fmt.Sprintf(" (%s:%d)", filename, lineNumber)80 }81 }82 Info(ctx, info)83 tc.computedInfo = append(tc.computedInfo, info)84 tsResult.ComputedInfo = append(tsResult.ComputedInfo, info)85 }86 if result == nil {87 Debug(ctx, "empty testcase, applying assertions on variables: %v", AllVarsFromCtx(ctx))88 assertRes = applyAssertions(ctx, AllVarsFromCtx(ctx), *tc, stepNumber, rangedIndex, step, nil)89 } else {90 if h, ok := e.(executorWithDefaultAssertions); ok {91 assertRes = applyAssertions(ctx, result, *tc, stepNumber, rangedIndex, step, h.GetDefaultAssertions())92 } else {93 assertRes = applyAssertions(ctx, result, *tc, stepNumber, rangedIndex, step, nil)94 }95 }96 tsResult.AssertionsApplied = assertRes97 tc.computedVars.AddAll(H(mapResult))98 if assertRes.OK {99 break100 }101 failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), tc.computedVars, "")102 if err != nil {103 tsResult.appendError(fmt.Errorf("Error while evaluating retry condition: %v", err))104 break105 }106 if len(failures) > 0 {107 failure := newFailure(ctx, *tc, stepNumber, rangedIndex, "", fmt.Errorf("retry conditions not fulfilled, skipping %d remaining retries", e.Retry()-retry))108 tsResult.Errors = append(tsResult.Errors, *failure)109 break110 }111 }112 if retry > 1 && len(assertRes.errors) > 0 {113 tsResult.appendFailure(Failure{Value: fmt.Sprintf("It's a failure after %d attempts", retry)})114 } else if len(assertRes.errors) > 0 {115 tsResult.appendFailure(assertRes.errors...)116 }117 tsResult.Systemerr += assertRes.systemerr + "\n"118 tsResult.Systemout += assertRes.systemout + "\n"119 return result120}121func (v *Venom) runTestStepExecutor(ctx context.Context, e ExecutorRunner, tc *TestCase, ts *TestStepResult, step TestStep) (interface{}, error) {122 ctx = context.WithValue(ctx, ContextKey("executor"), e.Name())123 if e.Timeout() == 0 {124 if e.Type() == "user" {125 return v.RunUserExecutor(ctx, e, tc, ts, step)126 }127 return e.Run(ctx, step)128 }129 ctxTimeout, cancel := context.WithTimeout(ctx, time.Duration(e.Timeout())*time.Second)130 defer cancel()131 ch := make(chan interface{})132 cherr := make(chan error)133 go func(e ExecutorRunner, step TestStep) {134 var err error135 var result interface{}136 if e.Type() == "user" {137 result, err = v.RunUserExecutor(ctx, e, tc, ts, step)138 } else {139 result, err = e.Run(ctx, step)140 }141 if err != nil {142 cherr <- err143 } else {144 ch <- result145 }146 }(e, step)147 select {148 case err := <-cherr:149 return nil, err150 case result := <-ch:151 return result, nil152 case <-ctxTimeout.Done():153 return nil, fmt.Errorf("Timeout after %d second(s)", e.Timeout())154 }155}...

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err1 := errors.New("error 1")4 err2 := errors.New("error 2")5 err3 := errors.New("error 3")6 err = venom.AppendError(err, err2)7 err = venom.AppendError(err, err3)8 fmt.Println(err)9}10error 1; error 2; error 3

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 e = venom.AppendError(e, fmt.Errorf("error 1"))4 e = venom.AppendError(e, fmt.Errorf("error 2"))5 fmt.Println(e)6}7import (8func main() {9 e = venom.AppendError(e, fmt.Errorf("error 1"))10 e = venom.AppendError(e, fmt.Errorf("error 2"))11 fmt.Println(e)12}13import (14func main() {15 e = venom.AppendError(e, fmt.Errorf("error 1"))16 e = venom.AppendError(e, fmt.Errorf("error 2"))17 fmt.Println(e)18}19import (20func main() {21 e = venom.AppendError(e, fmt.Errorf("error 1"))22 e = venom.AppendError(e, fmt.Errorf("error 2"))23 fmt.Println(e)24}25import (26func main() {27 e = venom.AppendError(e, fmt.Errorf("error 1"))28 e = venom.AppendError(e, fmt.Errorf("error 2"))29 fmt.Println(e)30}31import (

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v := validator.NewValidator(4 &rules.NoUnusedFragments{},5 &rules.NoUnusedVariables{},6 &rules.NoUndefinedVariables{},7 &rules.NoUndefinedTypes{},8 &rules.NoUndefinedFragments{},9 &rules.NoFragmentCycles{},10 &rules.UniqueFragmentNames{},11 &rules.UniqueOperationNames{},12 &rules.UniqueVariableNames{},13 &rules.PossibleFragmentSpreads{},14 &rules.NoFragmentSpreadsOnCompositeTypes{},15 &rules.KnownDirectives{},16 &rules.KnownFragmentNames{},

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v := venom.New()4 suite := venom.TestSuite{5 }6 testCase := venom.TestCase{7 }8 testStep := venom.TestStep{9 }10 testCase.TestSteps = append(testCase.TestSteps, testStep)11 suite.TestCases = append(suite.TestCases, testCase)12 v.TestSuites = append(v.TestSuites, suite)13 result, err := v.RunTestSuite(suite.Name)14 if err != nil {15 log.Fatal(err)16 }17 fmt.Println(result)18 result.AppendError(fmt.Errorf("error message"))19 fmt.Println(result)20 resultJSON, err := result.ToJSON()21 if err != nil {22 log.Fatal(err)23 }24 fmt.Println(resultJSON)25 resultXML, err := result.ToXML()26 if err != nil {27 log.Fatal(err)28 }29 fmt.Println(resultXML)30 f, err := os.Create("result.json")31 if err != nil {32 log.Fatal(err)33 }34 defer f.Close()35 f.Write(resultJSON)36 f, err = os.Create("result.xml")37 if err != nil {38 log.Fatal(err)39 }40 defer f.Close()41 f.Write(resultXML)42}

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 v := venom.Venom{}5 v.AppendError("test error")6 fmt.Println(v.Errors)7}8import (9func main() {10 fmt.Println("Hello, playground")11 v := venom.Venom{}12 v.AppendError("test error")13 fmt.Println(v.Errors)14}15import (16func main() {17 fmt.Println("Hello, playground")18 v := venom.Venom{}19 v.AppendError("test error")20 fmt.Println(v.Errors)21}22import (23func main() {24 fmt.Println("Hello, playground")25 v := venom.Venom{}26 v.AppendError("test error")27 fmt.Println(v.Errors)28}29import (30func main() {31 fmt.Println("Hello, playground")32 v := venom.Venom{}33 v.AppendError("test error")34 fmt.Println(v.Errors)35}36import (37func main() {38 fmt.Println("Hello, playground")39 v := venom.Venom{}40 v.AppendError("test error")41 fmt.Println(v.Errors)42}43import (

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "venom"3func main() {4 myerr := venom.NewError("This is my error")5 fmt.Println(myerr)6 myerr.AppendError("This is appended error")7 fmt.Println(myerr)8}9import "fmt"10import "venom"11func main() {12 myerr := venom.NewError("This is my error")13 fmt.Println(myerr)14 myerr.AppendError("This is appended error")15 fmt.Println(myerr)16}17import "fmt"18import "venom"19func main() {20 myerr := venom.NewError("This is my error")21 fmt.Println(myerr)22 myerr.AppendError("This is appended error")23 fmt.Println(myerr)24}25import "fmt"26import "venom"27func main() {28 myerr := venom.NewError("This is my error")29 fmt.Println(myerr)30 myerr.AppendError("This is appended error")31 fmt.Println(myerr)32}33import "fmt"34import "venom"35func main() {36 myerr := venom.NewError("This is my error")37 fmt.Println(myerr)38 myerr.AppendError("This is appended error")39 fmt.Println(myerr)40}41import "fmt"42import "venom"43func main() {44 myerr := venom.NewError("This is my error")45 fmt.Println(myerr)46 myerr.AppendError("This is appended error")47 fmt.Println(myerr)48}49import "fmt"50import "venom"51func main() {52 myerr := venom.NewError("This is my error")53 fmt.Println(myerr)54 myerr.AppendError("This is appended error")55 fmt.Println(myerr)56}

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v := venom.New()4 v.AppendError(venom.NewError("test1"))5 v.AppendError(venom.NewError("test2"))6 v.AppendError(venom.NewError("test3"))7 fmt.Println(v.Error())8}

Full Screen

Full Screen

AppendError

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4import (5func main() {6}7import (8func main() {9}10import (11func main() {12}13import (14func main() {15}16import (17func main() {18}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Venom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful