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

     1  package patch_modules
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/agiledragon/gomonkey/v2"
     7  
     8  	"github.com/machinefi/w3bstream/pkg/depends/base/types"
     9  	"github.com/machinefi/w3bstream/pkg/enums"
    10  	"github.com/machinefi/w3bstream/pkg/models"
    11  	"github.com/machinefi/w3bstream/pkg/modules/config"
    12  	"github.com/machinefi/w3bstream/pkg/types/wasm"
    13  )
    14  
    15  func ConfigRemove(patch *gomonkey.Patches, err error) *gomonkey.Patches {
    16  	return patch.ApplyFunc(
    17  		config.Remove,
    18  		func(_ context.Context, _ *config.CondArgs) error { return err },
    19  	)
    20  }
    21  func ConfigCreate(patch *gomonkey.Patches, v *models.Config, err error) *gomonkey.Patches {
    22  	return patch.ApplyFunc(
    23  		config.Create,
    24  		func(_ context.Context, _ types.SFID, _ wasm.Configuration) (*models.Config, error) { return v, err },
    25  	)
    26  }
    27  
    28  func ConfigList(patch *gomonkey.Patches, v []*config.Detail, err error) *gomonkey.Patches {
    29  	return patch.ApplyFunc(
    30  		config.List,
    31  		func(_ context.Context, _ *config.CondArgs) ([]*config.Detail, error) { return v, err },
    32  	)
    33  }
    34  
    35  func ConfigMarshal(patch *gomonkey.Patches, data []byte, err error) *gomonkey.Patches {
    36  	return patch.ApplyFunc(
    37  		config.Marshal,
    38  		func(_ wasm.Configuration) ([]byte, error) { return data, err },
    39  	)
    40  }
    41  
    42  func ConfigUnmarshal(patch *gomonkey.Patches, c wasm.Configuration, err error) *gomonkey.Patches {
    43  	return patch.ApplyFunc(
    44  		config.Unmarshal,
    45  		func(_ []byte, _ enums.ConfigType) (wasm.Configuration, error) { return c, err },
    46  	)
    47  }