crud

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package crud provides a set of tests for CRUD operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTests

func RunTests[T, K any](t *testing.T, setup Setup[T, K])

RunTests runs the CRUD tests for the given type.

Types

type EntityOps

type EntityOps[T, K any] struct {
	NewEntity     func(key int) T // create a new entity with the given key
	ModifyEntity  func(model T) T // modify the given entity
	UnboundEntity func() T        // entity with no key
	ExtractKey    func(T) K       // key extractor
	MissingKey    func() K        // key that does not exist
}

EntityOps contains the operations that do not operate on the repository, but on the entity itself.

type RepoOps

type RepoOps[T, K any] struct {
	GetAll  func(ctx context.Context) ([]T, error)
	GetByID func(ctx context.Context, id K) (T, error)
	Create  func(ctx context.Context, model T) error
	Update  func(ctx context.Context, model T) error
	Delete  func(ctx context.Context, id K) error
}

RepoOps contains the operations that operate on the repository.

type Setup

type Setup[T, K any] struct {
	RepoOps     RepoOps[T, K]
	EntityOps   EntityOps[T, K]
	NotFoundErr func() any // return not found error instance
}

Setup is the setup for the CRUD tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL