gitee.com/mirrors/gauge@v1.0.6/execution/result/conceptResult.go (about) 1 // Copyright 2015 ThoughtWorks, Inc. 2 3 // This file is part of Gauge. 4 5 // Gauge is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 10 // Gauge is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 15 // You should have received a copy of the GNU General Public License 16 // along with Gauge. If not, see <http://www.gnu.org/licenses/>. 17 18 package result 19 20 import "github.com/getgauge/gauge/gauge_messages" 21 22 // ConceptResult represents result of a concept execution 23 type ConceptResult struct { 24 ProtoConcept *gauge_messages.ProtoConcept 25 } 26 27 // NewConceptResult creates a ConceptResult with given ProtoConcept 28 func NewConceptResult(con *gauge_messages.ProtoConcept) *ConceptResult { 29 return &ConceptResult{ProtoConcept: con} 30 } 31 32 // SetFailure sets the conceptResult as failed 33 func (conceptResult *ConceptResult) SetFailure() { 34 conceptResult.ProtoConcept.ConceptExecutionResult.ExecutionResult.Failed = true 35 } 36 37 // GetFailed returns the state of the concept result 38 func (conceptResult *ConceptResult) GetFailed() bool { 39 return conceptResult.ProtoConcept.GetConceptExecutionResult().GetExecutionResult().GetFailed() 40 } 41 42 // GetRecoverable returns the state of the concept result 43 func (conceptResult *ConceptResult) GetRecoverable() bool { 44 return conceptResult.ProtoConcept.GetConceptExecutionResult().GetExecutionResult().GetRecoverableError() 45 } 46 47 // ExecTime returns the time taken for concept execution 48 func (conceptResult *ConceptResult) ExecTime() int64 { 49 return conceptResult.ProtoConcept.GetConceptExecutionResult().GetExecutionResult().GetExecutionTime() 50 } 51 52 // SetConceptExecResult sets the conceptExecResult as result of concept execution as well as result of ConceptStep 53 func (conceptResult *ConceptResult) SetConceptExecResult(conceptExecResult *gauge_messages.ProtoStepExecutionResult) { 54 conceptResult.ProtoConcept.ConceptExecutionResult = conceptExecResult 55 conceptResult.ProtoConcept.ConceptStep.StepExecutionResult = conceptExecResult 56 } 57 58 // UpdateConceptExecResult sets the result of Concept execution 59 func (conceptResult *ConceptResult) UpdateConceptExecResult() { 60 var failed, recoverable bool 61 protoConcept := conceptResult.ProtoConcept 62 var conceptExecutionTime int64 63 for _, step := range protoConcept.GetSteps() { 64 if step.GetItemType() == gauge_messages.ProtoItem_Concept { 65 stepExecResult := step.GetConcept().GetConceptExecutionResult().GetExecutionResult() 66 conceptExecutionTime += stepExecResult.GetExecutionTime() 67 if step.GetConcept().GetConceptExecutionResult().GetExecutionResult().GetFailed() { 68 failed = true 69 conceptExecutionResult := &gauge_messages.ProtoStepExecutionResult{ExecutionResult: step.GetConcept().GetConceptExecutionResult().GetExecutionResult(), Skipped: false} 70 conceptExecutionResult.ExecutionResult.ExecutionTime = conceptExecutionTime 71 protoConcept.ConceptExecutionResult = conceptExecutionResult 72 protoConcept.ConceptStep.StepExecutionResult = conceptExecutionResult 73 recoverable = step.GetConcept().GetConceptExecutionResult().GetExecutionResult().GetRecoverableError() 74 if !recoverable { 75 return 76 } 77 } 78 } else if step.GetItemType() == gauge_messages.ProtoItem_Step { 79 stepExecResult := step.GetStep().GetStepExecutionResult().GetExecutionResult() 80 conceptExecutionTime += stepExecResult.GetExecutionTime() 81 if stepExecResult.GetFailed() { 82 failed = true 83 conceptExecutionResult := &gauge_messages.ProtoStepExecutionResult{ExecutionResult: stepExecResult, Skipped: false} 84 conceptExecutionResult.ExecutionResult.ExecutionTime = conceptExecutionTime 85 protoConcept.ConceptExecutionResult = conceptExecutionResult 86 protoConcept.ConceptStep.StepExecutionResult = conceptExecutionResult 87 recoverable = step.GetStep().GetStepExecutionResult().GetExecutionResult().GetRecoverableError() 88 if !recoverable { 89 return 90 } 91 } 92 } 93 } 94 95 conceptResult.SetConceptExecResult(&gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{RecoverableError: recoverable, Failed: failed, ExecutionTime: conceptExecutionTime}}) 96 protoConcept.ConceptStep.StepExecutionResult.Skipped = false 97 } 98 99 func (conceptResult *ConceptResult) GetPreHook() []*gauge_messages.ProtoHookFailure { 100 return nil 101 } 102 103 func (conceptResult *ConceptResult) GetPostHook() []*gauge_messages.ProtoHookFailure { 104 return nil 105 } 106 107 func (conceptResult *ConceptResult) AddPreHook(_ ...*gauge_messages.ProtoHookFailure) { 108 } 109 110 func (conceptResult *ConceptResult) AddPostHook(_ ...*gauge_messages.ProtoHookFailure) { 111 } 112 113 func (conceptResult *ConceptResult) Item() interface{} { 114 return conceptResult.ProtoConcept 115 }