How to use CmpPanic method of td Package

Best Go-testdeep code snippet using td.CmpPanic

string_map_unmarshal_test.go

Source:string_map_unmarshal_test.go Github

copy

Full Screen

...36 td.Cmp(t, target, want)37 })38 t.Run("unmarshal only works on structs or pointers to them", func(t *testing.T) {39 sm := map[string]string{}40 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, 42) }, scold.ErrNotAStructLike)41 i := 4242 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, &i) }, scold.ErrNotAStructLike)43 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, "foo") }, scold.ErrNotAStructLike)44 str := "foo"45 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, &str) }, scold.ErrNotAStructLike)46 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, []int{1, 2, 3}) }, scold.ErrNotAStructLike)47 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, [...]int{1, 2, 3}) }, scold.ErrNotAStructLike)48 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, sm) }, scold.ErrNotAStructLike)49 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, func() {}) }, scold.ErrNotAStructLike)50 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, make(chan int)) }, scold.ErrNotAStructLike)51 // ---52 err := scold.StringMapUnmarshal(sm, struct{}{})53 td.CmpNoError(t, err)54 test := struct{}{}55 err = scold.StringMapUnmarshal(sm, &test)56 td.CmpNoError(t, err)57 })58 t.Run("report missing fields", func(t *testing.T) {59 target := struct{}{}60 sm := map[string]string{61 "Foo": "42",62 "Bar": "ハロー",63 "AGAIN?": "435",64 }65 errs := scold.StringMapUnmarshal(sm, &target).(*multierror.Error)66 td.CmpError(t, errs)67 wantErrs := []error{68 &scold.FieldError{"Foo", scold.ErrUnknownField},69 &scold.FieldError{"Bar", scold.ErrUnknownField},70 &scold.FieldError{"AGAIN?", scold.ErrUnknownField},71 }72 td.Cmp(t, errs.Errors, td.Bag(td.Flatten(wantErrs)))73 })74 t.Run("int fields, no error", func(t *testing.T) {75 type structType struct {76 Untouched int77 I int78 Ui uint79 I8 int880 I16 int1681 I32 int3282 I64 int6483 U8 uint884 U16 uint1685 U32 uint3286 U64 uint6487 }88 target := structType{42, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}89 sm := map[string]string{90 "I": "42",91 "I8": "127",92 "I16": "-32000",93 "I32": "-2000000000",94 "I64": "18000000000",95 "Ui": "12",96 "U8": "255",97 "U16": "65000",98 "U32": "4000000000",99 "U64": "32000000000",100 }101 want := structType{42, 42, 12, 127, -32000, -2000000000, 18000000000, 255, 65000, 4000000000, 32000000000}102 err := scold.StringMapUnmarshal(sm, &target)103 td.CmpNoError(t, err)104 td.Cmp(t, target, want)105 })106 t.Run("int fields, values out of bounds or bogus", func(t *testing.T) {107 type structType struct {108 Untouched int109 I int110 Ui uint111 I8 int8112 I16 int16113 I32 int32114 I64 int64115 U8 uint8116 U16 uint16117 U32 uint32118 U64 uint64119 }120 target := structType{42, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}121 sm := map[string]string{122 "I": "-0",123 "I8": "-129",124 "I16": "40000",125 "I32": "-3000000000",126 "I64": "10000000000000000000",127 "Ui": "0",128 "U8": "300",129 "U16": "67000",130 "U32": "5000000000",131 "U64": "20000000000000000000",132 }133 want := structType{42, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10}134 errs := scold.StringMapUnmarshal(sm, &target).(*multierror.Error)135 wantErrs := []error{136 &scold.FieldError{"I8", &scold.NotValueOfTypeError{reflect.Int8.String(), "-129", nil}},137 &scold.FieldError{"I16", &scold.NotValueOfTypeError{reflect.Int16.String(), "40000", nil}},138 &scold.FieldError{"I32", &scold.NotValueOfTypeError{reflect.Int32.String(), "-3000000000", nil}},139 &scold.FieldError{"I64", &scold.NotValueOfTypeError{reflect.Int64.String(), "10000000000000000000", nil}},140 &scold.FieldError{"Ui", &scold.NotValueOfTypeError{reflect.Uint.String(), "0", nil}},141 &scold.FieldError{"U8", &scold.NotValueOfTypeError{reflect.Uint8.String(), "300", nil}},142 &scold.FieldError{"U16", &scold.NotValueOfTypeError{reflect.Uint16.String(), "67000", nil}},143 &scold.FieldError{"U32", &scold.NotValueOfTypeError{reflect.Uint32.String(), "5000000000", nil}},144 &scold.FieldError{"U64", &scold.NotValueOfTypeError{reflect.Uint64.String(), "20000000000000000000", nil}},145 }146 td.Cmp(t, errs.Errors, td.Bag(td.Flatten(wantErrs)))147 td.Cmp(t, target, want)148 })149 t.Run("float fields, no error", func(t *testing.T) {150 type structType struct {151 F32 float32152 Untouched int153 F64 float64154 }155 target := structType{1.0, 0, 2.0}156 sm := map[string]string{157 "F32": "42.00",158 "F64": "1e9",159 }160 want := structType{42.0, 0, 1e9}161 err := scold.StringMapUnmarshal(sm, &target)162 td.CmpNoError(t, err)163 td.Cmp(t, target, want)164 })165 t.Run("float fields, values out of range or bogus", func(t *testing.T) {166 type structType struct {167 F32 float32168 Untouched int169 F64 float64170 }171 target := structType{1.0, 0, 2.0}172 sm := map[string]string{173 "F32": "3.402824E+38",174 "F64": "-2.7976931348623157E+308",175 }176 want := structType{1.0, 0, 2.0}177 errs := scold.StringMapUnmarshal(sm, &target).(*multierror.Error)178 wantErrs := []error{179 &scold.FieldError{"F32", &scold.NotValueOfTypeError{reflect.Float32.String(), "3.402824E+38", nil}},180 &scold.FieldError{"F64", &scold.NotValueOfTypeError{reflect.Float64.String(), "-2.7976931348623157E+308", nil}},181 }182 td.Cmp(t, errs.Errors, td.Bag(td.Flatten(wantErrs)))183 td.Cmp(t, target, want)184 })185 t.Run("bool field, no error", func(t *testing.T) {186 type structType struct {187 B bool188 }189 target := structType{false}190 sequence := []struct {191 value string192 want structType193 }{194 {"true", structType{true}},195 {"false", structType{false}},196 {"1", structType{true}},197 {"0", structType{false}},198 {"T", structType{true}},199 {"F", structType{false}},200 {"t", structType{true}},201 {"f", structType{false}},202 {"True", structType{true}},203 {"False", structType{false}},204 {"TRUE", structType{true}},205 {"FALSE", structType{false}},206 {"t", structType{true}},207 {"f", structType{false}},208 }209 for _, step := range sequence {210 sm := map[string]string{211 "B": step.value,212 }213 err := scold.StringMapUnmarshal(sm, &target)214 td.CmpNoError(t, err)215 td.Cmp(t, target, step.want, "for value %q", step.value)216 }217 })218 t.Run("bool field, bogus values", func(t *testing.T) {219 type structType struct {220 B bool221 }222 target := structType{false}223 seq1 := []struct {224 value string225 want structType226 }{227 {"tRuE", structType{false}},228 {"2", structType{false}},229 {"~OwO~", structType{false}},230 }231 for _, step := range seq1 {232 sm := map[string]string{233 "B": step.value,234 }235 errs := scold.StringMapUnmarshal(sm, &target).(*multierror.Error)236 td.Cmp(t, errs.Errors, []error{237 &scold.FieldError{"B", &scold.NotValueOfTypeError{reflect.Bool.String(), step.value, nil}},238 })239 td.Cmp(t, target, step.want, "for value %q", step.value)240 }241 target = structType{true}242 seq2 := []struct {243 value string244 want structType245 }{246 {"fAlSe", structType{true}},247 {"00", structType{true}},248 {"x_x", structType{true}},249 }250 for _, step := range seq2 {251 sm := map[string]string{252 "B": step.value,253 }254 errs := scold.StringMapUnmarshal(sm, &target).(*multierror.Error)255 td.Cmp(t, errs.Errors, []error{256 &scold.FieldError{"B", &scold.NotValueOfTypeError{reflect.Bool.String(), step.value, nil}},257 })258 td.Cmp(t, target, step.want, "for value %q", step.value)259 }260 })261 t.Run("report missing fields", func(t *testing.T) {262 target := struct{}{}263 sm := map[string]string{264 "Foo": "42",265 "Bar": "ハロー",266 "": "えっ?",267 }268 errs := scold.StringMapUnmarshal(sm, &target).(*multierror.Error)269 td.CmpError(t, errs)270 wantErrs := []error{271 &scold.FieldError{"Foo", scold.ErrUnknownField},272 &scold.FieldError{"Bar", scold.ErrUnknownField},273 &scold.FieldError{"", scold.ErrUnknownField},274 }275 td.Cmp(t, errs.Errors, td.Bag(td.Flatten(wantErrs)))276 })277 t.Run("string fields", func(t *testing.T) {278 type testType struct {279 Foo string280 Bar string281 Zap string282 Untouched string283 }284 target := testType{}285 sm := map[string]string{286 "Foo": "42",287 "Bar": "ハロー",288 "Zap": "",289 }290 err := scold.StringMapUnmarshal(sm, &target)291 td.CmpNoError(t, err)292 td.Cmp(t, target, testType{"42", "ハロー", "", ""})293 })294 t.Run("plain struct fields cause panic", func(t *testing.T) {295 target1 := struct {296 Info struct{ Age int }297 }{}298 sm := map[string]string{299 "Info": "my age is over 9000",300 }301 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, &target1) }, &scold.NotTextUnmarshalableTypeError{Field: "Info", Type: reflect.Struct, TypeName: "struct { Age int }"})302 type InfoType struct{ Age int }303 target2 := struct {304 Info InfoType305 }{}306 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, &target2) }, &scold.NotTextUnmarshalableTypeError{Field: "Info", Type: reflect.Struct, TypeName: "scold_test.InfoType"})307 target3 := struct {308 Info *InfoType309 }{}310 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, &target3) }, &scold.NotTextUnmarshalableTypeError{Field: "Info", Type: reflect.Ptr, TypeName: "*scold_test.InfoType"})311 type Numbers []int312 target4 := struct {313 Info Numbers314 }{}315 td.CmpPanic(t, func() { _ = scold.StringMapUnmarshal(sm, &target4) }, &scold.NotTextUnmarshalableTypeError{Field: "Info", Type: reflect.Slice, TypeName: "scold_test.Numbers"})316 })317 t.Run("pointer to deserializable type that was allocated", func(t *testing.T) {318 target := struct {319 Dur *scold.PositiveDuration320 }{&scold.PositiveDuration{time.Second}}321 sm := map[string]string{322 "Dur": "5s",323 }324 err := scold.StringMapUnmarshal(sm, &target)325 td.CmpNoError(t, err)326 td.Cmp(t, target, struct{ Dur *scold.PositiveDuration }{&scold.PositiveDuration{5 * time.Second}})327 })328 t.Run("pointer to deserializable type that was NOT allocated should allocate it", func(t *testing.T) {329 target := struct {...

