MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestDecodeAttachmentError

Function TestDecodeAttachmentError

db/attachment_test.go:546–586  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

544}
545
546func TestDecodeAttachmentError(t *testing.T) {
547 attr, err := DecodeAttachment(make([]int, 1))
548 assert.Nil(t, attr, "Attachment of data (type []int) should not get decoded.")
549 assert.Error(t, err, "It should throw 400 invalid attachment data (type []int)")
550 assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest))
551
552 attr, err = DecodeAttachment(make([]float64, 1))
553 assert.Nil(t, attr, "Attachment of data (type []float64) should not get decoded.")
554 assert.Error(t, err, "It should throw 400 invalid attachment data (type []float64)")
555 assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest))
556
557 attr, err = DecodeAttachment(make([]string, 1))
558 assert.Nil(t, attr, "Attachment of data (type []string) should not get decoded.")
559 assert.Error(t, err, "It should throw 400 invalid attachment data (type []string)")
560 assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest))
561
562 attr, err = DecodeAttachment(make(map[string]int, 1))
563 assert.Nil(t, attr, "Attachment of data (type map[string]int) should not get decoded.")
564 assert.Error(t, err, "It should throw 400 invalid attachment data (type map[string]int)")
565 assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest))
566
567 attr, err = DecodeAttachment(make(map[string]float64, 1))
568 assert.Nil(t, attr, "Attachment of data (type map[string]float64) should not get decoded.")
569 assert.Error(t, err, "It should throw 400 invalid attachment data (type map[string]float64)")
570 assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest))
571
572 attr, err = DecodeAttachment(make(map[string]string, 1))
573 assert.Nil(t, attr, "should throw 400 invalid attachment data (type map[string]float64)")
574 assert.Error(t, err, "It 400 invalid attachment data (type map[string]string)")
575 assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest))
576
577 book := struct {
578 author string
579 title string
580 price float64
581 }{author: "William Shakespeare", title: "Hamlet", price: 7.99}
582 attr, err = DecodeAttachment(book)
583 assert.Nil(t, attr)
584 assert.Error(t, err, "It should throw 400 invalid attachment data (type struct { author string; title string; price float64 })")
585 assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest))
586}
587
588func TestSetAttachment(t *testing.T) {
589 db, ctx := setupTestDB(t)

Callers

nothing calls this directly

Calls 3

DecodeAttachmentFunction · 0.85
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected