How to use Error method of venom Package

Best Venom code snippet using venom.Error

decode_test.go

Source:decode_test.go Github

copy

Full Screen

...273 for _, test := range testIO {274 t.Run(test.tc, func(t *testing.T) {275 var conf configStruct276 err := Unmarshal(test.v, &conf)277 assertEqualErrors(t, test.err, err)278 assert.Equal(t, test.expect, &conf)279 })280 }281}282func TestInvalidUnmarshalError(t *testing.T) {283 testIO := []struct {284 tc string285 v *Venom286 conf interface{}287 err error288 }{289 {290 tc: "should err due to nil config",291 v: New(),292 conf: nil,293 err: &InvalidUnmarshalError{reflect.TypeOf(nil)},294 },295 {296 tc: "should err due to nil config",297 v: New(),298 conf: configStruct{},299 err: &InvalidUnmarshalError{reflect.TypeOf(configStruct{})},300 },301 {302 tc: "should err due to nil config",303 v: New(),304 conf: func() interface{} {305 var c *configStruct306 return c307 }(),308 err: func() error {309 var c *configStruct310 return &InvalidUnmarshalError{reflect.TypeOf(c)}311 }(),312 },313 }314 for _, test := range testIO {315 t.Run(test.tc, func(t *testing.T) {316 err := Unmarshal(test.v, test.conf)317 assertEqualErrors(t, test.err, err)318 })319 }320}321func TestUnmarshalNested(t *testing.T) {322 testIO := []struct {323 tc string324 v *Venom325 err error326 expect *nestedConfig327 }{328 {329 tc: "should load nested",330 v: func() *Venom {331 ven := New()332 ven.SetDefault("something_special", "special")333 ven.SetDefault("basic.uint8", uint8(8))334 ven.SetDefault("basic2.uint16", uint16(16))335 return ven336 }(),337 expect: &nestedConfig{338 SomethingSpecial: "special",339 Basic: configStruct{340 Uint8: 8,341 },342 BasicPtr: &configStruct{343 Uint16: 16,344 },345 },346 },347 }348 for _, test := range testIO {349 t.Run(test.tc, func(t *testing.T) {350 conf := nestedConfig{351 BasicPtr: &configStruct{},352 }353 err := Unmarshal(test.v, &conf)354 assertEqualErrors(t, test.err, err)355 assert.Equal(t, test.expect, &conf)356 })357 }358}359func TestUnmarshalSlice(t *testing.T) {360 testIO := []struct {361 tc string362 v *Venom363 err error364 expect *sliceConfig365 }{366 {367 tc: "should unmarshal string slice",368 v: func() *Venom {369 ven := New()370 ven.SetDefault("strings", []string{"foo", "bar"})371 return ven372 }(),373 expect: &sliceConfig{374 Strings: []string{"foo", "bar"},375 },376 },377 {378 tc: "should unmarshal nil string slice",379 v: func() *Venom {380 ven := New()381 ven.SetDefault("strings", nil)382 return ven383 }(),384 expect: &sliceConfig{385 Strings: nil,386 },387 },388 {389 tc: "should unmarshal string interface{} slice",390 v: func() *Venom {391 ven := New()392 ven.SetDefault("strings", []interface{}{"foo", "bar"})393 return ven394 }(),395 expect: &sliceConfig{396 Strings: []string{"foo", "bar"},397 },398 },399 {400 tc: "should unmarshal bool slice",401 v: func() *Venom {402 ven := New()403 ven.SetDefault("bools", []bool{true, true, false})404 return ven405 }(),406 expect: &sliceConfig{407 Bools: []bool{true, true, false},408 },409 },410 {411 tc: "should unmarshal nil bool slice",412 v: func() *Venom {413 ven := New()414 ven.SetDefault("bools", nil)415 return ven416 }(),417 expect: &sliceConfig{418 Bools: nil,419 },420 },421 {422 tc: "should unmarshal bool interface{} slice",423 v: func() *Venom {424 ven := New()425 ven.SetDefault("bools", []interface{}{true, true, false})426 return ven427 }(),428 expect: &sliceConfig{429 Bools: []bool{true, true, false},430 },431 },432 {433 tc: "should unmarshal int slice",434 v: func() *Venom {435 ven := New()436 ven.SetDefault("ints", []int{0, 1})437 return ven438 }(),439 expect: &sliceConfig{440 Ints: []int{0, 1},441 },442 },443 {444 tc: "should unmarshal nil int slice",445 v: func() *Venom {446 ven := New()447 ven.SetDefault("ints", nil)448 return ven449 }(),450 expect: &sliceConfig{451 Ints: nil,452 },453 },454 {455 tc: "should unmarshal int interface{} slice",456 v: func() *Venom {457 ven := New()458 ven.SetDefault("ints", []interface{}{0, 1})459 return ven460 }(),461 expect: &sliceConfig{462 Ints: []int{0, 1},463 },464 },465 {466 tc: "should unmarshal int8 slice",467 v: func() *Venom {468 ven := New()469 ven.SetDefault("int8s", []int8{2, 3})470 return ven471 }(),472 expect: &sliceConfig{473 Int8s: []int8{2, 3},474 },475 },476 {477 tc: "should unmarshal nil int8 slice",478 v: func() *Venom {479 ven := New()480 ven.SetDefault("int8s", nil)481 return ven482 }(),483 expect: &sliceConfig{484 Int8s: nil,485 },486 },487 {488 tc: "should unmarshal int8 interface{} slice",489 v: func() *Venom {490 ven := New()491 ven.SetDefault("int8s", []interface{}{int8(2), int8(3)})492 return ven493 }(),494 expect: &sliceConfig{495 Int8s: []int8{2, 3},496 },497 },498 {499 tc: "should unmarshal int16 slice",500 v: func() *Venom {501 ven := New()502 ven.SetDefault("int16s", []int16{4, 5})503 return ven504 }(),505 expect: &sliceConfig{506 Int16s: []int16{4, 5},507 },508 },509 {510 tc: "should unmarshal nil int16 slice",511 v: func() *Venom {512 ven := New()513 ven.SetDefault("int16s", nil)514 return ven515 }(),516 expect: &sliceConfig{517 Int16s: nil,518 },519 },520 {521 tc: "should unmarshal int16 interface{} slice",522 v: func() *Venom {523 ven := New()524 ven.SetDefault("int16s", []interface{}{int16(2), int16(3)})525 return ven526 }(),527 expect: &sliceConfig{528 Int16s: []int16{2, 3},529 },530 },531 {532 tc: "should unmarshal int32 slice",533 v: func() *Venom {534 ven := New()535 ven.SetDefault("int32s", []int32{6, 7})536 return ven537 }(),538 expect: &sliceConfig{539 Int32s: []int32{6, 7},540 },541 },542 {543 tc: "should unmarshal nil int32 slice",544 v: func() *Venom {545 ven := New()546 ven.SetDefault("int32s", nil)547 return ven548 }(),549 expect: &sliceConfig{550 Int32s: nil,551 },552 },553 {554 tc: "should unmarshal int32 interface{} slice",555 v: func() *Venom {556 ven := New()557 ven.SetDefault("int32s", []interface{}{int32(2), int32(3)})558 return ven559 }(),560 expect: &sliceConfig{561 Int32s: []int32{2, 3},562 },563 },564 {565 tc: "should unmarshal int64 slice",566 v: func() *Venom {567 ven := New()568 ven.SetDefault("int64s", []int64{8, 9})569 return ven570 }(),571 expect: &sliceConfig{572 Int64s: []int64{8, 9},573 },574 },575 {576 tc: "should unmarshal nil int64 slice",577 v: func() *Venom {578 ven := New()579 ven.SetDefault("int64s", nil)580 return ven581 }(),582 expect: &sliceConfig{583 Int64s: nil,584 },585 },586 {587 tc: "should unmarshal int64 interface{} slice",588 v: func() *Venom {589 ven := New()590 ven.SetDefault("int64s", []interface{}{int64(2), int64(3)})591 return ven592 }(),593 expect: &sliceConfig{594 Int64s: []int64{2, 3},595 },596 },597 {598 tc: "should unmarshal uint slice",599 v: func() *Venom {600 ven := New()601 ven.SetDefault("uints", []uint{0, 1})602 return ven603 }(),604 expect: &sliceConfig{605 Uints: []uint{0, 1},606 },607 },608 {609 tc: "should unmarshal nil uint slice",610 v: func() *Venom {611 ven := New()612 ven.SetDefault("uints", nil)613 return ven614 }(),615 expect: &sliceConfig{616 Uints: nil,617 },618 },619 {620 tc: "should unmarshal uint interface{} slice",621 v: func() *Venom {622 ven := New()623 ven.SetDefault("uints", []interface{}{uint(2), uint(3)})624 return ven625 }(),626 expect: &sliceConfig{627 Uints: []uint{2, 3},628 },629 },630 {631 tc: "should unmarshal uint8 slice",632 v: func() *Venom {633 ven := New()634 ven.SetDefault("uint8s", []uint8{2, 3})635 return ven636 }(),637 expect: &sliceConfig{638 Uint8s: []uint8{2, 3},639 },640 },641 {642 tc: "should unmarshal nil uint8 slice",643 v: func() *Venom {644 ven := New()645 ven.SetDefault("uint8s", nil)646 return ven647 }(),648 expect: &sliceConfig{649 Uint8s: nil,650 },651 },652 {653 tc: "should unmarshal uint8 interface{} slice",654 v: func() *Venom {655 ven := New()656 ven.SetDefault("uint8s", []interface{}{uint8(2), uint8(3)})657 return ven658 }(),659 expect: &sliceConfig{660 Uint8s: []uint8{2, 3},661 },662 },663 {664 tc: "should unmarshal uint16 slice",665 v: func() *Venom {666 ven := New()667 ven.SetDefault("uint16s", []uint16{4, 5})668 return ven669 }(),670 expect: &sliceConfig{671 Uint16s: []uint16{4, 5},672 },673 },674 {675 tc: "should unmarshal nil uint16 slice",676 v: func() *Venom {677 ven := New()678 ven.SetDefault("uint16s", nil)679 return ven680 }(),681 expect: &sliceConfig{682 Uint16s: nil,683 },684 },685 {686 tc: "should unmarshal uint16 interface{} slice",687 v: func() *Venom {688 ven := New()689 ven.SetDefault("uint16s", []interface{}{uint16(2), uint16(3)})690 return ven691 }(),692 expect: &sliceConfig{693 Uint16s: []uint16{2, 3},694 },695 },696 {697 tc: "should unmarshal uint32 slice",698 v: func() *Venom {699 ven := New()700 ven.SetDefault("uint32s", []uint32{6, 7})701 return ven702 }(),703 expect: &sliceConfig{704 Uint32s: []uint32{6, 7},705 },706 },707 {708 tc: "should unmarshal nil uint32 slice",709 v: func() *Venom {710 ven := New()711 ven.SetDefault("uint32s", nil)712 return ven713 }(),714 expect: &sliceConfig{715 Uint32s: nil,716 },717 },718 {719 tc: "should unmarshal uint32 interface{} slice",720 v: func() *Venom {721 ven := New()722 ven.SetDefault("uint32s", []interface{}{uint32(2), uint32(3)})723 return ven724 }(),725 expect: &sliceConfig{726 Uint32s: []uint32{2, 3},727 },728 },729 {730 tc: "should unmarshal uint64 slice",731 v: func() *Venom {732 ven := New()733 ven.SetDefault("uint64s", []uint64{8, 9})734 return ven735 }(),736 expect: &sliceConfig{737 Uint64s: []uint64{8, 9},738 },739 },740 {741 tc: "should unmarshal nil uint64 slice",742 v: func() *Venom {743 ven := New()744 ven.SetDefault("uint64s", nil)745 return ven746 }(),747 expect: &sliceConfig{748 Uint64s: nil,749 },750 },751 {752 tc: "should unmarshal uint64 interface{} slice",753 v: func() *Venom {754 ven := New()755 ven.SetDefault("uint64s", []interface{}{uint64(2), uint64(3)})756 return ven757 }(),758 expect: &sliceConfig{759 Uint64s: []uint64{2, 3},760 },761 },762 {763 tc: "should unmarshal float32 slice",764 v: func() *Venom {765 ven := New()766 ven.SetDefault("float32s", []float32{0.0, 8675.309})767 return ven768 }(),769 expect: &sliceConfig{770 Float32s: []float32{0.0, 8675.309},771 },772 },773 {774 tc: "should unmarshal nil float32 slice",775 v: func() *Venom {776 ven := New()777 ven.SetDefault("float32s", nil)778 return ven779 }(),780 expect: &sliceConfig{781 Float32s: nil,782 },783 },784 {785 tc: "should unmarshal float32 interface{} slice",786 v: func() *Venom {787 ven := New()788 ven.SetDefault("float32s", []interface{}{float32(0.0), float32(8675.309)})789 return ven790 }(),791 expect: &sliceConfig{792 Float32s: []float32{0.0, 8675.309},793 },794 },795 {796 tc: "should unmarshal float64 slice",797 v: func() *Venom {798 ven := New()799 ven.SetDefault("float64s", []float64{0.0, 8675.309})800 return ven801 }(),802 expect: &sliceConfig{803 Float64s: []float64{0.0, 8675.309},804 },805 },806 {807 tc: "should unmarshal nil float64 slice",808 v: func() *Venom {809 ven := New()810 ven.SetDefault("float64s", nil)811 return ven812 }(),813 expect: &sliceConfig{814 Float64s: nil,815 },816 },817 {818 tc: "should unmarshal float64 interface{} slice",819 v: func() *Venom {820 ven := New()821 ven.SetDefault("float64s", []interface{}{float64(0.0), float64(8675.309)})822 return ven823 }(),824 expect: &sliceConfig{825 Float64s: []float64{0.0, 8675.309},826 },827 },828 {829 tc: "should unmarshal 2d slice",830 v: func() *Venom {831 ven := New()832 ven.SetDefault("int2d", [][]int{833 {0, 1, 2, 3, 4, 5},834 {6, 7, 8, 9, 10, 11},835 {12, 13, 14, 15, 16, 17},836 })837 return ven838 }(),839 expect: &sliceConfig{840 Int2D: [][]int{841 {0, 1, 2, 3, 4, 5},842 {6, 7, 8, 9, 10, 11},843 {12, 13, 14, 15, 16, 17},844 },845 },846 },847 {848 tc: "should unmarshal 3d slice",849 v: func() *Venom {850 ven := New()851 ven.SetDefault("int3d", [][][]int{852 {853 {0, 1, 2, 3, 4, 5},854 {6, 7, 8, 9, 10, 11},855 {12, 13, 14, 15, 16, 17},856 },857 {858 {18, 19, 20, 21, 22, 23},859 {24, 25, 26, 27, 28, 29},860 {30, 31, 32, 33, 34, 35},861 },862 })863 return ven864 }(),865 expect: &sliceConfig{866 Int3D: [][][]int{867 {868 {0, 1, 2, 3, 4, 5},869 {6, 7, 8, 9, 10, 11},870 {12, 13, 14, 15, 16, 17},871 },872 {873 {18, 19, 20, 21, 22, 23},874 {24, 25, 26, 27, 28, 29},875 {30, 31, 32, 33, 34, 35},876 },877 },878 },879 },880 {881 tc: "should error coercing string to slice of strings",882 v: func() *Venom {883 ven := New()884 ven.SetDefault("strings", "foobar")885 return ven886 }(),887 expect: new(sliceConfig),888 err: &CoerceErr{From: "foobar", To: "[]string"},889 },890 {891 tc: "should error coercing interface{} slice with invalid values to slice of strings",892 v: func() *Venom {893 ven := New()894 ven.SetDefault("strings", []interface{}{"foo", true})895 return ven896 }(),897 expect: new(sliceConfig),898 err: &CoerceErr{899 From: []interface{}{"foo", true},900 To: "[]string",901 Err: &CoerceErr{902 From: true,903 To: "string",904 },905 },906 },907 {908 tc: "should error coercing string to slice of bools",909 v: func() *Venom {910 ven := New()911 ven.SetDefault("bools", "foobar")912 return ven913 }(),914 expect: new(sliceConfig),915 err: &CoerceErr{From: "foobar", To: "[]bool"},916 },917 {918 tc: "should error coercing interface{} slice with invalid values to slice of bools",919 v: func() *Venom {920 ven := New()921 ven.SetDefault("bools", []interface{}{true, "false"})922 return ven923 }(),924 expect: new(sliceConfig),925 err: &CoerceErr{926 From: []interface{}{true, "false"},927 To: "[]bool",928 Err: &CoerceErr{929 From: "false",930 To: "bool",931 },932 },933 },934 {935 tc: "should error coercing string to slice of ints",936 v: func() *Venom {937 ven := New()938 ven.SetDefault("ints", "foobar")939 return ven940 }(),941 expect: new(sliceConfig),942 err: &CoerceErr{From: "foobar", To: "[]int"},943 },944 {945 tc: "should error coercing interface{} slice with invalid values to slice of ints",946 v: func() *Venom {947 ven := New()948 ven.SetDefault("ints", []interface{}{0, "foobar"})949 return ven950 }(),951 expect: new(sliceConfig),952 err: &CoerceErr{953 From: []interface{}{0, "foobar"},954 To: "[]int",955 Err: &CoerceErr{956 From: "foobar",957 To: "int",958 },959 },960 },961 {962 tc: "should error coercing string to slice of int8s",963 v: func() *Venom {964 ven := New()965 ven.SetDefault("int8s", "foobar")966 return ven967 }(),968 expect: new(sliceConfig),969 err: &CoerceErr{From: "foobar", To: "[]int8"},970 },971 {972 tc: "should error coercing interface{} slice with invalid values to slice of int8s",973 v: func() *Venom {974 ven := New()975 ven.SetDefault("int8s", []interface{}{int8(0), "foobar"})976 return ven977 }(),978 expect: new(sliceConfig),979 err: &CoerceErr{980 From: []interface{}{int8(0), "foobar"},981 To: "[]int8",982 Err: &CoerceErr{983 From: "foobar",984 To: "int8",985 },986 },987 },988 {989 tc: "should error coercing string to slice of int16s",990 v: func() *Venom {991 ven := New()992 ven.SetDefault("int16s", "foobar")993 return ven994 }(),995 expect: new(sliceConfig),996 err: &CoerceErr{From: "foobar", To: "[]int16"},997 },998 {999 tc: "should error coercing interface{} slice with invalid values to slice of int16s",1000 v: func() *Venom {1001 ven := New()1002 ven.SetDefault("int16s", []interface{}{int16(0), "foobar"})1003 return ven1004 }(),1005 expect: new(sliceConfig),1006 err: &CoerceErr{1007 From: []interface{}{int16(0), "foobar"},1008 To: "[]int16",1009 Err: &CoerceErr{1010 From: "foobar",1011 To: "int16",1012 },1013 },1014 },1015 {1016 tc: "should error coercing string to slice of int32s",1017 v: func() *Venom {1018 ven := New()1019 ven.SetDefault("int32s", "foobar")1020 return ven1021 }(),1022 expect: new(sliceConfig),1023 err: &CoerceErr{From: "foobar", To: "[]int32"},1024 },1025 {1026 tc: "should error coercing interface{} slice with invalid values to slice of int32s",1027 v: func() *Venom {1028 ven := New()1029 ven.SetDefault("int32s", []interface{}{int32(0), "foobar"})1030 return ven1031 }(),1032 expect: new(sliceConfig),1033 err: &CoerceErr{1034 From: []interface{}{int32(0), "foobar"},1035 To: "[]int32",1036 Err: &CoerceErr{1037 From: "foobar",1038 To: "int32",1039 },1040 },1041 },1042 {1043 tc: "should error coercing string to slice of int64s",1044 v: func() *Venom {1045 ven := New()1046 ven.SetDefault("int64s", "foobar")1047 return ven1048 }(),1049 expect: new(sliceConfig),1050 err: &CoerceErr{From: "foobar", To: "[]int64"},1051 },1052 {1053 tc: "should error coercing interface{} slice with invalid values to slice of int64s",1054 v: func() *Venom {1055 ven := New()1056 ven.SetDefault("int64s", []interface{}{int64(0), "foobar"})1057 return ven1058 }(),1059 expect: new(sliceConfig),1060 err: &CoerceErr{1061 From: []interface{}{int64(0), "foobar"},1062 To: "[]int64",1063 Err: &CoerceErr{1064 From: "foobar",1065 To: "int64",1066 },1067 },1068 },1069 {1070 tc: "should error coercing string to slice of uints",1071 v: func() *Venom {1072 ven := New()1073 ven.SetDefault("uints", "foobar")1074 return ven1075 }(),1076 expect: new(sliceConfig),1077 err: &CoerceErr{From: "foobar", To: "[]uint"},1078 },1079 {1080 tc: "should error coercing interface{} slice with invalid values to slice of uints",1081 v: func() *Venom {1082 ven := New()1083 ven.SetDefault("uints", []interface{}{uint(0), "foobar"})1084 return ven1085 }(),1086 expect: new(sliceConfig),1087 err: &CoerceErr{1088 From: []interface{}{uint(0), "foobar"},1089 To: "[]uint",1090 Err: &CoerceErr{1091 From: "foobar",1092 To: "uint",1093 },1094 },1095 },1096 {1097 tc: "should error coercing string to slice of uint8s",1098 v: func() *Venom {1099 ven := New()1100 ven.SetDefault("uint8s", "foobar")1101 return ven1102 }(),1103 expect: new(sliceConfig),1104 err: &CoerceErr{From: "foobar", To: "[]uint8"},1105 },1106 {1107 tc: "should error coercing interface{} slice with invalid values to slice of uint8s",1108 v: func() *Venom {1109 ven := New()1110 ven.SetDefault("uint8s", []interface{}{uint8(0), "foobar"})1111 return ven1112 }(),1113 expect: new(sliceConfig),1114 err: &CoerceErr{1115 From: []interface{}{uint8(0), "foobar"},1116 To: "[]uint8",1117 Err: &CoerceErr{1118 From: "foobar",1119 To: "uint8",1120 },1121 },1122 },1123 {1124 tc: "should error coercing string to slice of uint16s",1125 v: func() *Venom {1126 ven := New()1127 ven.SetDefault("uint16s", "foobar")1128 return ven1129 }(),1130 expect: new(sliceConfig),1131 err: &CoerceErr{From: "foobar", To: "[]uint16"},1132 },1133 {1134 tc: "should error coercing interface{} slice with invalid values to slice of uint16s",1135 v: func() *Venom {1136 ven := New()1137 ven.SetDefault("uint16s", []interface{}{uint16(0), "foobar"})1138 return ven1139 }(),1140 expect: new(sliceConfig),1141 err: &CoerceErr{1142 From: []interface{}{uint16(0), "foobar"},1143 To: "[]uint16",1144 Err: &CoerceErr{1145 From: "foobar",1146 To: "uint16",1147 },1148 },1149 },1150 {1151 tc: "should error coercing string to slice of uint32s",1152 v: func() *Venom {1153 ven := New()1154 ven.SetDefault("uint32s", "foobar")1155 return ven1156 }(),1157 expect: new(sliceConfig),1158 err: &CoerceErr{From: "foobar", To: "[]uint32"},1159 },1160 {1161 tc: "should error coercing interface{} slice with invalid values to slice of uint32s",1162 v: func() *Venom {1163 ven := New()1164 ven.SetDefault("uint32s", []interface{}{uint32(0), "foobar"})1165 return ven1166 }(),1167 expect: new(sliceConfig),1168 err: &CoerceErr{1169 From: []interface{}{uint32(0), "foobar"},1170 To: "[]uint32",1171 Err: &CoerceErr{1172 From: "foobar",1173 To: "uint32",1174 },1175 },1176 },1177 {1178 tc: "should error coercing string to slice of uint64s",1179 v: func() *Venom {1180 ven := New()1181 ven.SetDefault("uint64s", "foobar")1182 return ven1183 }(),1184 expect: new(sliceConfig),1185 err: &CoerceErr{From: "foobar", To: "[]uint64"},1186 },1187 {1188 tc: "should error coercing interface{} slice with invalid values to slice of uint64s",1189 v: func() *Venom {1190 ven := New()1191 ven.SetDefault("uint64s", []interface{}{uint64(0), "foobar"})1192 return ven1193 }(),1194 expect: new(sliceConfig),1195 err: &CoerceErr{1196 From: []interface{}{uint64(0), "foobar"},1197 To: "[]uint64",1198 Err: &CoerceErr{1199 From: "foobar",1200 To: "uint64",1201 },1202 },1203 },1204 {1205 tc: "should error coercing string to slice of float32s",1206 v: func() *Venom {1207 ven := New()1208 ven.SetDefault("float32s", "foobar")1209 return ven1210 }(),1211 expect: new(sliceConfig),1212 err: &CoerceErr{From: "foobar", To: "[]float32"},1213 },1214 {1215 tc: "should error coercing interface{} slice with invalid values to slice of float32s",1216 v: func() *Venom {1217 ven := New()1218 ven.SetDefault("float32s", []interface{}{float32(0), "foobar"})1219 return ven1220 }(),1221 expect: new(sliceConfig),1222 err: &CoerceErr{1223 From: []interface{}{float32(0), "foobar"},1224 To: "[]float32",1225 Err: &CoerceErr{1226 From: "foobar",1227 To: "float32",1228 },1229 },1230 },1231 {1232 tc: "should error coercing string to slice of float64s",1233 v: func() *Venom {1234 ven := New()1235 ven.SetDefault("float64s", "foobar")1236 return ven1237 }(),1238 expect: new(sliceConfig),1239 err: &CoerceErr{From: "foobar", To: "[]float64"},1240 },1241 {1242 tc: "should error coercing interface{} slice with invalid values to slice of float64s",1243 v: func() *Venom {1244 ven := New()1245 ven.SetDefault("float64s", []interface{}{float64(0), "foobar"})1246 return ven1247 }(),1248 expect: new(sliceConfig),1249 err: &CoerceErr{1250 From: []interface{}{float64(0), "foobar"},1251 To: "[]float64",1252 Err: &CoerceErr{1253 From: "foobar",1254 To: "float64",1255 },1256 },1257 },1258 {1259 tc: "should error coercing non-matching slices",1260 v: func() *Venom {1261 ven := New()1262 ven.SetDefault("strings", []float64{0.0})1263 return ven1264 }(),1265 expect: new(sliceConfig),1266 err: &CoerceErr{From: []float64{0}, To: "[]string"},1267 },1268 }1269 for _, test := range testIO {1270 t.Run(test.tc, func(t *testing.T) {1271 conf := new(sliceConfig)1272 err := Unmarshal(test.v, conf)1273 assertEqualErrors(t, test.err, err)1274 assert.Equal(t, test.expect, conf)1275 })1276 }1277}1278type Config struct {1279 Ports []int1280 Storage StorageConfig1281 Dir string `venom:"dir"`1282}1283type StorageConfig struct {1284 Driver string1285 DriverOpts map[string]string `venom:"driver_opts"`1286}1287func TestUnmarshal_Hyper(t *testing.T) {...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...117 if varsFromFile != "" {118 varFileMap := make(map[string]string)119 bytes, err := ioutil.ReadFile(varsFromFile)120 if err != nil {121 return actionplugin.Fail("VENOM - Error while reading file: %v\n", err)122 }123 switch filepath.Ext(varsFromFile) {124 case ".json":125 err = json.Unmarshal(bytes, &varFileMap)126 case ".yaml":127 err = yaml.Unmarshal(bytes, &varFileMap)128 default:129 return actionplugin.Fail("VENOM - unsupported varFile format")130 }131 if err != nil {132 return actionplugin.Fail("VENOM - Error on unmarshal file: %v\n", err)133 }134 for key, value := range varFileMap {135 data[key] = value136 }137 }138 v.AddVariables(data)139 v.LogLevel = loglevel140 v.OutputFormat = "xml"141 v.OutputDir = output142 v.Parallel = parallel143 filepathVal := strings.Split(path, ",")144 filepathExcluded := strings.Split(exclude, ",")145 if len(filepathVal) == 1 {146 filepathVal = strings.Split(filepathVal[0], " ")147 }148 var filepathValComputed []string149 for _, fp := range filepathVal {150 expandedPaths, err := walkGlobFile(fp)151 if err != nil {152 return actionplugin.Fail("VENOM - Error on walk files: %v\n", err)153 }154 filepathValComputed = append(filepathValComputed, expandedPaths...)155 }156 if len(filepathExcluded) == 1 {157 filepathExcluded = strings.Split(filepathExcluded[0], " ")158 }159 var filepathExcludedComputed []string160 for _, fp := range filepathExcluded {161 expandedPaths, err := walkGlobFile(fp)162 if err != nil {163 return actionplugin.Fail("VENOM - Error on walk excluded files: %v\n", err)164 }165 filepathExcludedComputed = append(filepathExcludedComputed, expandedPaths...)166 }167 fmt.Printf("VENOM - filepath: %v\n", filepathValComputed)168 fmt.Printf("VENOM - excluded: %v\n", filepathExcludedComputed)169 tests, err := v.Process(filepathValComputed, filepathExcludedComputed)170 if err != nil {171 return actionplugin.Fail("VENOM - Fail on venom: %v\n", err)172 }173 elapsed := time.Since(start)174 fmt.Printf("VENOM - Output test results under: %s\n", output)175 if err := v.OutputResult(*tests, elapsed); err != nil {176 return actionplugin.Fail("VENOM - Error while uploading test results: %v\n", err)177 }178 return &actionplugin.ActionResult{179 Status: sdk.StatusSuccess,180 }, nil181}182func main() {183 actPlugin := venomActionPlugin{}184 if err := actionplugin.Start(context.Background(), &actPlugin); err != nil {185 panic(err)186 }187 return188}189func walkGlobFile(path string) ([]string, error) {190 filenames, err := filepath.Glob(path)...

Full Screen

Full Screen

venom.go

Source:venom.go Github

copy

Full Screen

1package testing2import (3 "fmt"4 "sync"5 "mby.fr/mass/internal/display"6 "mby.fr/mass/internal/resources"7 "mby.fr/utils/container"8)9var (10 venomImage = "mxbossard/venom:1.0.1"11 venomRunner = container.Runner{12 Image: venomImage,13 //Volumes: []string{testDirMount},14 CmdArgs: []string{"run"},15 Remove: true,16 }17 dummyRunner = container.Runner{18 Image: "alpine:3.16",19 CmdArgs: []string{"sh", "-c", "echo 'Dummy venom runner '; for i in $(seq 3); do sleep 1; echo .; done"},20 Remove: true,21 }22)23func RunProjectVenomTests(d display.Displayer, p resources.Project) (err error) {24 images, err := p.Images()25 if err != nil {26 return27 }28 var wg sync.WaitGroup29 errors := make(chan error, len(images))30 for _, i := range images {31 wg.Add(1)32 go func(i resources.Image) {33 defer wg.Done()34 err = RunImageVenomTests(d, i)35 if err != nil {36 errors <- err37 }38 }(i)39 }40 // Wait for all tests to finish41 wg.Wait()42 // Use select to not block if no error in channel43 select {44 case err = <-errors:45 default:46 }47 if err != nil {48 return49 }50 err = RunVenomTests(d, p)51 return52}53func RunImageVenomTests(d display.Displayer, i resources.Image) (err error) {54 return RunVenomTests(d, i)55}56func RunVenomTests(d display.Displayer, res resources.Tester) (err error) {57 testDirMount := res.AbsTestDir() + ":/venom:ro"58 runner := venomRunner59 runner.Volumes = []string{testDirMount}60 logger := d.BufferedActionLogger("test", res.QualifiedName())61 //defer logger.Close()62 err = runner.Wait(logger.Out(), logger.Err())63 return64}65func VenomTests(d display.Displayer, res resources.Resource) (err error) {66 switch v := res.(type) {67 case resources.Project:68 RunProjectVenomTests(d, v)69 case resources.Image:70 RunImageVenomTests(d, v)71 default:72 d.Warn(fmt.Sprintf("Resource %s is not testable !", res.QualifiedName()))73 return74 }75 return76}...

Full Screen

Full Screen

Error

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(x)4 fmt.Printf("%T\n", x)5 fmt.Println(x)6}

Full Screen

Full Screen

Error

Using AI Code Generation

copy

Full Screen

1import "fmt"2type venom struct {3}4func (v venom) Error() string {5 return fmt.Sprintf("Error: %v", v.age)6}7func main() {8 v := venom{age: 30}9 fmt.Println(v)10}11import "fmt"12type venom struct {13}14func (v venom) Error() string {15 return fmt.Sprintf("Error: %v", v.age)16}17func main() {18 v := venom{age: 30}19 fmt.Println(v)20}21import "fmt"22type venom struct {23}24func (v venom) Error() string {25 return fmt.Sprintf("Error: %v", v.age)26}27func main() {28 v := venom{age: 30}29 fmt.Println(v)30}31import "fmt"32type venom struct {33}34func (v venom) Error() string {35 return fmt.Sprintf("Error: %v", v.age)36}37func main() {38 v := venom{age: 30}39 fmt.Println(v)40}41import "fmt"42type venom struct {43}44func (v venom) Error() string {45 return fmt.Sprintf("Error: %v", v.age)46}47func main() {48 v := venom{age: 30}49 fmt.Println(v)50}51import "fmt"52type venom struct {53}54func (v venom) Error() string {55 return fmt.Sprintf("Error: %v", v.age)56}57func main() {58 v := venom{age: 30}59 fmt.Println(v)60}61import "fmt"62type venom struct {63}64func (v venom) Error() string {65 return fmt.Sprintf("Error: %v", v.age)66}67func main() {68 v := venom{age: 30}69 fmt.Println(v)70}

Full Screen

Full Screen

Error

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := venom.New("spiderman")4 fmt.Println(err.Error())5}6import (7func main() {8 err := venom.New("spiderman")9 fmt.Println(err)10}11import (12func main() {13 err := venom.New("spiderman")14 fmt.Println(err)15}16import (17func main() {18 err := venom.New("spiderman")19 fmt.Println(err.Error())20}21import (22func main() {23 err := venom.New("spiderman")24 fmt.Println(err.Error())25}26import (27func main() {28 err := venom.New("spiderman")29 fmt.Println(err.Error())30}31import (32func main() {33 err := venom.New("spiderman")34 fmt.Println(err.Error())35}36import (37func main() {38 err := venom.New("spiderman")39 fmt.Println(err.Error())40}41import (42func main() {43 err := venom.New("spiderman")44 fmt.Println(err.Error())45}46import (

Full Screen

Full Screen

Error

Using AI Code Generation

copy

Full Screen

1import (2type Venom struct {3}4func (v Venom) Error() string {5 return fmt.Sprintf("Venom Number %d", v.Number)6}7func main() {8 v := Venom{Number: 42}9 log.Fatal(v)10}11import (12type Venom struct {13}14func (v Venom) Error() string {15 return fmt.Sprintf("Venom Number %d", v.Number)16}17func main() {18 v := Venom{Number: 42}19 log.Fatal(v)20}21import (22type Venom struct {23}24func (v Venom) Error() string {25 return fmt.Sprintf("Venom Number %d", v.Number)26}27func main() {28 v := Venom{Number: 42}29 log.Fatal(v)30}31import (32type Venom struct {33}34func (v Venom) Error() string {35 return fmt.Sprintf("Venom Number %d", v.Number)36}37func main() {38 v := Venom{Number: 42}39 log.Fatal(v)40}

Full Screen

Full Screen

Error

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 venom.Error("This is an error")4 fmt.Println("This is a test")5}6import (7func Error(msg string) {8 f, err := os.OpenFile("error.log", os.O_WRONLY|os.O_CREATE, 0644)9 if err != nil {10 log.Fatal(err)11 }12 defer f.Close()13 log.SetOutput(f)14 log.Println(msg)15 fmt.Println("Error logged")16}

Full Screen

Full Screen

Error

Using AI Code Generation

copy

Full Screen

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

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 Venom automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful