Documentation ¶
Index ¶
- func CreateOrUpdate[T any](ctx context.Context, storage Storage, id string, value T) error
- func Get[T any](ctx context.Context, storage Storage, id string) (T, error)
- func GetOrDefault[T any](ctx context.Context, storage Storage, id string, defaultValue T) (T, error)
- func GetTypeName[T any]() string
- type Storage
- type StorageMock
- func (mock *StorageMock) Create(ctx context.Context, id string, typeName string, value any) error
- func (mock *StorageMock) CreateCalls() []struct{ ... }
- func (mock *StorageMock) Exists(ctx context.Context, id string, typeName string) bool
- func (mock *StorageMock) ExistsCalls() []struct{ ... }
- func (mock *StorageMock) Read(ctx context.Context, id string, typeName string) (any, error)
- func (mock *StorageMock) ReadCalls() []struct{ ... }
- func (mock *StorageMock) Update(ctx context.Context, id string, typeName string, value any) error
- func (mock *StorageMock) UpdateCalls() []struct{ ... }
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateOrUpdate ¶
func GetOrDefault ¶
func GetTypeName ¶
Types ¶
type StorageMock ¶
type StorageMock struct { // CreateFunc mocks the Create method. CreateFunc func(ctx context.Context, id string, typeName string, value any) error // ExistsFunc mocks the Exists method. ExistsFunc func(ctx context.Context, id string, typeName string) bool // ReadFunc mocks the Read method. ReadFunc func(ctx context.Context, id string, typeName string) (any, error) // UpdateFunc mocks the Update method. UpdateFunc func(ctx context.Context, id string, typeName string, value any) error // contains filtered or unexported fields }
StorageMock is a mock implementation of Storage.
func TestSomethingThatUsesStorage(t *testing.T) { // make and configure a mocked Storage mockedStorage := &StorageMock{ CreateFunc: func(ctx context.Context, id string, typeName string, value any) error { panic("mock out the Create method") }, ExistsFunc: func(ctx context.Context, id string, typeName string) bool { panic("mock out the Exists method") }, ReadFunc: func(ctx context.Context, id string, typeName string) (any, error) { panic("mock out the Read method") }, UpdateFunc: func(ctx context.Context, id string, typeName string, value any) error { panic("mock out the Update method") }, } // use mockedStorage in code that requires Storage // and then make assertions. }
func (*StorageMock) CreateCalls ¶
func (mock *StorageMock) CreateCalls() []struct { Ctx context.Context ID string TypeName string Value any }
CreateCalls gets all the calls that were made to Create. Check the length with:
len(mockedStorage.CreateCalls())
func (*StorageMock) ExistsCalls ¶
func (mock *StorageMock) ExistsCalls() []struct { Ctx context.Context ID string TypeName string }
ExistsCalls gets all the calls that were made to Exists. Check the length with:
len(mockedStorage.ExistsCalls())
func (*StorageMock) ReadCalls ¶
func (mock *StorageMock) ReadCalls() []struct { Ctx context.Context ID string TypeName string }
ReadCalls gets all the calls that were made to Read. Check the length with:
len(mockedStorage.ReadCalls())
func (*StorageMock) UpdateCalls ¶
func (mock *StorageMock) UpdateCalls() []struct { Ctx context.Context ID string TypeName string Value any }
UpdateCalls gets all the calls that were made to Update. Check the length with:
len(mockedStorage.UpdateCalls())
Click to show internal directories.
Click to hide internal directories.