github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/gauge/arg_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 gauge 19 20 import . "gopkg.in/check.v1" 21 22 func (s *MySuite) TestLookupaddArg(c *C) { 23 lookup := new(ArgLookup) 24 lookup.AddArgName("param1") 25 lookup.AddArgName("param2") 26 27 c.Assert(lookup.ParamIndexMap["param1"], Equals, 0) 28 c.Assert(lookup.ParamIndexMap["param2"], Equals, 1) 29 c.Assert(len(lookup.paramValue), Equals, 2) 30 c.Assert(lookup.paramValue[0].name, Equals, "param1") 31 c.Assert(lookup.paramValue[1].name, Equals, "param2") 32 33 } 34 35 func (s *MySuite) TestLookupContainsArg(c *C) { 36 lookup := new(ArgLookup) 37 lookup.AddArgName("param1") 38 lookup.AddArgName("param2") 39 40 c.Assert(lookup.ContainsArg("param1"), Equals, true) 41 c.Assert(lookup.ContainsArg("param2"), Equals, true) 42 c.Assert(lookup.ContainsArg("param3"), Equals, false) 43 } 44 45 func (s *MySuite) TestAddArgValue(c *C) { 46 lookup := new(ArgLookup) 47 lookup.AddArgName("param1") 48 lookup.AddArgValue("param1", &StepArg{Value: "value1", ArgType: Static}) 49 lookup.AddArgName("param2") 50 lookup.AddArgValue("param2", &StepArg{Value: "value2", ArgType: Dynamic}) 51 52 c.Assert(lookup.GetArg("param1").Value, Equals, "value1") 53 c.Assert(lookup.GetArg("param2").Value, Equals, "value2") 54 } 55 56 func (s *MySuite) TestPanicForInvalidArg(c *C) { 57 lookup := new(ArgLookup) 58 59 c.Assert(func() { lookup.AddArgValue("param1", &StepArg{Value: "value1", ArgType: Static}) }, Panics, "Accessing an invalid parameter (param1)") 60 c.Assert(func() { lookup.GetArg("param1") }, Panics, "Accessing an invalid parameter (param1)") 61 } 62 63 func (s *MySuite) TestGetLookupCopy(c *C) { 64 originalLookup := new(ArgLookup) 65 originalLookup.AddArgName("param1") 66 originalLookup.AddArgValue("param1", &StepArg{Value: "oldValue", ArgType: Dynamic}) 67 68 copiedLookup := originalLookup.GetCopy() 69 copiedLookup.AddArgValue("param1", &StepArg{Value: "new value", ArgType: Static}) 70 71 c.Assert(copiedLookup.GetArg("param1").Value, Equals, "new value") 72 c.Assert(originalLookup.GetArg("param1").Value, Equals, "oldValue") 73 } 74 75 func (s *MySuite) TestGetLookupFromTableRow(c *C) { 76 dataTable := new(Table) 77 dataTable.AddHeaders([]string{"id", "name"}) 78 dataTable.AddRowValues([]string{"1", "admin"}) 79 dataTable.AddRowValues([]string{"2", "root"}) 80 81 emptyLookup := new(ArgLookup).FromDataTableRow(new(Table), 0) 82 lookup1 := new(ArgLookup).FromDataTableRow(dataTable, 0) 83 lookup2 := new(ArgLookup).FromDataTableRow(dataTable, 1) 84 85 c.Assert(emptyLookup.ParamIndexMap, IsNil) 86 87 c.Assert(lookup1.GetArg("id").Value, Equals, "1") 88 c.Assert(lookup1.GetArg("id").ArgType, Equals, Static) 89 c.Assert(lookup1.GetArg("name").Value, Equals, "admin") 90 c.Assert(lookup1.GetArg("name").ArgType, Equals, Static) 91 92 c.Assert(lookup2.GetArg("id").Value, Equals, "2") 93 c.Assert(lookup2.GetArg("id").ArgType, Equals, Static) 94 c.Assert(lookup2.GetArg("name").Value, Equals, "root") 95 c.Assert(lookup2.GetArg("name").ArgType, Equals, Static) 96 }