How to use mustContain method of td_test Package

Best Go-testdeep code snippet using td_test.mustContain

td_struct_test.go

Source:td_struct_test.go Github

copy

Full Screen

...56 td.Struct(&MyStruct{}, td.StructFields{}),57 expectedError{58 Message: mustBe("type mismatch"),59 Path: mustBe("DATA"),60 Got: mustContain("int"),61 Expected: mustContain("*td_test.MyStruct"),62 })63 checkError(t, &MyStructBase{},64 td.Struct(&MyStruct{}, td.StructFields{}),65 expectedError{66 Message: mustBe("type mismatch"),67 Path: mustBe("DATA"),68 Got: mustContain("*td_test.MyStructBase"),69 Expected: mustContain("*td_test.MyStruct"),70 })71 checkError(t, &gotStruct,72 td.Struct(&MyStruct{}, td.StructFields{73 "ValBool": false, // ← does not match74 "ValStr": "foobar",75 "ValInt": 123,76 }),77 expectedError{78 Message: mustBe("values differ"),79 Path: mustBe("DATA.ValBool"),80 Got: mustContain("true"),81 Expected: mustContain("false"),82 })83 checkOK(t, &gotStruct,84 td.Struct(&MyStruct{85 MyStructMid: MyStructMid{86 MyStructBase: MyStructBase{87 ValBool: true,88 },89 ValStr: "foobar",90 },91 ValInt: 123,92 }, nil))93 checkError(t, &gotStruct,94 td.Struct(&MyStruct{95 MyStructMid: MyStructMid{96 MyStructBase: MyStructBase{97 ValBool: true,98 },99 ValStr: "foobax", // ← does not match100 },101 ValInt: 123,102 }, nil),103 expectedError{104 Message: mustBe("values differ"),105 Path: mustBe("DATA.ValStr"),106 Got: mustContain("foobar"),107 Expected: mustContain("foobax"),108 })109 // Zero values110 checkOK(t, &MyStruct{},111 td.Struct(&MyStruct{}, td.StructFields{112 "ValBool": false,113 "ValStr": "",114 "ValInt": 0,115 }))116 // nil cases117 checkError(t, nil, td.Struct(&MyStruct{}, nil),118 expectedError{119 Message: mustBe("values differ"),120 Path: mustBe("DATA"),121 Got: mustContain("nil"),122 Expected: mustContain("*td_test.MyStruct"),123 })124 checkError(t, (*MyStruct)(nil), td.Struct(&MyStruct{}, nil),125 expectedError{126 Message: mustBe("values differ"),127 Path: mustBe("DATA"),128 Got: mustContain("nil"),129 Expected: mustBe("non-nil"),130 })131 //132 // Without pointer133 checkOK(t, gotStruct,134 td.Struct(MyStruct{}, td.StructFields{135 "ValBool": true,136 "ValStr": "foobar",137 "ValInt": 123,138 }))139 checkOK(t, gotStruct,140 td.Struct(141 MyStruct{142 MyStructMid: MyStructMid{143 ValStr: "zip",144 },145 ValInt: 666,146 },147 td.StructFields{148 "ValBool": true,149 "> ValStr": "foobar",150 ">ValInt": 123,151 }))152 checkError(t, 123, td.Struct(MyStruct{}, td.StructFields{}),153 expectedError{154 Message: mustBe("type mismatch"),155 Path: mustBe("DATA"),156 Got: mustContain("int"),157 Expected: mustContain("td_test.MyStruct"),158 })159 checkError(t, gotStruct,160 td.Struct(MyStruct{}, td.StructFields{161 "ValBool": false, // ← does not match162 "ValStr": "foobar",163 "ValInt": 123,164 }),165 expectedError{166 Message: mustBe("values differ"),167 Path: mustBe("DATA.ValBool"),168 Got: mustContain("true"),169 Expected: mustContain("false"),170 })171 checkOK(t, gotStruct,172 td.Struct(MyStruct{173 MyStructMid: MyStructMid{174 MyStructBase: MyStructBase{175 ValBool: true,176 },177 ValStr: "foobar",178 },179 ValInt: 123,180 }, nil))181 checkError(t, gotStruct,182 td.Struct(MyStruct{183 MyStructMid: MyStructMid{184 MyStructBase: MyStructBase{185 ValBool: true,186 },187 ValStr: "foobax", // ← does not match188 },189 ValInt: 123,190 }, nil),191 expectedError{192 Message: mustBe("values differ"),193 Path: mustBe("DATA.ValStr"),194 Got: mustContain("foobar"),195 Expected: mustContain("foobax"),196 })197 // Zero values198 checkOK(t, MyStruct{},199 td.Struct(MyStruct{}, td.StructFields{200 "ValBool": false,201 "ValStr": "",202 "ValInt": 0,203 }))204 // nil cases205 checkError(t, nil, td.Struct(MyStruct{}, nil),206 expectedError{207 Message: mustBe("values differ"),208 Path: mustBe("DATA"),209 Got: mustContain("nil"),210 Expected: mustContain("td_test.MyStruct"),211 })212 checkError(t, (*MyStruct)(nil), td.Struct(MyStruct{}, nil),213 expectedError{214 Message: mustBe("type mismatch"),215 Path: mustBe("DATA"),216 Got: mustBe("*td_test.MyStruct"),217 Expected: mustBe("td_test.MyStruct"),218 })219 //220 // Be lax...221 type Struct1 struct {222 name string223 age int224 }225 type Struct2 struct {226 name string227 age int228 }229 // Without Lax → error230 checkError(t,231 Struct1{name: "Bob", age: 42},232 td.Struct(Struct2{name: "Bob", age: 42}, nil),233 expectedError{234 Message: mustBe("type mismatch"),235 })236 // With Lax → OK237 checkOK(t,238 Struct1{name: "Bob", age: 42},239 td.Lax(td.Struct(Struct2{name: "Bob", age: 42}, nil)))240 //241 // IgnoreUnexported242 t.Run("IgnoreUnexported", func(tt *testing.T) {243 type SType struct {244 Public int245 private string246 }247 got := SType{Public: 42, private: "test"}248 expected := td.Struct(SType{Public: 42, private: "zip"}, nil)249 checkError(tt, got, expected,250 expectedError{251 Message: mustBe("values differ"),252 Path: mustBe("DATA.private"),253 Got: mustBe(`"test"`),254 Expected: mustBe(`"zip"`),255 })256 // Ignore unexported globally257 defer func() { td.DefaultContextConfig.IgnoreUnexported = false }()258 td.DefaultContextConfig.IgnoreUnexported = true259 checkOK(tt, got, expected)260 td.DefaultContextConfig.IgnoreUnexported = false261 ttt := test.NewTestingTB(t.Name())262 t := td.NewT(ttt).IgnoreUnexported(SType{}) // ignore only for SType263 test.IsTrue(tt, t.Cmp(got, expected))264 })265 //266 // Bad usage267 checkError(t, "never tested",268 td.Struct("test", nil),269 expectedError{270 Message: mustBe("bad usage of Struct operator"),271 Path: mustBe("DATA"),272 Summary: mustBe("usage: Struct(STRUCT|&STRUCT, EXPECTED_FIELDS), but received string as 1st parameter"),273 })274 i := 12275 checkError(t, "never tested",276 td.Struct(&i, nil),277 expectedError{278 Message: mustBe("bad usage of Struct operator"),279 Path: mustBe("DATA"),280 Summary: mustBe("usage: Struct(STRUCT|&STRUCT, EXPECTED_FIELDS), but received *int (ptr) as 1st parameter"),281 })282 checkError(t, "never tested",283 td.Struct(&MyStruct{}, td.StructFields{"UnknownField": 123}),284 expectedError{285 Message: mustBe("bad usage of Struct operator"),286 Path: mustBe("DATA"),287 Summary: mustBe(`struct td_test.MyStruct has no field "UnknownField"`),288 })289 checkError(t, "never tested",290 td.Struct(&MyStruct{}, td.StructFields{">\tUnknownField": 123}),291 expectedError{292 Message: mustBe("bad usage of Struct operator"),293 Path: mustBe("DATA"),294 Summary: mustBe(`struct td_test.MyStruct has no field "UnknownField" (from ">\tUnknownField")`),295 })296 checkError(t, "never tested",297 td.Struct(&MyStruct{}, td.StructFields{"ValBool": 123}),298 expectedError{299 Message: mustBe("bad usage of Struct operator"),300 Path: mustBe("DATA"),301 Summary: mustBe("type int of field expected value ValBool differs from struct one (bool)"),302 })303 checkError(t, "never tested",304 td.Struct(&MyStruct{}, td.StructFields{">ValBool": 123}),305 expectedError{306 Message: mustBe("bad usage of Struct operator"),307 Path: mustBe("DATA"),308 Summary: mustBe(`type int of field expected value ValBool (from ">ValBool") differs from struct one (bool)`),309 })310 checkError(t, "never tested",311 td.Struct(&MyStruct{}, td.StructFields{"ValBool": nil}),312 expectedError{313 Message: mustBe("bad usage of Struct operator"),314 Path: mustBe("DATA"),315 Summary: mustBe("expected value of field ValBool cannot be nil as it is a bool"),316 })317 checkError(t, "never tested",318 td.Struct(&MyStruct{319 MyStructMid: MyStructMid{320 MyStructBase: MyStructBase{321 ValBool: true,322 },323 },324 },325 td.StructFields{"ValBool": false}),326 expectedError{327 Message: mustBe("bad usage of Struct operator"),328 Path: mustBe("DATA"),329 Summary: mustBe("non zero field ValBool in model already exists in expectedFields"),330 })331 //332 // String333 test.EqualStr(t,334 td.Struct(MyStruct{335 MyStructMid: MyStructMid{336 ValStr: "foobar",337 },338 ValInt: 123,339 },340 td.StructFields{341 "ValBool": false,342 }).String(),343 `Struct(td_test.MyStruct{344 ValBool: false345 ValInt: 123346 ValStr: "foobar"347})`)348 test.EqualStr(t,349 td.Struct(&MyStruct{350 MyStructMid: MyStructMid{351 ValStr: "foobar",352 },353 ValInt: 123,354 },355 td.StructFields{356 "ValBool": false,357 }).String(),358 `Struct(*td_test.MyStruct{359 ValBool: false360 ValInt: 123361 ValStr: "foobar"362})`)363 test.EqualStr(t,364 td.Struct(&MyStruct{}, td.StructFields{}).String(),365 `Struct(*td_test.MyStruct{})`)366 // Erroneous op367 test.EqualStr(t, td.Struct("test", nil).String(), "Struct(<ERROR>)")368}369func TestStructPrivateFields(t *testing.T) {370 type privateKey struct {371 num int372 name string373 }374 type privateValue struct {375 value string376 weight int377 }378 type MyTime time.Time379 type structPrivateFields struct {380 byKey map[privateKey]*privateValue381 name string382 nameb []byte383 err error384 iface any385 properties []int386 birth time.Time387 birth2 MyTime388 next *structPrivateFields389 }390 d := func(rfc3339Date string) (ret time.Time) {391 var err error392 ret, err = time.Parse(time.RFC3339Nano, rfc3339Date)393 if err != nil {394 panic(err)395 }396 return397 }398 got := structPrivateFields{399 byKey: map[privateKey]*privateValue{400 {num: 1, name: "foo"}: {value: "test", weight: 12},401 {num: 2, name: "bar"}: {value: "tset", weight: 23},402 {num: 3, name: "zip"}: {value: "ttse", weight: 34},403 },404 name: "foobar",405 nameb: []byte("foobar"),406 err: errors.New("the error"),407 iface: 1234,408 properties: []int{20, 22, 23, 21},409 birth: d("2018-04-01T10:11:12.123456789Z"),410 birth2: MyTime(d("2018-03-01T09:08:07.987654321Z")),411 next: &structPrivateFields{412 byKey: map[privateKey]*privateValue{},413 name: "sub",414 iface: bytes.NewBufferString("buffer!"),415 birth: d("2018-04-02T10:11:12.123456789Z"),416 birth2: MyTime(d("2018-03-02T09:08:07.987654321Z")),417 },418 }419 checkOK(t, got,420 td.Struct(structPrivateFields{}, td.StructFields{421 "name": "foobar",422 }))423 checkOK(t, got,424 td.Struct(structPrivateFields{}, td.StructFields{425 "name": td.Re("^foo"),426 }))427 checkOK(t, got,428 td.Struct(structPrivateFields{}, td.StructFields{429 "nameb": td.Re("^foo"),430 }))431 checkOKOrPanicIfUnsafeDisabled(t, got,432 td.Struct(structPrivateFields{}, td.StructFields{433 "err": td.Re("error"),434 }))435 checkError(t, got,436 td.Struct(structPrivateFields{}, td.StructFields{437 "iface": td.Re("buffer"),438 }),439 expectedError{440 Message: mustBe("bad type"),441 Path: mustBe("DATA.iface"),442 Got: mustBe("int"),443 Expected: mustBe("string (convertible) OR fmt.Stringer OR error OR []uint8"),444 })445 checkOKOrPanicIfUnsafeDisabled(t, got,446 td.Struct(structPrivateFields{}, td.StructFields{447 "next": td.Struct(&structPrivateFields{}, td.StructFields{448 "iface": td.Re("buffer"),449 }),450 }))451 checkOK(t, got,452 td.Struct(structPrivateFields{}, td.StructFields{453 "properties": []int{20, 22, 23, 21},454 }))455 checkOK(t, got,456 td.Struct(structPrivateFields{}, td.StructFields{457 "properties": td.ArrayEach(td.Between(20, 23)),458 }))459 checkOK(t, got,460 td.Struct(structPrivateFields{}, td.StructFields{461 "byKey": td.MapEach(td.Struct(&privateValue{}, td.StructFields{462 "weight": td.Between(12, 34),463 "value": td.Any(td.HasPrefix("t"), td.HasSuffix("e")),464 })),465 }))466 checkOK(t, got,467 td.Struct(structPrivateFields{}, td.StructFields{468 "byKey": td.SuperMapOf(469 map[privateKey]*privateValue{470 {num: 3, name: "zip"}: {value: "ttse", weight: 34},471 },472 td.MapEntries{473 privateKey{num: 2, name: "bar"}: &privateValue{value: "tset", weight: 23},474 }),475 }))476 expected := td.Struct(structPrivateFields{}, td.StructFields{477 "birth": td.TruncTime(d("2018-04-01T10:11:12Z"), time.Second),478 "birth2": td.TruncTime(MyTime(d("2018-03-01T09:08:07Z")), time.Second),479 })480 if !dark.UnsafeDisabled {481 checkOK(t, got, expected)482 } else {483 checkError(t, got, expected,484 expectedError{485 Message: mustBe("cannot compare"),486 Path: mustBe("DATA.birth"),487 Summary: mustBe("unexported field that cannot be overridden"),488 })489 }490 checkError(t, got,491 td.Struct(structPrivateFields{}, td.StructFields{492 "next": td.Struct(&structPrivateFields{}, td.StructFields{493 "name": "sub",494 "birth": td.Code(func(t time.Time) bool { return true }),495 }),496 }),497 expectedError{498 Message: mustBe("cannot compare unexported field"),499 Path: mustBe("DATA.next.birth"),500 Summary: mustBe("use Code() on surrounding struct instead"),501 })502 checkError(t, got,503 td.Struct(structPrivateFields{}, td.StructFields{504 "next": td.Struct(&structPrivateFields{}, td.StructFields{505 "name": "sub",506 "birth": td.Smuggle(507 func(t time.Time) string { return t.String() },508 "2018-04-01T10:11:12.123456789Z"),509 }),510 }),511 expectedError{512 Message: mustBe("cannot smuggle unexported field"),513 Path: mustBe("DATA.next.birth"),514 Summary: mustBe("work on surrounding struct instead"),515 })516}517func TestStructPatterns(t *testing.T) {518 type paAnon struct {519 alphaNum int520 betaNum int521 }522 type paTest struct {523 paAnon524 Num int525 }526 got := paTest{527 paAnon: paAnon{528 alphaNum: 1000,529 betaNum: 2000,530 },531 Num: 666,532 }533 t.Run("Shell pattern", func(t *testing.T) {534 checkOK(t, got,535 td.Struct(paTest{Num: 666},536 td.StructFields{537 "=*Num": td.Gte(1000), // matches alphaNum & betaNum538 }))539 checkOK(t, got,540 td.Struct(paTest{Num: 666},541 td.StructFields{542 "=a*Num": td.Lt(0), // no remaining fields to match543 "=*": td.Gte(1000), // first, matches alphaNum & betaNum544 "=b*Num": td.Lt(0), // no remaining fields to match545 }),546 "Default sorting uses patterns")547 checkOK(t, got,548 td.Struct(paTest{Num: 666},549 td.StructFields{550 "1 = a*Num": td.Between(999, 1001), // matches alphaNum551 "2 = *": td.Gte(2000), // matches betaNum552 "3 = b*Num": td.Gt(3000), // no remaining fields to match553 }),554 "Explicitly sorted")555 checkOK(t, got,556 td.Struct(paTest{Num: 666},557 td.StructFields{558 "1 ! beta*": 1000, // matches alphaNum559 "2 = *": 2000, // matches betaNum560 }),561 "negative shell pattern")562 checkError(t, "never tested",563 td.Struct(paTest{Num: 666}, td.StructFields{"= al[pha": 123}),564 expectedError{565 Message: mustBe("bad usage of Struct operator"),566 Path: mustBe("DATA"),567 Summary: mustContain("bad shell pattern field `= al[pha`: "),568 })569 checkError(t, "never tested",570 td.Struct(paTest{Num: 666}, td.StructFields{"= alpha*": nil}), expectedError{571 Message: mustBe("bad usage of Struct operator"),572 Path: mustBe("DATA"),573 Summary: mustBe("expected value of field alphaNum (from pattern `= alpha*`) cannot be nil as it is a int"),574 })575 })576 t.Run("Regexp", func(t *testing.T) {577 checkOK(t, got,578 td.Struct(paTest{Num: 666},579 td.StructFields{580 "=~Num$": td.Gte(1000), // matches alphaNum & betaNum581 }))582 checkOK(t, got,583 td.Struct(paTest{Num: 666},584 td.StructFields{585 "=~^a.*Num$": td.Lt(0), // no remaining fields to match586 "=~.": td.Gte(1000), // first, matches alphaNum & betaNum587 "=~^b.*Num$": td.Lt(0), // no remaining fields to match588 }),589 "Default sorting uses patterns")590 checkOK(t, got,591 td.Struct(paTest{Num: 666},592 td.StructFields{593 "1 =~ ^a.*Num$": td.Between(999, 1001), // matches alphaNum594 "2 =~ .": td.Gte(2000), // matches betaNum595 "3 =~ ^b.*Num$": td.Gt(3000), // no remaining fields to match596 }),597 "Explicitly sorted")598 checkOK(t, got,599 td.Struct(paTest{Num: 666},600 td.StructFields{601 "1 !~ ^beta": 1000, // matches alphaNum602 "2 =~ .": 2000, // matches betaNum603 }),604 "negative regexp")605 checkError(t, "never tested",606 td.Struct(paTest{Num: 666}, td.StructFields{"=~ al(*": 123}),607 expectedError{608 Message: mustBe("bad usage of Struct operator"),609 Path: mustBe("DATA"),610 Summary: mustContain("bad regexp field `=~ al(*`: "),611 })612 checkError(t, "never tested",613 td.Struct(paTest{Num: 666}, td.StructFields{"=~ alpha": nil}),614 expectedError{615 Message: mustBe("bad usage of Struct operator"),616 Path: mustBe("DATA"),617 Summary: mustBe("expected value of field alphaNum (from pattern `=~ alpha`) cannot be nil as it is a int"),618 })619 })620}621func TestStructTypeBehind(t *testing.T) {622 equalTypes(t, td.Struct(MyStruct{}, nil), MyStruct{})623 equalTypes(t, td.Struct(&MyStruct{}, nil), &MyStruct{})624 // Erroneous op625 equalTypes(t, td.Struct("test", nil), nil)626}627func TestSStruct(t *testing.T) {628 gotStruct := MyStruct{629 MyStructMid: MyStructMid{630 MyStructBase: MyStructBase{631 ValBool: true,632 },633 ValStr: "foobar",634 },635 ValInt: 123,636 }637 //638 // Using pointer639 checkOK(t, &gotStruct,640 td.SStruct(&MyStruct{}, td.StructFields{641 "ValBool": true,642 "ValStr": "foobar",643 "ValInt": 123,644 // nil Ptr645 }))646 checkOK(t, &gotStruct,647 td.SStruct(648 &MyStruct{649 MyStructMid: MyStructMid{650 ValStr: "zip",651 },652 ValInt: 666,653 },654 td.StructFields{655 "ValBool": true,656 "> ValStr": "foobar",657 ">ValInt": 123,658 }))659 checkOK(t, &gotStruct,660 td.SStruct((*MyStruct)(nil), td.StructFields{661 "ValBool": true,662 "ValStr": "foobar",663 "ValInt": 123,664 // nil Ptr665 }))666 checkError(t, 123,667 td.SStruct(&MyStruct{}, td.StructFields{}),668 expectedError{669 Message: mustBe("type mismatch"),670 Path: mustBe("DATA"),671 Got: mustContain("int"),672 Expected: mustContain("*td_test.MyStruct"),673 })674 checkError(t, &MyStructBase{},675 td.SStruct(&MyStruct{}, td.StructFields{}),676 expectedError{677 Message: mustBe("type mismatch"),678 Path: mustBe("DATA"),679 Got: mustContain("*td_test.MyStructBase"),680 Expected: mustContain("*td_test.MyStruct"),681 })682 checkError(t, &gotStruct,683 td.SStruct(&MyStruct{}, td.StructFields{684 // ValBool false ← does not match685 "ValStr": "foobar",686 "ValInt": 123,687 }),688 expectedError{689 Message: mustBe("values differ"),690 Path: mustBe("DATA.ValBool"),691 Got: mustContain("true"),692 Expected: mustContain("false"),693 })694 checkOK(t, &gotStruct,695 td.SStruct(&MyStruct{696 MyStructMid: MyStructMid{697 MyStructBase: MyStructBase{698 ValBool: true,699 },700 ValStr: "foobar",701 },702 ValInt: 123,703 }, nil))704 checkError(t, &gotStruct,705 td.SStruct(&MyStruct{706 MyStructMid: MyStructMid{707 MyStructBase: MyStructBase{708 ValBool: true,709 },710 ValStr: "foobax", // ← does not match711 },712 ValInt: 123,713 }, nil),714 expectedError{715 Message: mustBe("values differ"),716 Path: mustBe("DATA.ValStr"),717 Got: mustContain("foobar"),718 Expected: mustContain("foobax"),719 })720 // Zero values721 checkOK(t, &MyStruct{}, td.SStruct(&MyStruct{}, nil))722 checkOK(t, &MyStruct{}, td.SStruct(&MyStruct{}, td.StructFields{}))723 // nil cases724 checkError(t, nil, td.SStruct(&MyStruct{}, nil),725 expectedError{726 Message: mustBe("values differ"),727 Path: mustBe("DATA"),728 Got: mustContain("nil"),729 Expected: mustContain("*td_test.MyStruct"),730 })731 checkError(t, (*MyStruct)(nil), td.SStruct(&MyStruct{}, nil),732 expectedError{733 Message: mustBe("values differ"),734 Path: mustBe("DATA"),735 Got: mustContain("nil"),736 Expected: mustBe("non-nil"),737 })738 //739 // Without pointer740 checkOK(t, gotStruct,741 td.SStruct(MyStruct{}, td.StructFields{742 "ValBool": true,743 "ValStr": "foobar",744 "ValInt": 123,745 }))746 checkOK(t, gotStruct,747 td.SStruct(748 MyStruct{749 MyStructMid: MyStructMid{750 ValStr: "zip",751 },752 ValInt: 666,753 },754 td.StructFields{755 "ValBool": true,756 "> ValStr": "foobar",757 ">ValInt": 123,758 }))759 checkError(t, 123, td.SStruct(MyStruct{}, td.StructFields{}),760 expectedError{761 Message: mustBe("type mismatch"),762 Path: mustBe("DATA"),763 Got: mustContain("int"),764 Expected: mustContain("td_test.MyStruct"),765 })766 checkError(t, gotStruct,767 td.SStruct(MyStruct{}, td.StructFields{768 // "ValBool" false ← does not match769 "ValStr": "foobar",770 "ValInt": 123,771 }),772 expectedError{773 Message: mustBe("values differ"),774 Path: mustBe("DATA.ValBool"),775 Got: mustContain("true"),776 Expected: mustContain("false"),777 })778 checkOK(t, gotStruct,779 td.SStruct(MyStruct{780 MyStructMid: MyStructMid{781 MyStructBase: MyStructBase{782 ValBool: true,783 },784 ValStr: "foobar",785 },786 ValInt: 123,787 }, nil))788 checkError(t, gotStruct,789 td.SStruct(MyStruct{790 MyStructMid: MyStructMid{791 MyStructBase: MyStructBase{792 ValBool: true,793 },794 ValStr: "foobax", // ← does not match795 },796 ValInt: 123,797 }, nil),798 expectedError{799 Message: mustBe("values differ"),800 Path: mustBe("DATA.ValStr"),801 Got: mustContain("foobar"),802 Expected: mustContain("foobax"),803 })804 // Zero values805 checkOK(t, MyStruct{}, td.Struct(MyStruct{}, td.StructFields{}))806 checkOK(t, MyStruct{}, td.Struct(MyStruct{}, nil))807 // nil cases808 checkError(t, nil, td.SStruct(MyStruct{}, nil),809 expectedError{810 Message: mustBe("values differ"),811 Path: mustBe("DATA"),812 Got: mustContain("nil"),813 Expected: mustContain("td_test.MyStruct"),814 })815 checkError(t, (*MyStruct)(nil), td.SStruct(MyStruct{}, nil),816 expectedError{817 Message: mustBe("type mismatch"),818 Path: mustBe("DATA"),819 Got: mustBe("*td_test.MyStruct"),820 Expected: mustBe("td_test.MyStruct"),821 })822 //823 // Be lax...824 type Struct1 struct {825 name string826 age int827 }...

Full Screen

Full Screen

td_map_test.go

Source:td_map_test.go Github

copy

Full Screen

...280 td.Map("test", nil),281 expectedError{282 Message: mustBe("bad usage of Map operator"),283 Path: mustBe("DATA"),284 Summary: mustContain("usage: Map("),285 })286 checkError(t, "never tested",287 td.SuperMapOf("test", nil),288 expectedError{289 Message: mustBe("bad usage of SuperMapOf operator"),290 Path: mustBe("DATA"),291 Summary: mustContain("usage: SuperMapOf("),292 })293 checkError(t, "never tested",294 td.SubMapOf("test", nil),295 expectedError{296 Message: mustBe("bad usage of SubMapOf operator"),297 Path: mustBe("DATA"),298 Summary: mustContain("usage: SubMapOf("),299 })300 num := 12301 checkError(t, "never tested",302 td.Map(&num, nil),303 expectedError{304 Message: mustBe("bad usage of Map operator"),305 Path: mustBe("DATA"),306 Summary: mustContain("usage: Map("),307 })308 checkError(t, "never tested",309 td.SuperMapOf(&num, nil),310 expectedError{311 Message: mustBe("bad usage of SuperMapOf operator"),312 Path: mustBe("DATA"),313 Summary: mustContain("usage: SuperMapOf("),314 })315 checkError(t, "never tested",316 td.SubMapOf(&num, nil),317 expectedError{318 Message: mustBe("bad usage of SubMapOf operator"),319 Path: mustBe("DATA"),320 Summary: mustContain("usage: SubMapOf("),321 })322 checkError(t, "never tested",323 td.Map(&MyMap{}, td.MapEntries{1: 2}),324 expectedError{325 Message: mustBe("bad usage of Map operator"),326 Path: mustBe("DATA"),327 Summary: mustBe("expected key 1 type mismatch: int != model key type (string)"),328 })329 checkError(t, "never tested",330 td.SuperMapOf(&MyMap{}, td.MapEntries{1: 2}),331 expectedError{332 Message: mustBe("bad usage of SuperMapOf operator"),333 Path: mustBe("DATA"),334 Summary: mustBe("expected key 1 type mismatch: int != model key type (string)"),...

Full Screen

Full Screen

td_isa_test.go

Source:td_isa_test.go Github

copy

Full Screen

...33 checkError(t, &gotStruct, td.Isa(&MyStructBase{}),34 expectedError{35 Message: mustBe("type mismatch"),36 Path: mustBe("DATA"),37 Got: mustContain("*td_test.MyStruct"),38 Expected: mustContain("*td_test.MyStructBase"),39 })40 checkError(t, (*MyStruct)(nil), td.Isa(&MyStructBase{}),41 expectedError{42 Message: mustBe("type mismatch"),43 Path: mustBe("DATA"),44 Got: mustContain("*td_test.MyStruct"),45 Expected: mustContain("*td_test.MyStructBase"),46 })47 checkError(t, gotStruct, td.Isa(&MyStruct{}),48 expectedError{49 Message: mustBe("type mismatch"),50 Path: mustBe("DATA"),51 Got: mustContain("td_test.MyStruct"),52 Expected: mustContain("*td_test.MyStruct"),53 })54 checkError(t, &gotStruct, td.Isa(MyStruct{}),55 expectedError{56 Message: mustBe("type mismatch"),57 Path: mustBe("DATA"),58 Got: mustContain("*td_test.MyStruct"),59 Expected: mustContain("td_test.MyStruct"),60 })61 gotSlice := []int{1, 2, 3}62 checkOK(t, gotSlice, td.Isa([]int{}))63 checkOK(t, &gotSlice, td.Isa(((*[]int)(nil))))64 checkError(t, &gotSlice, td.Isa([]int{}),65 expectedError{66 Message: mustBe("type mismatch"),67 Path: mustBe("DATA"),68 Got: mustContain("*[]int"),69 Expected: mustContain("[]int"),70 })71 checkError(t, gotSlice, td.Isa((*[]int)(nil)),72 expectedError{73 Message: mustBe("type mismatch"),74 Path: mustBe("DATA"),75 Got: mustContain("[]int"),76 Expected: mustContain("*[]int"),77 })78 checkError(t, gotSlice, td.Isa([1]int{2}),79 expectedError{80 Message: mustBe("type mismatch"),81 Path: mustBe("DATA"),82 Got: mustContain("[]int"),83 Expected: mustContain("[1]int"),84 })85 //86 // Bad usage87 checkError(t, "never tested",88 td.Isa(nil),89 expectedError{90 Message: mustBe("bad usage of Isa operator"),91 Path: mustBe("DATA"),92 Summary: mustBe("Isa(nil) is not allowed. To check an interface, try Isa((*fmt.Stringer)(nil)), for fmt.Stringer for example"),93 })94 //95 // String96 test.EqualStr(t, td.Isa((*MyStruct)(nil)).String(),97 "*td_test.MyStruct")...

Full Screen

Full Screen

mustContain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(td_test.MustContain("Hello", "H"))4 fmt.Println(td_test.MustContain("Hello", "L"))5 fmt.Println(td_test.MustContain("Hello", "X"))6}

Full Screen

Full Screen

mustContain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 td_test.MustContain("Hello World", "Hello")5}6import (7func main() {8 fmt.Println("Hello World")9 td_test.MustNotContain("Hello World", "Hello")10}11import (12func main() {13 fmt.Println("Hello World")14 td_test.MustBeEmpty("Hello World")15}16import (17func main() {18 fmt.Println("Hello World")19 td_test.MustNotBeEmpty("Hello World")20}21import (22func main() {23 fmt.Println("Hello World")24 td_test.MustBeTrue(true)25}26import (27func main() {28 fmt.Println("Hello World")29 td_test.MustBeFalse(false)30}31import (32func main() {33 fmt.Println("Hello World")34 td_test.MustBeZero(0)35}36import (37func main() {38 fmt.Println("Hello World")39 td_test.MustNotBeZero(1)40}41import (

Full Screen

Full Screen

mustContain

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 td_test = td_test{"test"}4 td_test.mustContain("test")5 fmt.Println("done")6}7import "fmt"8type td_test struct {9}10func (td_test *td_test) mustContain(s string) {11 fmt.Println(td_test.name + " must contain " + s)12}13func main() {14 fmt.Println("done")15}16I tried to use the import keyword, but it doesn't work. I think that the import keyword is used to import the package, not the class. I also tried to use the import keyword to import the package, but I got the error:17 /usr/lib/go-1.6/src/github.com/td_test (from $GOROOT)18 /home/td/go/src/github.com/td_test (from $GOPATH)19I also tried to use the import keyword to import the package, but I got the error:20 /usr/lib/go-1.6/src/github.com/td_test (from $GOROOT)21 /home/td/go/src/github.com/td_test (from $GOPATH)22I also tried to use the import keyword to import the package, but I got the error:23 /usr/lib/go-1.6/src/github.com/td_test (from $GOROOT)24 /home/td/go/src/github.com/td_test (from $GOPATH)25I tried to use the import keyword to import the package, but I got the error:

Full Screen

Full Screen

mustContain

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 t.mustContain("Hello, World", "Hello")4 t.mustContain("Hello, World", "World")5 t.mustContain("Hello, World", "Goodbye")6 fmt.Println(t)7}8import "fmt"9func main() {10 t.mustContain("Hello, World", "Hello")11 t.mustContain("Hello, World", "World")12 t.mustContain("Hello, World", "Goodbye")13 fmt.Println(t)14}15import "fmt"16func main() {17 t.mustContain("Hello, World", "Hello")18 t.mustContain("Hello, World", "World")19 t.mustContain("Hello, World", "Goodbye")20 fmt.Println(t)21}22import "fmt"23func main() {24 t.mustContain("Hello, World", "Hello")25 t.mustContain("Hello, World", "World")26 t.mustContain("Hello, World", "Goodbye")27 fmt.Println(t)28}29import "fmt"30func main() {31 t.mustContain("Hello, World", "Hello")32 t.mustContain("Hello, World", "World")33 t.mustContain("Hello, World", "Goodbye")34 fmt.Println(t)35}36import "fmt"37func main() {38 t.mustContain("Hello, World", "Hello")39 t.mustContain("Hello, World", "World")40 t.mustContain("Hello, World", "Goodbye")41 fmt.Println(t)42}

Full Screen

Full Screen

mustContain

Using AI Code Generation

copy

Full Screen

1func main() {2}3func main() {4}5func main() {6}7func main() {8}9func main() {10}11func main() {

Full Screen

Full Screen

mustContain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(td_test.Td_test{}.MustContain("Hello World", "Hello"))4}5import (6func TestMustContain(t *testing.T) {7 td_test.Td_test{}.MustContain("Hello World", "Hello")8}9import (10func main() {11 fmt.Println(td_test.Td_test{}.MustContain("Hello World", "Hello"))12}

Full Screen

Full Screen

mustContain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(td.MustContain("1.txt", "hello"))4}5import (6func main() {7 fmt.Println(td.MustNotContain("1.txt", "hello"))8}9import (10func main() {11 fmt.Println(td.MustNotBeEmpty("1.txt"))12}13import (14func main() {15 fmt.Println(td.MustBeEmpty("1.txt"))16}17import (18func main() {19 fmt.Println(td.MustBeEqual("1.txt", "2.txt"))20}21import (22func main() {23 fmt.Println(td.MustNotBeEqual("1.txt", "2.txt"))24}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Go-testdeep automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful