Documentation
¶
Overview ¶
Package mock provides a mock server for testing generated storage layer code.
Index ¶
- func TestOrderData() []map[string]interface{}
- func TestProductData() []map[string]interface{}
- func TestUserData() []map[string]interface{}
- func ToJSON(v interface{}) string
- type GenericRequest
- type GenericResponse
- type GenericService
- type MockServer
- type MockStore
- func (s *MockStore) Clear()
- func (s *MockStore) Delete(table string, where map[string]interface{}) (int64, error)
- func (s *MockStore) GetAllRecords(table string) []map[string]interface{}
- func (s *MockStore) Insert(table string, record map[string]interface{}) (int64, error)
- func (s *MockStore) SeedData(table string, records []map[string]interface{}) error
- func (s *MockStore) Select(table string, where map[string]interface{}) ([]map[string]interface{}, error)
- func (s *MockStore) SelectOne(table string, where map[string]interface{}) (map[string]interface{}, error)
- func (s *MockStore) Truncate(table string) error
- func (s *MockStore) Update(table string, set map[string]interface{}, where map[string]interface{}) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestOrderData ¶
func TestOrderData() []map[string]interface{}
TestOrderData provides sample order data for testing
func TestProductData ¶
func TestProductData() []map[string]interface{}
TestProductData provides sample product data for testing
func TestUserData ¶
func TestUserData() []map[string]interface{}
TestUserData provides sample user data for testing
Types ¶
type GenericRequest ¶
type GenericRequest struct {
Table string `json:"table"`
Data map[string]interface{} `json:"data,omitempty"`
Where map[string]interface{} `json:"where,omitempty"`
Set map[string]interface{} `json:"set,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
GenericRequest represents a generic request
type GenericResponse ¶
type GenericResponse struct {
Success bool `json:"success"`
Records []map[string]interface{} `json:"records,omitempty"`
AffectedRows int64 `json:"affected_rows,omitempty"`
InsertedID int64 `json:"inserted_id,omitempty"`
Error string `json:"error,omitempty"`
}
GenericResponse represents a generic response
type GenericService ¶
type GenericService struct {
// contains filtered or unexported fields
}
GenericService provides a generic CRUD interface
func NewGenericService ¶
func NewGenericService(store *MockStore) *GenericService
NewGenericService creates a new generic service
func (*GenericService) Execute ¶
func (s *GenericService) Execute(ctx context.Context, operation string, req GenericRequest) (*GenericResponse, error)
Execute performs a generic operation
type MockServer ¶
type MockServer struct {
// contains filtered or unexported fields
}
MockServer wraps the mock store with a service interface
func (*MockServer) Service ¶
func (s *MockServer) Service() *GenericService
Service returns the generic service
func (*MockServer) Store ¶
func (s *MockServer) Store() *MockStore
Store returns the underlying mock store
type MockStore ¶
type MockStore struct {
// contains filtered or unexported fields
}
MockStore provides an in-memory data store for testing
func SetupTestStore ¶
func SetupTestStore() *MockStore
SetupTestStore creates a store with test data
func (*MockStore) GetAllRecords ¶
GetAllRecords returns all records in a table (for testing)
func (*MockStore) Select ¶
func (s *MockStore) Select(table string, where map[string]interface{}) ([]map[string]interface{}, error)
Select retrieves records from a table
func (*MockStore) SelectOne ¶
func (s *MockStore) SelectOne(table string, where map[string]interface{}) (map[string]interface{}, error)
SelectOne retrieves a single record