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

     1  package patch_modules
     2  
     3  import (
     4  	"context"
     5  	"mime/multipart"
     6  
     7  	"github.com/agiledragon/gomonkey/v2"
     8  
     9  	"github.com/machinefi/w3bstream/pkg/models"
    10  	"github.com/machinefi/w3bstream/pkg/modules/resource"
    11  	"github.com/machinefi/w3bstream/pkg/types"
    12  )
    13  
    14  func ResourceGetContentBySFID(patch *gomonkey.Patches, m *models.Resource, data []byte, err error) *gomonkey.Patches {
    15  	return patch.ApplyFunc(
    16  		resource.GetContentBySFID,
    17  		func(_ context.Context, _ types.SFID) (*models.Resource, []byte, error) {
    18  			return m, data, err
    19  		},
    20  	)
    21  }
    22  
    23  func ResourceGetBySFID(patch *gomonkey.Patches, m *models.Resource, err error) *gomonkey.Patches {
    24  	return patch.ApplyFunc(
    25  		resource.GetBySFID,
    26  		func(_ context.Context, _ types.SFID) (*models.Resource, error) { return m, err },
    27  	)
    28  }
    29  
    30  func ResourceCreate(patch *gomonkey.Patches, m *models.Resource, data []byte, err error) *gomonkey.Patches {
    31  	return patch.ApplyFunc(
    32  		resource.Create,
    33  		func(_ context.Context, _ types.SFID, _ *multipart.FileHeader, _, _ string) (*models.Resource, []byte, error) {
    34  			return m, data, err
    35  		},
    36  	)
    37  }