gitee.com/mirrors/gauge@v1.0.6/execution/result/conceptResult_test.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  	"testing"
    22  
    23  	"github.com/getgauge/gauge/gauge_messages"
    24  	gc "gopkg.in/check.v1"
    25  )
    26  
    27  func Test(t *testing.T) { gc.TestingT(t) }
    28  
    29  type MySuite struct{}
    30  
    31  var _ = gc.Suite(&MySuite{})
    32  
    33  func (s *MySuite) TestUpdateConceptExecutionResultWithARecoverableStep(c *gc.C) {
    34  	cptStep := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}
    35  	item1 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}}
    36  	step2Res := &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{RecoverableError: true, Failed: true}}
    37  	item2 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: step2Res}}
    38  	item3 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}}
    39  	cptRes := NewConceptResult(&gauge_messages.ProtoConcept{ConceptStep: cptStep, Steps: []*gauge_messages.ProtoItem{item1, item2, item3}})
    40  
    41  	cptRes.UpdateConceptExecResult()
    42  
    43  	c.Assert(cptRes.GetFailed(), gc.Equals, true)
    44  	c.Assert(cptRes.GetRecoverable(), gc.Equals, true)
    45  }
    46  
    47  func (s *MySuite) TestUpdateConceptExecutionResultWithNonRecoverableFailure(c *gc.C) {
    48  	cptStep := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}
    49  	item1 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}}
    50  	step2Res := &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{Failed: true, ErrorMessage: "step failure"}}
    51  	item2 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: step2Res}}
    52  	item3 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}}
    53  	cptRes := NewConceptResult(&gauge_messages.ProtoConcept{ConceptStep: cptStep, Steps: []*gauge_messages.ProtoItem{item1, item2, item3}})
    54  
    55  	cptRes.UpdateConceptExecResult()
    56  
    57  	c.Assert(cptRes.GetFailed(), gc.Equals, true)
    58  	c.Assert(cptRes.GetRecoverable(), gc.Equals, false)
    59  	c.Assert(cptRes.ProtoConcept.GetConceptExecutionResult().GetExecutionResult().GetErrorMessage(), gc.Equals, "step failure")
    60  }
    61  
    62  func (s *MySuite) TestUpdateConceptExecutionResultWithRecoverableAndNonRecoverableSteps(c *gc.C) {
    63  	cptStep := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}
    64  	step1Res := &gauge_messages.ProtoExecutionResult{Failed: true, RecoverableError: true, ErrorMessage: "a recoverable step"}
    65  	item1 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: step1Res}}}
    66  	step2Res := &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{Failed: true, ErrorMessage: "step failure"}}
    67  	item2 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: step2Res}}
    68  	item3 := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Step, Step: &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{}}}}
    69  	cptRes := NewConceptResult(&gauge_messages.ProtoConcept{ConceptStep: cptStep, Steps: []*gauge_messages.ProtoItem{item1, item2, item3}})
    70  
    71  	cptRes.UpdateConceptExecResult()
    72  
    73  	c.Assert(cptRes.GetFailed(), gc.Equals, true)
    74  	c.Assert(cptRes.GetRecoverable(), gc.Equals, false)
    75  	c.Assert(cptRes.ProtoConcept.GetConceptExecutionResult().GetExecutionResult().GetErrorMessage(), gc.Equals, "step failure")
    76  }