Full Screen

Full Screen

request_test.go

Source:request_test.go Github

copy

Full Screen

...111 )112 t.Cmp(req.URL.String(), "/path?already=true&p1=123&p3=true")113 })114 t.Run("NewRequest panics", func(t *td.T) {115 t.CmpPanic(116 func() { tdhttp.NewRequest("GET", "/path", nil, "H", "V", true) },117 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[2])"))118 t.CmpPanic(119 func() { tdhttp.NewRequest("GET", "/path", nil, "H1", true) },120 td.HasPrefix(`header "H1" should have a string value, not a bool (@ headersQueryParams[1])`))121 t.CmpPanic(122 func() { tdhttp.Get("/path", true) },123 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))124 t.CmpPanic(125 func() { tdhttp.Head("/path", true) },126 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))127 t.CmpPanic(128 func() { tdhttp.Options("/path", nil, true) },129 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))130 t.CmpPanic(131 func() { tdhttp.Post("/path", nil, true) },132 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))133 t.CmpPanic(134 func() { tdhttp.PostForm("/path", nil, true) },135 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))136 t.CmpPanic(137 func() { tdhttp.PostMultipartFormData("/path", &tdhttp.MultipartBody{}, true) },138 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))139 t.CmpPanic(140 func() { tdhttp.Patch("/path", nil, true) },141 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))142 t.CmpPanic(143 func() { tdhttp.Put("/path", nil, true) },144 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))145 t.CmpPanic(146 func() { tdhttp.Delete("/path", nil, true) },147 td.HasPrefix("headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not bool (@ headersQueryParams[0])"))148 // Bad target149 t.CmpPanic(150 func() { tdhttp.NewRequest("GET", ":/badpath", nil) },151 td.HasPrefix(`target is not a valid path: `))152 // Q error153 t.CmpPanic(154 func() { tdhttp.Get("/", tdhttp.Q{"bad": map[string]bool{}}) },155 td.HasPrefix(`headersQueryParams... tdhttp.Q bad parameter: don't know how to add type map[string]bool (map) to param "bad" (@ headersQueryParams[0])`))156 })157 // Get158 t.Cmp(tdhttp.Get("/path", "Foo", "Bar"),159 td.Struct(160 &http.Request{161 Method: "GET",162 Header: http.Header{"Foo": []string{"Bar"}},163 },164 td.StructFields{165 "URL": td.String("/path"),166 }))167 // Head168 t.Cmp(tdhttp.Head("/path", "Foo", "Bar"),169 td.Struct(170 &http.Request{171 Method: "HEAD",172 Header: http.Header{"Foo": []string{"Bar"}},173 },174 td.StructFields{175 "URL": td.String("/path"),176 }))177 // Options178 t.Cmp(tdhttp.Options("/path", nil, "Foo", "Bar"),179 td.Struct(180 &http.Request{181 Method: "OPTIONS",182 Header: http.Header{"Foo": []string{"Bar"}},183 },184 td.StructFields{185 "URL": td.String("/path"),186 }))187 // Post188 t.Cmp(tdhttp.Post("/path", nil, "Foo", "Bar"),189 td.Struct(190 &http.Request{191 Method: "POST",192 Header: http.Header{"Foo": []string{"Bar"}},193 },194 td.StructFields{195 "URL": td.String("/path"),196 }))197 // PostForm - url.Values198 t.Cmp(199 tdhttp.PostForm("/path",200 url.Values{201 "param1": []string{"val1", "val2"},202 "param2": []string{"zip"},203 },204 "Foo", "Bar"),205 td.Struct(206 &http.Request{207 Method: "POST",208 Header: http.Header{209 "Content-Type": []string{"application/x-www-form-urlencoded"},210 "Foo": []string{"Bar"},211 },212 },213 td.StructFields{214 "URL": td.String("/path"),215 "Body": td.Smuggle(216 io.ReadAll,217 []byte("param1=val1&param1=val2&param2=zip"),218 ),219 }))220 // PostForm - td.Q221 t.Cmp(222 tdhttp.PostForm("/path",223 tdhttp.Q{224 "param1": "val1",225 "param2": "val2",226 },227 "Foo", "Bar"),228 td.Struct(229 &http.Request{230 Method: "POST",231 Header: http.Header{232 "Content-Type": []string{"application/x-www-form-urlencoded"},233 "Foo": []string{"Bar"},234 },235 },236 td.StructFields{237 "URL": td.String("/path"),238 "Body": td.Smuggle(239 io.ReadAll,240 []byte("param1=val1&param2=val2"),241 ),242 }))243 // PostForm - nil data244 t.Cmp(245 tdhttp.PostForm("/path", nil, "Foo", "Bar"),246 td.Struct(247 &http.Request{248 Method: "POST",249 Header: http.Header{250 "Content-Type": []string{"application/x-www-form-urlencoded"},251 "Foo": []string{"Bar"},252 },253 },254 td.StructFields{255 "URL": td.String("/path"),256 "Body": td.Smuggle(257 io.ReadAll,258 []byte{},259 ),260 }))261 // PostMultipartFormData262 req := tdhttp.PostMultipartFormData("/path",263 &tdhttp.MultipartBody{264 Boundary: "BoUnDaRy",265 Parts: []*tdhttp.MultipartPart{266 tdhttp.NewMultipartPartString("p1", "body1!"),267 tdhttp.NewMultipartPartString("p2", "body2!"),268 },269 },270 "Foo", "Bar")271 t.Cmp(req,272 td.Struct(273 &http.Request{274 Method: "POST",275 Header: http.Header{276 "Content-Type": []string{`multipart/form-data; boundary="BoUnDaRy"`},277 "Foo": []string{"Bar"},278 },279 },280 td.StructFields{281 "URL": td.String("/path"),282 }))283 if t.CmpNoError(req.ParseMultipartForm(10000)) {284 t.Cmp(req.PostFormValue("p1"), "body1!")285 t.Cmp(req.PostFormValue("p2"), "body2!")286 }287 // Put288 t.Cmp(tdhttp.Put("/path", nil, "Foo", "Bar"),289 td.Struct(290 &http.Request{291 Method: "PUT",292 Header: http.Header{"Foo": []string{"Bar"}},293 },294 td.StructFields{295 "URL": td.String("/path"),296 }))297 // Patch298 t.Cmp(tdhttp.Patch("/path", nil, "Foo", "Bar"),299 td.Struct(300 &http.Request{301 Method: "PATCH",302 Header: http.Header{"Foo": []string{"Bar"}},303 },304 td.StructFields{305 "URL": td.String("/path"),306 }))307 // Delete308 t.Cmp(tdhttp.Delete("/path", nil, "Foo", "Bar"),309 td.Struct(310 &http.Request{311 Method: "DELETE",312 Header: http.Header{"Foo": []string{"Bar"}},313 },314 td.StructFields{315 "URL": td.String("/path"),316 }))317}318type TestStruct struct {319 Name string `json:"name" xml:"name"`320}321func TestNewJSONRequest(tt *testing.T) {322 t := td.NewT(tt)323 t.Run("NewJSONRequest", func(t *td.T) {324 req := tdhttp.NewJSONRequest("GET", "/path",325 TestStruct{326 Name: "Bob",327 },328 "Foo", "Bar",329 "Zip", "Test")330 t.String(req.Header.Get("Content-Type"), "application/json")331 t.String(req.Header.Get("Foo"), "Bar")332 t.String(req.Header.Get("Zip"), "Test")333 body, err := io.ReadAll(req.Body)334 if t.CmpNoError(err, "read request body") {335 t.String(string(body), `{"name":"Bob"}`)336 }337 })338 t.Run("NewJSONRequest panic", func(t *td.T) {339 t.CmpPanic(340 func() { tdhttp.NewJSONRequest("GET", "/path", func() {}) },341 td.Contains("json: unsupported type: func()"))342 t.CmpPanic(343 func() { tdhttp.PostJSON("/path", func() {}) },344 td.Contains("json: unsupported type: func()"))345 t.CmpPanic(346 func() { tdhttp.PutJSON("/path", func() {}) },347 td.Contains("json: unsupported type: func()"))348 t.CmpPanic(349 func() { tdhttp.PatchJSON("/path", func() {}) },350 td.Contains("json: unsupported type: func()"))351 t.CmpPanic(352 func() { tdhttp.DeleteJSON("/path", func() {}) },353 td.Contains("json: unsupported type: func()"))354 t.CmpPanic(355 func() { tdhttp.NewJSONRequest("GET", "/path", td.JSONPointer("/a", 0)) },356 td.Contains("JSON encoding failed: json: error calling MarshalJSON for type *td.tdJSONPointer: JSONPointer TestDeep operator cannot be json.Marshal'led"))357 // Common user mistake358 t.CmpPanic(359 func() { tdhttp.NewJSONRequest("GET", "/path", td.JSON(`{}`)) },360 td.Contains(`JSON encoding failed: json: error calling MarshalJSON for type *td.tdJSON: JSON TestDeep operator cannot be json.Marshal'led, use json.RawMessage() instead`))361 })362 // Post363 t.Cmp(tdhttp.PostJSON("/path", 42, "Foo", "Bar"),364 td.Struct(365 &http.Request{366 Method: "POST",367 Header: http.Header{368 "Foo": []string{"Bar"},369 "Content-Type": []string{"application/json"},370 },371 },372 td.StructFields{373 "URL": td.String("/path"),374 }))375 // Put376 t.Cmp(tdhttp.PutJSON("/path", 42, "Foo", "Bar"),377 td.Struct(378 &http.Request{379 Method: "PUT",380 Header: http.Header{381 "Foo": []string{"Bar"},382 "Content-Type": []string{"application/json"},383 },384 },385 td.StructFields{386 "URL": td.String("/path"),387 }))388 // Patch389 t.Cmp(tdhttp.PatchJSON("/path", 42, "Foo", "Bar"),390 td.Struct(391 &http.Request{392 Method: "PATCH",393 Header: http.Header{394 "Foo": []string{"Bar"},395 "Content-Type": []string{"application/json"},396 },397 },398 td.StructFields{399 "URL": td.String("/path"),400 }))401 // Delete402 t.Cmp(tdhttp.DeleteJSON("/path", 42, "Foo", "Bar"),403 td.Struct(404 &http.Request{405 Method: "DELETE",406 Header: http.Header{407 "Foo": []string{"Bar"},408 "Content-Type": []string{"application/json"},409 },410 },411 td.StructFields{412 "URL": td.String("/path"),413 }))414}415func TestNewXMLRequest(tt *testing.T) {416 t := td.NewT(tt)417 t.Run("NewXMLRequest", func(t *td.T) {418 req := tdhttp.NewXMLRequest("GET", "/path",419 TestStruct{420 Name: "Bob",421 },422 "Foo", "Bar",423 "Zip", "Test")424 t.String(req.Header.Get("Content-Type"), "application/xml")425 t.String(req.Header.Get("Foo"), "Bar")426 t.String(req.Header.Get("Zip"), "Test")427 body, err := io.ReadAll(req.Body)428 if t.CmpNoError(err, "read request body") {429 t.String(string(body), `<TestStruct><name>Bob</name></TestStruct>`)430 }431 })432 t.Run("NewXMLRequest panic", func(t *td.T) {433 t.CmpPanic(434 func() { tdhttp.NewXMLRequest("GET", "/path", func() {}) },435 td.Contains("XML encoding failed"))436 t.CmpPanic(437 func() { tdhttp.PostXML("/path", func() {}) },438 td.Contains("XML encoding failed"))439 t.CmpPanic(440 func() { tdhttp.PutXML("/path", func() {}) },441 td.Contains("XML encoding failed"))442 t.CmpPanic(443 func() { tdhttp.PatchXML("/path", func() {}) },444 td.Contains("XML encoding failed"))445 t.CmpPanic(446 func() { tdhttp.DeleteXML("/path", func() {}) },447 td.Contains("XML encoding failed"))448 })449 // Post450 t.Cmp(tdhttp.PostXML("/path", 42, "Foo", "Bar"),451 td.Struct(452 &http.Request{453 Method: "POST",454 Header: http.Header{455 "Foo": []string{"Bar"},456 "Content-Type": []string{"application/xml"},457 },458 },459 td.StructFields{...

Full Screen

Full Screen

file_test.go

Source:file_test.go Github

copy

Full Screen

...38 assert.Cmp(httpmock.File(file).Bytes(), content)39 })40 assert.Run("Bytes panic", func(assert *td.T) {41 nonexistentFile := filepath.Join(dir, "nonexistent.raw")42 assert.CmpPanic(func() { httpmock.File(nonexistentFile).Bytes() },43 td.HasPrefix("Cannot read "+nonexistentFile))44 })45 assert.Run("String", func(assert *td.T) {46 file := filepath.Join(dir, "ok.txt")47 content := `abc123`48 writeFile(assert, file, []byte(content))49 assert.Cmp(httpmock.File(file).String(), content)50 })51 assert.Run("String panic", func(assert *td.T) {52 nonexistentFile := filepath.Join(dir, "nonexistent.txt")53 assert.CmpPanic(54 func() {55 httpmock.File(nonexistentFile).String() //nolint: govet56 },57 td.HasPrefix("Cannot read "+nonexistentFile))58 })59}...

Full Screen

Full Screen

CmpPanic

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td := td.New()4 td.CmpPanic("package main")5}6main.main()7import (8func main() {9 td := td.New()10 if err := td.Cmp("package main"); err != nil {11 fmt.Printf("error: %s12 }13}

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