How to use newFailedMetaData method of rerun Package

Best Gauge code snippet using rerun.newFailedMetaData

rerun.go

Source:rerun.go Github

copy

Full Screen

...26 lastRunCmdFileName = "lastRunCmd.json"27)28var failedMeta *failedMetadata29func init() {30 failedMeta = newFailedMetaData()31}32type failedMetadata struct {33 Args []string34 failedItemsMap map[string]map[string]bool35 FailedItems []string36}37func (m *failedMetadata) args() []string {38 return append(m.Args, m.FailedItems...)39}40func (m *failedMetadata) getFailedItems() []string {41 failedItems := []string{}42 for _, v := range m.failedItemsMap {43 for k := range v {44 failedItems = append(failedItems, k)45 }46 }47 return failedItems48}49func (m *failedMetadata) aggregateFailedItems() {50 m.FailedItems = m.getFailedItems()51}52func newFailedMetaData() *failedMetadata {53 return &failedMetadata{Args: make([]string, 0), failedItemsMap: make(map[string]map[string]bool), FailedItems: []string{}}54}55func (m *failedMetadata) addFailedItem(itemName string, item string) {56 if _, ok := m.failedItemsMap[itemName]; !ok {57 m.failedItemsMap[itemName] = make(map[string]bool)58 }59 m.failedItemsMap[itemName][item] = true60}61// ListenFailedScenarios listens to execution events and writes the failed scenarios to JSON file62func ListenFailedScenarios(wg *sync.WaitGroup, specDirs []string) {63 ch := make(chan event.ExecutionEvent)64 event.Register(ch, event.ScenarioEnd)65 event.Register(ch, event.SpecEnd)66 event.Register(ch, event.SuiteEnd)67 wg.Add(1)68 go func() {69 for {70 e := <-ch71 switch e.Topic {72 case event.ScenarioEnd:73 prepareScenarioFailedMetadata(e.Result.(*result.ScenarioResult), e.Item.(*gauge.Scenario), e.ExecutionInfo)74 case event.SpecEnd:75 addFailedMetadata(e.Result, specDirs, addSpecFailedMetadata)76 case event.SuiteEnd:77 addFailedMetadata(e.Result, specDirs, addSuiteFailedMetadata)78 failedMeta.aggregateFailedItems()79 writeFailedMeta(getJSON(failedMeta))80 wg.Done()81 }82 }83 }()84}85func prepareScenarioFailedMetadata(res *result.ScenarioResult, sce *gauge.Scenario, executionInfo *gauge_messages.ExecutionInfo) {86 if res.GetFailed() {87 specPath := executionInfo.GetCurrentSpec().GetFileName()88 failedScenario := util.RelPathToProjectRoot(specPath)89 failedMeta.addFailedItem(specPath, fmt.Sprintf("%s:%v", failedScenario, sce.Span.Start))90 }91}92func addSpecFailedMetadata(res result.Result, args []string) {93 fileName := util.RelPathToProjectRoot(res.(*result.SpecResult).ProtoSpec.GetFileName())94 delete(failedMeta.failedItemsMap, fileName)95 failedMeta.addFailedItem(fileName, fileName)96}97func addSuiteFailedMetadata(res result.Result, args []string) {98 failedMeta.failedItemsMap = make(map[string]map[string]bool)99 for _, arg := range args {100 path, err := filepath.Abs(arg)101 path = util.RelPathToProjectRoot(path)102 if err == nil {103 failedMeta.addFailedItem(path, path)104 }105 }106}107func addFailedMetadata(res result.Result, args []string, add func(res result.Result, args []string)) {108 if len(res.GetPostHook()) > 0 || len(res.GetPreHook()) > 0 {109 add(res, args)110 }111}112func writeFailedMeta(contents string) {113 failuresFile := filepath.Join(config.ProjectRoot, common.DotGauge, failedFile)114 dotGaugeDir := filepath.Join(config.ProjectRoot, common.DotGauge)115 if err := os.MkdirAll(dotGaugeDir, common.NewDirectoryPermissions); err != nil {116 logger.Fatalf(true, "Failed to create directory in %s. Reason: %s", dotGaugeDir, err.Error())117 }118 err := ioutil.WriteFile(failuresFile, []byte(contents), common.NewFilePermissions)119 if err != nil {120 logger.Fatalf(true, "Failed to write to %s. Reason: %s", failuresFile, err.Error())121 }122}123func getJSON(failedMeta *failedMetadata) string {124 j, err := json.MarshalIndent(failedMeta, "", "\t")125 if err != nil {126 logger.Warningf(true, "Failed to save run info. Reason: %s", err.Error())127 }128 return string(j)129}130var GetLastFailedState = func() ([]string, error) {131 meta := readLastFailedState()132 util.SetWorkingDir(config.ProjectRoot)133 if len(meta.FailedItems) == 0 {134 return nil, errors.New("No failed tests found.")135 }136 return meta.args(), nil137}138func SaveState(args []string, specs []string) {139 isPresent := func(values []string, value string) bool {140 for _, v := range values {141 if v == value {142 return true143 }144 }145 return false146 }147 for _, a := range args {148 if !isPresent(specs, a) {149 failedMeta.Args = append(failedMeta.Args, a)150 }151 }152}153func readLastFailedState() *failedMetadata {154 contents, err := common.ReadFileContents(filepath.Join(config.ProjectRoot, common.DotGauge, failedFile))155 if err != nil {156 logger.Fatalf(true, "Failed to read last run information. Reason: %s", err.Error())157 }158 meta := newFailedMetaData()159 if err = json.Unmarshal([]byte(contents), meta); err != nil {160 logger.Fatalf(true, "Invalid last run information. Reason: %s", err.Error())161 }162 return meta163}164var ReadPrevArgs = func() []string {165 contents, err := common.ReadFileContents(filepath.Join(config.ProjectRoot, common.DotGauge, lastRunCmdFileName))166 if err != nil {167 logger.Fatalf(true, "Failed to read previous command information. Reason: %s", err.Error())168 return nil169 }170 var args []string171 if err = json.Unmarshal([]byte(contents), &args); err != nil {172 logger.Fatalf(true, "Invalid previous command information. Reason: %s", err.Error())...

Full Screen

Full Screen

rerun_test.go

Source:rerun_test.go Github

copy

Full Screen

...23var _ = Suite(&MySuite{})24func (s *MySuite) SetUpTest(c *C) {25 p, _ := filepath.Abs("_testdata")26 config.ProjectRoot = p27 failedMeta = newFailedMetaData()28}29func (s *MySuite) TestIfFailedFileIsCreated(c *C) {30 msg := "hello world"31 writeFailedMeta(msg)32 file := filepath.Join(config.ProjectRoot, common.DotGauge, failedFile)33 c.Assert(common.FileExists(file), Equals, true)34 expected := msg35 content, _ := ioutil.ReadFile(file)36 c.Assert(string(content), Equals, expected)37 os.RemoveAll(filepath.Join(config.ProjectRoot, common.DotGauge))38}39func (s *MySuite) TestGetScenarioFailedMetadata(c *C) {40 spec1Rel := filepath.Join("specs", "example1.spec")41 spec1Abs := filepath.Join(config.ProjectRoot, spec1Rel)42 sce := &gauge.Scenario{Span: &gauge.Span{Start: 2}}43 sr1 := &result.ScenarioResult{ProtoScenario: &gauge_messages.ProtoScenario{ExecutionStatus: gauge_messages.ExecutionStatus_FAILED}}44 prepareScenarioFailedMetadata(sr1, sce, &gauge_messages.ExecutionInfo{CurrentSpec: &gauge_messages.SpecInfo{FileName: spec1Abs}})45 c.Assert(len(failedMeta.failedItemsMap[spec1Abs]), Equals, 1)46 c.Assert(failedMeta.failedItemsMap[spec1Abs][spec1Rel+":2"], Equals, true)47}48func (s *MySuite) TestAddSpecPreHookFailedMetadata(c *C) {49 spec1Rel := filepath.Join("specs", "example1.spec")50 spec1Abs := filepath.Join(config.ProjectRoot, spec1Rel)51 spec1 := &result.SpecResult{ProtoSpec: &gauge_messages.ProtoSpec{PreHookFailures: []*gauge_messages.ProtoHookFailure{{ErrorMessage: "error"}}, FileName: spec1Abs}}52 addFailedMetadata(spec1, []string{}, addSpecFailedMetadata)53 c.Assert(len(failedMeta.failedItemsMap[spec1Rel]), Equals, 1)54 c.Assert(failedMeta.failedItemsMap[spec1Rel][spec1Rel], Equals, true)55}56func (s *MySuite) TestAddSpecPostHookFailedMetadata(c *C) {57 spec1Rel := filepath.Join("specs", "example1.spec")58 spec1Abs := filepath.Join(config.ProjectRoot, spec1Rel)59 spec1 := &result.SpecResult{ProtoSpec: &gauge_messages.ProtoSpec{PostHookFailures: []*gauge_messages.ProtoHookFailure{{ErrorMessage: "error"}}, FileName: spec1Abs}}60 addFailedMetadata(spec1, []string{}, addSpecFailedMetadata)61 c.Assert(len(failedMeta.failedItemsMap[spec1Rel]), Equals, 1)62 c.Assert(failedMeta.failedItemsMap[spec1Rel][spec1Rel], Equals, true)63}64func (s *MySuite) TestAddSpecFailedMetadataOverwritesPreviouslyAddedValues(c *C) {65 spec1Rel := filepath.Join("specs", "example1.spec")66 spec1Abs := filepath.Join(config.ProjectRoot, spec1Rel)67 spec1 := &result.SpecResult{ProtoSpec: &gauge_messages.ProtoSpec{PreHookFailures: []*gauge_messages.ProtoHookFailure{{ErrorMessage: "error"}}, FileName: spec1Abs}}68 failedMeta.failedItemsMap[spec1Rel] = make(map[string]bool)69 failedMeta.failedItemsMap[spec1Rel]["scn1"] = true70 failedMeta.failedItemsMap[spec1Rel]["scn2"] = true71 addSpecFailedMetadata(spec1, []string{})72 c.Assert(len(failedMeta.failedItemsMap[spec1Rel]), Equals, 1)73 c.Assert(failedMeta.failedItemsMap[spec1Rel][spec1Rel], Equals, true)74}75func (s *MySuite) TestGetRelativePath(c *C) {76 spec1Rel := filepath.Join("specs", "example1.spec")77 spec1Abs := filepath.Join(config.ProjectRoot, spec1Rel)78 path := util.RelPathToProjectRoot(spec1Abs)79 c.Assert(path, Equals, spec1Rel)80}81func (s *MySuite) TestGetAllFailedItems(c *C) {82 spec1Rel := filepath.Join("specs", "example1.spec")83 spec2Rel := filepath.Join("specs", "example2.spec")84 metaData := newFailedMetaData()85 metaData.failedItemsMap[spec1Rel] = make(map[string]bool)86 metaData.failedItemsMap[spec2Rel] = make(map[string]bool)87 metaData.failedItemsMap[spec1Rel]["scn1"] = true88 metaData.failedItemsMap[spec1Rel]["scn2"] = true89 metaData.failedItemsMap[spec2Rel]["scn3"] = true90 failedItems := metaData.getFailedItems()91 sort.Strings(failedItems)92 c.Assert(failedItems, DeepEquals, []string{"scn1", "scn2", "scn3"})93}...

Full Screen

Full Screen

newFailedMetaData

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, 世界")4}5import "fmt"6func main() {7 fmt.Println("Hello, 世界")8}9import "fmt"10func main() {11 fmt.Println("Hello, 世界")12}13import "fmt"14func main() {15 fmt.Println("Hello, 世界")16}17import "fmt"18func main() {19 fmt.Println("Hello, 世界")20}21import "fmt"22func main() {23 fmt.Println("Hello, 世界")24}25import "fmt"26func main() {27 fmt.Println("Hello, 世界")28}29import "fmt"30func main() {31 fmt.Println("Hello, 世界")32}33import "fmt"34func main() {35 fmt.Println("Hello, 世界")36}37import "fmt"38func main() {39 fmt.Println("Hello, 世界")40}41import "fmt"42func main() {43 fmt.Println("Hello, 世界")44}45import "fmt"46func main() {47 fmt.Println("Hello, 世界")48}

Full Screen

Full Screen

newFailedMetaData

Using AI Code Generation

copy

Full Screen

1import (2type rerun struct {3 failedMetaData map[string]interface{}4}5func (r *rerun) newFailedMetaData() {6 r.failedMetaData = make(map[string]interface{})7}8func main() {9 r.newFailedMetaData()10 fmt.Println("Failed meta data is: ", r.failedMetaData)11 fmt.Println("Type of failed meta data is: ", reflect.TypeOf(r.failedMetaData))12}13Type of failed meta data is: map[string]interface {}14make(map[keyType]valueType, [capacity])15import (16func main() {17 m := make(map[string]int, 10)18 fmt.Println("Map is

Full Screen

Full Screen

newFailedMetaData

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 rerun := &Rerun{}4 rerun.NewFailedMetaData()5}6import (7type Rerun struct {8}9func (r *Rerun) NewFailedMetaData() {10 fmt.Println("NewFailedMetaData")11}12import (13func main() {14 rerun := &Rerun{}15 rerun.NewFailedMetaData()16}17import (18type Rerun struct {19}20func (r *Rerun) NewFailedMetaData() {21 fmt.Println("NewFailedMetaData")22}23import (24func main() {25 rerun := &Rerun{}26 rerun.NewFailedMetaData()27}28import (29type Rerun struct {30}31func (r *Rerun) NewFailedMetaData() {32 fmt.Println("NewFailedMetaData")33}34import (35func main() {36 rerun := &Rerun{}37 rerun.NewFailedMetaData()38}39import (40type Rerun struct {41}42func (r *Rerun) NewFailedMetaData() {43 fmt.Println("NewFailedMetaData")44}45import (46func main() {47 rerun := &Rerun{}48 rerun.NewFailedMetaData()49}

Full Screen

Full Screen

newFailedMetaData

Using AI Code Generation

copy

Full Screen

1import (2type rerun struct {3}4func (r *rerun) newFailedMetaData() map[string]interface{} {5 return map[string]interface{}{6 }7}8func main() {9 var x map[string]interface{}10 x = map[string]interface{}{11 }12 fmt.Println(x["failed"])13 r := rerun{}14 t := reflect.TypeOf(r)15 m := t.MethodByName("newFailedMetaData")16 v := reflect.ValueOf(&r)17 rerunMap := m.Func.Call([]reflect.Value{v})18 fmt.Println(rerunMap[0].Interface().(map[string]interface{})["failed"])19}20import (21type rerun struct {22}23func (r *rerun) newFailedMetaData() map[string]interface{} {24 return map[string]interface{}{25 }26}27func main() {28 var x map[string]interface{}29 x = map[string]interface{}{30 }31 fmt.Println(x["failed"])32 r := rerun{}33 t := reflect.TypeOf(r)34 m := t.MethodByName("newFailedMetaData")35 v := reflect.ValueOf(&r)36 rerunMap := m.Func.Call([]reflect.Value{v})37 fmt.Println(rerunMap[0].Interface().(map[string]interface{})["failed"])38}

Full Screen

Full Screen

newFailedMetaData

Using AI Code Generation

copy

Full Screen

1import (2type rerun struct {3}4type failedMetadata struct {5}6func (r *rerun) newFailedMetadata() *failedMetadata {7 return &failedMetadata{8 }9}10func (r *rerun) newFailedMetadataWithArgs(data string) *failedMetadata {11 return &failedMetadata{12 }13}14func main() {15 r := &rerun{}16 failedMetadata := r.newFailedMetadata()17 fmt.Println(failedMetadata.FailedData)18 failedMetadataWithArgs := r.newFailedMetadataWithArgs("failed with args")19 fmt.Println(failedMetadataWithArgs.FailedData)20}

Full Screen

Full Screen

newFailedMetaData

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd := rerun.NewCmdRerun("oc")4 fmt.Println(cmd)5}6import (7func main() {8 cmd := rerun.NewCmdRerun("oc")9 fmt.Println(cmd)10}11import (12func main() {13 cmd := rerun.NewCmdRerun("oc")14 fmt.Println(cmd)15}16import (17func main() {18 cmd := rerun.NewCmdRerun("oc")19 fmt.Println(cmd)20}21import (22func main() {23 cmd := rerun.NewCmdRerun("oc")24 fmt.Println(cmd)25}26import (27func main() {28 cmd := rerun.NewCmdRerun("oc")29 fmt.Println(cmd)30}31import (32func main() {33 cmd := rerun.NewCmdRerun("oc")34 fmt.Println(cmd)35}

Full Screen

Full Screen

newFailedMetaData

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 rerun := Practice.Rerun{}5 rerun.NewFailedMetaData()6}7import (8func main() {9 fmt.Println("Hello, playground")10 rerun := Practice.Rerun{}11 rerun.NewFailedMetaData()12}13 /usr/local/Cellar/go/1.6/libexec/src/github.com/PranavSinghRawat/GoLang-Practice/Practice (from $GOROOT)14 /Users/pranavrawat/GoLang/src/github.com/PranavSinghRawat/GoLang-Practice/Practice (from $GOPATH)15import (

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful