gitee.com/mirrors/gauge@v1.0.6/execution/execute_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 execution 19 20 import ( 21 "fmt" 22 23 "github.com/getgauge/gauge/gauge" 24 25 . "gopkg.in/check.v1" 26 ) 27 28 type testLogger struct { 29 output string 30 } 31 32 func (l *testLogger) Write(b []byte) (int, error) { 33 l.output = string(b) 34 return len(b), nil 35 } 36 37 func (s *MySuite) TestFunctionsOfTypeSpecList(c *C) { 38 mySpecs := gauge.NewSpecCollection(createSpecsList(4), false) 39 c.Assert(mySpecs.Next()[0].FileName, Equals, "spec0") 40 c.Assert(mySpecs.Next()[0].FileName, Equals, "spec1") 41 c.Assert(mySpecs.HasNext(), Equals, true) 42 c.Assert(mySpecs.Size(), Equals, 4) 43 c.Assert(mySpecs.Next()[0].FileName, Equals, "spec2") 44 c.Assert(mySpecs.Next()[0].FileName, Equals, "spec3") 45 c.Assert(mySpecs.HasNext(), Equals, false) 46 } 47 48 func createSpecsList(number int) []*gauge.Specification { 49 var specs []*gauge.Specification 50 for i := 0; i < number; i++ { 51 specs = append(specs, &gauge.Specification{FileName: fmt.Sprint("spec", i)}) 52 } 53 return specs 54 } 55 56 func (s *MySuite) TestValidateFlagsIfNotParallel(c *C) { 57 InParallel = false 58 err := validateFlags() 59 c.Assert(err, Equals, nil) 60 } 61 62 func (s *MySuite) TestValidateFlagsWithStartegyEager(c *C) { 63 InParallel = true 64 Strategy = "eager" 65 NumberOfExecutionStreams = 1 66 err := validateFlags() 67 c.Assert(err, Equals, nil) 68 } 69 70 func (s *MySuite) TestValidateFlagsWithStartegyLazy(c *C) { 71 InParallel = true 72 Strategy = "lazy" 73 NumberOfExecutionStreams = 1 74 err := validateFlags() 75 c.Assert(err, Equals, nil) 76 } 77 78 func (s *MySuite) TestValidateFlagsWithInvalidStrategy(c *C) { 79 InParallel = true 80 Strategy = "sdf" 81 NumberOfExecutionStreams = 1 82 err := validateFlags() 83 c.Assert(err.Error(), Equals, "invalid input(sdf) to --strategy flag") 84 } 85 86 func (s *MySuite) TestValidateFlagsWithInvalidStream(c *C) { 87 InParallel = true 88 NumberOfExecutionStreams = -1 89 err := validateFlags() 90 c.Assert(err.Error(), Equals, "invalid input(-1) to --n flag") 91 }