github.com/qiniu/go-sdk/v7@v7.27.0/client/json_decode_test.go (about)

     1  //go:build unit
     2  // +build unit
     3  
     4  package client
     5  
     6  import (
     7  	"testing"
     8  )
     9  
    10  func TestJsonDecode(t *testing.T) {
    11  	var ret struct{}
    12  	body := `<?xml version="1.0" encoding="UTF-8"?>
    13  <Error>
    14    <Code>NoSuchKey</Code>
    15    <Message>The resource you requested does not exist</Message>
    16    <Resource>/mybucket/myfoto.jpg</Resource>
    17    <RequestId>4442587FB7D0A2F9</RequestId>
    18  </Error>`
    19  	err := decodeJsonFromData([]byte(body), &ret)
    20  	if err.Error() != "invalid character '<' looking for beginning of value: "+body {
    21  		t.Fatal("unexpected error message", err.Error())
    22  	}
    23  }