github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/execution/result/scenarioResult.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 ( 21 "github.com/getgauge/gauge/gauge_messages" 22 "github.com/golang/protobuf/proto" 23 ) 24 25 type ScenarioResult struct { 26 ProtoScenario *gauge_messages.ProtoScenario 27 } 28 29 func (scenarioResult *ScenarioResult) SetFailure() { 30 scenarioResult.ProtoScenario.Failed = proto.Bool(true) 31 } 32 33 func (scenarioResult *ScenarioResult) GetFailure() bool { 34 return scenarioResult.ProtoScenario.GetFailed() 35 } 36 37 func (scenarioResult *ScenarioResult) AddItems(protoItems []*gauge_messages.ProtoItem) { 38 scenarioResult.ProtoScenario.ScenarioItems = append(scenarioResult.ProtoScenario.ScenarioItems, protoItems...) 39 } 40 41 func (scenarioResult *ScenarioResult) AddContexts(contextProtoItems []*gauge_messages.ProtoItem) { 42 scenarioResult.ProtoScenario.Contexts = append(scenarioResult.ProtoScenario.Contexts, contextProtoItems...) 43 } 44 45 func (scenarioResult *ScenarioResult) AddTearDownSteps(tearDownProtoItems []*gauge_messages.ProtoItem) { 46 scenarioResult.ProtoScenario.TearDownSteps = append(scenarioResult.ProtoScenario.TearDownSteps, tearDownProtoItems...) 47 } 48 49 func (scenarioResult *ScenarioResult) UpdateExecutionTime() { 50 scenarioResult.updateExecutionTimeFromItems(scenarioResult.ProtoScenario.GetContexts()) 51 scenarioResult.updateExecutionTimeFromItems(scenarioResult.ProtoScenario.GetScenarioItems()) 52 } 53 54 func (scenarioResult *ScenarioResult) AddExecTime(execTime int64) { 55 currentScenarioExecTime := scenarioResult.ProtoScenario.GetExecutionTime() 56 scenarioResult.ProtoScenario.ExecutionTime = proto.Int64(currentScenarioExecTime + execTime) 57 } 58 59 func (scenarioResult *ScenarioResult) updateExecutionTimeFromItems(protoItems []*gauge_messages.ProtoItem) { 60 for _, item := range protoItems { 61 if item.GetItemType() == gauge_messages.ProtoItem_Step { 62 stepExecTime := item.GetStep().GetStepExecutionResult().GetExecutionResult().GetExecutionTime() 63 scenarioResult.AddExecTime(stepExecTime) 64 } else if item.GetItemType() == gauge_messages.ProtoItem_Concept { 65 conceptExecTime := item.GetConcept().GetConceptExecutionResult().GetExecutionResult().GetExecutionTime() 66 scenarioResult.AddExecTime(conceptExecTime) 67 } 68 } 69 } 70 71 func (scenarioResult *ScenarioResult) getPreHook() **(gauge_messages.ProtoHookFailure) { 72 return &scenarioResult.ProtoScenario.PreHookFailure 73 } 74 75 func (scenarioResult *ScenarioResult) getPostHook() **(gauge_messages.ProtoHookFailure) { 76 return &scenarioResult.ProtoScenario.PostHookFailure 77 }