Best Go-testdeep code snippet using td.CmpError
config_test.go
Source:config_test.go
...10 var err error11 from, to, err = parseTCPMapPair("")12 td.CmpDeeply(from, "")13 td.CmpDeeply(to, "")14 td.CmpError(err)15 from, to, err = parseTCPMapPair("a-b")16 td.CmpDeeply(from, "")17 td.CmpDeeply(to, "")18 td.CmpError(err)19 from, to, err = parseTCPMapPair(":123-b")20 td.CmpDeeply(from, "")21 td.CmpDeeply(to, "")22 td.CmpError(err)23 from, to, err = parseTCPMapPair("1.2.3.4-b")24 td.CmpDeeply(from, "")25 td.CmpDeeply(to, "")26 td.CmpError(err)27 from, to, err = parseTCPMapPair("1.2.3.4:123-b")28 td.CmpDeeply(from, "")29 td.CmpDeeply(to, "")30 td.CmpError(err)31 from, to, err = parseTCPMapPair("1.2.3.4:123-2.2.2.2")32 td.CmpDeeply(from, "")33 td.CmpDeeply(to, "")34 td.CmpError(err)35 from, to, err = parseTCPMapPair("1.2.3.4:123-:456")36 td.CmpDeeply(from, "")37 td.CmpDeeply(to, "")38 td.CmpError(err)39 from, to, err = parseTCPMapPair("1.2.3.4:123-2.2.2.2:456")40 td.CmpDeeply(from, "1.2.3.4:123")41 td.CmpDeeply(to, "2.2.2.2:456")42 td.CmpNoError(err)43 from, to, err = parseTCPMapPair("[::1]:123-[::2]:456")44 td.CmpDeeply(from, "[::1]:123")45 td.CmpDeeply(to, "[::2]:456")46 td.CmpNoError(err)47}48func TestConfig_getDefaultTargetDirector(t *testing.T) {49 ctx, flush := th.TestContext(t)50 defer flush()51 td := testdeep.NewT(t)52 var director Director53 var err error54 c := Config{55 DefaultTarget: "",56 }57 director, err = c.getDefaultTargetDirector(ctx)58 td.Nil(director)59 td.CmpError(err)60 c = Config{61 DefaultTarget: "asd",62 }63 director, err = c.getDefaultTargetDirector(ctx)64 td.Nil(director)65 td.CmpError(err)66 c = Config{67 DefaultTarget: ":123",68 }69 director, err = c.getDefaultTargetDirector(ctx)70 td.CmpDeeply(director, NewDirectorSameIP(123))71 td.CmpNoError(err)72 c = Config{73 DefaultTarget: "1.2.3.4",74 }75 director, err = c.getDefaultTargetDirector(ctx)76 td.CmpDeeply(director, NewDirectorHost("1.2.3.4:80"))77 td.CmpNoError(err)78 c = Config{79 DefaultTarget: "::4",80 }81 director, err = c.getDefaultTargetDirector(ctx)82 td.CmpDeeply(director, NewDirectorHost("[::4]:80"))83 td.CmpNoError(err)84 c = Config{85 DefaultTarget: "1.2.3.4:555",86 }87 director, err = c.getDefaultTargetDirector(ctx)88 td.CmpDeeply(director, NewDirectorHost("1.2.3.4:555"))89 td.CmpNoError(err)90}91func TestConfig_getHeadersDirector(t *testing.T) {92 ctx, flush := th.TestContext(t)93 defer flush()94 td := testdeep.NewT(t)95 var director Director96 var err error97 c := Config{98 Headers: []string{},99 }100 director, err = c.getHeadersDirector(ctx)101 td.Nil(director)102 td.CmpNoError(err)103 c = Config{104 Headers: []string{"asd"},105 }106 director, err = c.getHeadersDirector(ctx)107 td.Nil(director)108 td.CmpError(err)109 c = Config{110 Headers: []string{"asd:aaa", "bbb"},111 }112 director, err = c.getHeadersDirector(ctx)113 td.Nil(director)114 td.CmpError(err)115 c = Config{116 Headers: []string{"asd:aaa", "bbb:ccc:hhh", "Ajd:{{qwe}}"},117 }118 director, err = c.getHeadersDirector(ctx)119 td.CmpDeeply(director, NewDirectorSetHeaders(map[string]string{120 "asd": "aaa",121 "bbb": "ccc:hhh",122 "Ajd": "{{qwe}}",123 }))124 td.CmpNoError(err)125}126func TestConfig_getMapDirector(t *testing.T) {127 ctx, flush := th.TestContext(t)128 defer flush()129 td := testdeep.NewT(t)130 var director Director131 var err error132 c := Config{133 TargetMap: []string{},134 }135 director, err = c.getMapDirector(ctx)136 td.Nil(director)137 td.CmpNoError(err)138 c = Config{139 TargetMap: []string{"asd"},140 }141 director, err = c.getMapDirector(ctx)142 td.Nil(director)143 td.CmpError(err)144 c = Config{145 TargetMap: []string{"1.2.3.4-2.3.4.5"},146 }147 director, err = c.getMapDirector(ctx)148 td.Nil(director)149 td.CmpError(err)150 c = Config{151 TargetMap: []string{"1.2.3.4:222-2.3.4.5:333", "asd"},152 }153 director, err = c.getMapDirector(ctx)154 td.Nil(director)155 td.CmpError(err)156 c = Config{157 TargetMap: []string{"1.2.3.4:222-2.3.4.5:333", "[::2]:15-[::5]:91"},158 }159 director, err = c.getMapDirector(ctx)160 td.CmpDeeply(director, NewDirectorDestMap(map[string]string{161 "1.2.3.4:222": "2.3.4.5:333",162 "[::2]:15": "[::5]:91",163 }))164 td.CmpNoError(err)165}166func TestConfig_getSchemeDirector(t *testing.T) {167 ctx, flush := th.TestContext(t)168 defer flush()169 td := testdeep.NewT(t)170 var director Director171 var err error172 c := &Config{173 HTTPSBackend: false,174 }175 director, err = c.getSchemaDirector(ctx)176 td.CmpNoError(err)177 td.CmpDeeply(director, NewSetSchemeDirector(ProtocolHTTP))178 c = &Config{179 HTTPSBackend: true,180 }181 director, err = c.getSchemaDirector(ctx)182 td.CmpNoError(err)183 td.CmpDeeply(director, NewSetSchemeDirector(ProtocolHTTPS))184}185func TestConfig_Apply(t *testing.T) {186 ctx, flush := th.TestContext(t)187 defer flush()188 td := testdeep.NewT(t)189 var err error190 var p = &HTTPProxy{}191 c := Config{}192 err = c.Apply(ctx, p)193 td.CmpError(err)194 c = Config{195 Headers: []string{"aaa:bbb"},196 }197 p = &HTTPProxy{}198 err = c.Apply(ctx, p)199 td.CmpError(err)200 c = Config{201 DefaultTarget: ":94",202 Headers: []string{"aaa:bbb"},203 }204 p = &HTTPProxy{}205 err = c.Apply(ctx, p)206 td.CmpNoError(err)207 td.CmpDeeply(p.Director,208 NewDirectorChain(209 NewDirectorSameIP(94),210 NewDirectorSetHeaders(map[string]string{"aaa": "bbb"}),211 NewSetSchemeDirector(ProtocolHTTP),212 ),213 )...
types_test.go
Source:types_test.go
...12 t.CmpDeeply(str, "1.2")13 t.CmpNoError(err)14 str, err = TypeDouble.Human2VitodataValue("foo")15 t.Empty(str)16 t.CmpError(err)17 // Vitodata2HumanValue18 str, err = TypeDouble.Vitodata2HumanValue("1.200")19 t.CmpDeeply(str, "1.2")20 t.CmpNoError(err)21 str, err = TypeDouble.Vitodata2HumanValue("foo")22 t.Empty(str)23 t.CmpError(err)24 // Vitodata2NativeValue25 num, err := TypeDouble.Vitodata2NativeValue("1.200")26 t.CmpDeeply(num, float64(1.2))27 t.CmpNoError(err)28 num, err = TypeDouble.Vitodata2NativeValue("foo")29 t.Nil(num)30 t.CmpError(err)31}32func TestVitodataInteger(tt *testing.T) {33 t := td.NewT(tt)34 t.CmpDeeply(TypeInteger.Type(), "Integer")35 // Human2VitodataValue36 str, err := TypeInteger.Human2VitodataValue("12")37 t.CmpDeeply(str, "12")38 t.CmpNoError(err)39 str, err = TypeInteger.Human2VitodataValue("foo")40 t.Empty(str)41 t.CmpError(err)42 // Vitodata2HumanValue43 str, err = TypeInteger.Vitodata2HumanValue("00012")44 t.CmpDeeply(str, "12")45 t.CmpNoError(err)46 str, err = TypeInteger.Vitodata2HumanValue("foo")47 t.Empty(str)48 t.CmpError(err)49 // Vitodata2NativeValue50 num, err := TypeInteger.Vitodata2NativeValue("00012")51 t.CmpDeeply(num, int64(12))52 t.CmpNoError(err)53 num, err = TypeInteger.Vitodata2NativeValue("foo")54 t.Nil(num)55 t.CmpError(err)56}57func TestVitodataDate(tt *testing.T) {58 t := td.NewT(tt)59 t.CmpDeeply(TypeDate.Type(), "Date")60 const refDate = "2016-09-26 11:22:33"61 // Human2VitodataValue62 str, err := TypeDate.Human2VitodataValue(refDate)63 t.CmpDeeply(str, refDate)64 t.CmpNoError(err)65 str, err = TypeDate.Human2VitodataValue("foo")66 t.Empty(str)67 t.CmpError(err)68 // Vitodata2HumanValue69 str, err = TypeDate.Vitodata2HumanValue(refDate)70 t.CmpDeeply(str, refDate)71 t.CmpNoError(err)72 str, err = TypeDate.Vitodata2HumanValue("foo")73 t.Empty(str)74 t.CmpError(err)75 // Vitodata2NativeValue76 date, err := TypeDate.Vitodata2NativeValue(refDate)77 t.CmpDeeply(78 date,79 Time(time.Date(2016, time.September, 26, 11, 22, 33, 0, vitodataTZ)))80 t.CmpNoError(err)81 date, err = TypeDate.Vitodata2NativeValue("foo")82 t.Nil(date)83 t.CmpError(err)84}85func TestVitodataString(tt *testing.T) {86 t := td.NewT(tt)87 t.CmpDeeply(TypeString.Type(), "String")88 const refString = "foobar"89 // Human2VitodataValue90 str, err := TypeString.Human2VitodataValue(refString)91 t.CmpDeeply(str, refString)92 t.CmpNoError(err)93 // Vitodata2HumanValue94 str, err = TypeString.Vitodata2HumanValue(refString)95 t.CmpDeeply(str, refString)96 t.CmpNoError(err)97 // Vitodata2NativeValue98 strIf, err := TypeString.Vitodata2NativeValue(refString)99 t.CmpDeeply(strIf, refString)100 t.CmpNoError(err)101}102func TestVitodataEnum(tt *testing.T) {103 t := td.NewT(tt)104 typeEnumTest := NewEnum([]string{105 "zero",106 "one",107 "two",108 })109 t.CmpDeeply(typeEnumTest.Type(), "Enum3")110 // Human2VitodataValue111 str, err := typeEnumTest.Human2VitodataValue("one")112 t.CmpDeeply(str, "1")113 t.CmpNoError(err)114 str, err = typeEnumTest.Human2VitodataValue("1")115 t.CmpDeeply(str, "1")116 t.CmpNoError(err)117 str, err = typeEnumTest.Human2VitodataValue("foo")118 t.Empty(str)119 t.CmpError(err)120 // Vitodata2HumanValue121 str, err = typeEnumTest.Vitodata2HumanValue("2")122 t.CmpDeeply(str, "two")123 t.CmpNoError(err)124 str, err = typeEnumTest.Vitodata2HumanValue("42")125 t.Empty(str)126 t.CmpDeeply(err, ErrEnumInvalidValue)127 str, err = typeEnumTest.Vitodata2HumanValue("foo")128 t.Empty(str)129 t.CmpDeeply(err, ErrEnumInvalidValue)130 // Vitodata2NativeValue131 num, err := typeEnumTest.Vitodata2NativeValue("1")132 t.CmpDeeply(num, uint64(1))133 t.CmpNoError(err)...
apply_test.go
Source:apply_test.go
...21 expected := `{"foo":"Hello -> 12"}`22 td.Cmp(t, string(result), expected)23 h = json.RawMessage(`{"foo": "{{ .input.ifoo1}} -> {{.input.ifoo3.notexisting }}"}`)24 result, err = resolveObject(v, h, nil, "")25 if !td.CmpError(t, err) {26 return27 }28 td.CmpContains(t, err.Error(), "can't evaluate field notexisting in type interface")29}30func TestApplyNested(t *testing.T) {31 assert, require := td.AssertRequire(t)32 v := values.NewValues()33 v.SetInput(map[string]interface{}{34 "ifoo1": "Hello",35 "ifoo2": true,36 "ifoo3": 12,37 "ifoo4": []string{"Hello", "you!"},38 })39 h := json.RawMessage(`{"fooo":{"foo": "{{ .input.ifoo1}} -> {{.input.ifoo3 }}","array":["{{.input.ifoo2}}"]}}`)40 result, err := resolveObject(v, h, nil, "")41 require.CmpNoError(err)42 expected := `{"fooo":{"array":["true"],"foo":"Hello -> 12"}}`43 assert.Cmp(string(result), expected)44 h = json.RawMessage(`{"fooo":{"foo": "{{ .input.ifoo1}} -> {{.input.ifoo3.notexisting }}"}}`)45 result, err = resolveObject(v, h, nil, "")46 require.CmpError(err)47 assert.Contains(err.Error(), "can't evaluate field notexisting in type interface")48}49func TestApplyArray(t *testing.T) {50 assert, require := td.AssertRequire(t)51 v := values.NewValues()52 v.SetInput(map[string]interface{}{53 "ifoo1": "Hello",54 "ifoo2": true,55 "ifoo3": 12,56 "ifoo4": []string{"Hello", "you!"},57 })58 h := json.RawMessage(`["fooo",{"foo": "{{ .input.ifoo1}} -> {{.input.ifoo3 }}","array":["{{.input.ifoo2}}"]}]`)59 result, err := resolveObject(v, h, nil, "")60 require.CmpNoError(err)61 expected := `["fooo",{"array":["true"],"foo":"Hello -> 12"}]`62 assert.Cmp(string(result), expected)63 h = json.RawMessage(`["fooo",{"foo": "{{ .input.ifoo1}} -> {{.input.ifoo3.notexisting }}"}]`)64 result, err = resolveObject(v, h, nil, "")65 require.CmpError(err)66 assert.Contains(err.Error(), "can't evaluate field notexisting in type interface")67}...
CmpError
Using AI Code Generation
1import "fmt"2import "math"3type td struct {4}5func (z td) CmpError() float64 {6return math.Hypot(z.re, z.im)7}8func main() {9z := td{3, 4}10fmt.Println(z.CmpError())11}
CmpError
Using AI Code Generation
1import (2func main() {3 fmt.Println(duration)4 fmt.Println(duration)5 fmt.Println(duration)6}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!