github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/pkg/couchdb/errors_test.go (about)

     1  package couchdb
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestError_JSON(t *testing.T) {
    11  	couchError := Error{
    12  		StatusCode: 200,
    13  		CouchdbJSON: []byte(`{
    14  			"hello": "couchdb"
    15  		}`),
    16  		Name:     "a name",
    17  		Reason:   "a reason",
    18  		Original: fmt.Errorf("universe %d", 42),
    19  	}
    20  
    21  	asJSON := couchError.JSON()
    22  
    23  	expectedMap := map[string]interface{}{
    24  		"ok":       false,
    25  		"status":   "200",
    26  		"error":    "a name",
    27  		"reason":   "a reason",
    28  		"original": "universe 42",
    29  	}
    30  
    31  	assert.EqualValues(t, expectedMap, asJSON)
    32  }