github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/test/patch_std/patch_json.go (about)

     1  package patch_std
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/agiledragon/gomonkey/v2"
     7  )
     8  
     9  func JsonMarshal(patch *gomonkey.Patches, data []byte, err error) *gomonkey.Patches {
    10  	return patch.ApplyFunc(
    11  		json.Marshal,
    12  		func(_ interface{}) ([]byte, error) { return data, err },
    13  	)
    14  }
    15  
    16  func JsonUnmarshal(patch *gomonkey.Patches, err error) *gomonkey.Patches {
    17  	return patch.ApplyFunc(
    18  		json.Unmarshal,
    19  		func(_ []byte, _ interface{}) error { return err },
    20  	)
    21  }