mock

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package mock provides a mock server for testing generated storage layer code.

Index

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

func ToJSON

func ToJSON(v interface{}) string

ToJSON converts an interface to JSON string

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 NewMockServer

func NewMockServer() *MockServer

NewMockServer creates a new mock server

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 NewMockStore

func NewMockStore() *MockStore

NewMockStore creates a new mock store

func SetupTestStore

func SetupTestStore() *MockStore

SetupTestStore creates a store with test data

func (*MockStore) Clear

func (s *MockStore) Clear()

Clear removes all data from all tables

func (*MockStore) Delete

func (s *MockStore) Delete(table string, where map[string]interface{}) (int64, error)

Delete removes records from a table

func (*MockStore) GetAllRecords

func (s *MockStore) GetAllRecords(table string) []map[string]interface{}

GetAllRecords returns all records in a table (for testing)

func (*MockStore) Insert

func (s *MockStore) Insert(table string, record map[string]interface{}) (int64, error)

Insert adds a record to a table

func (*MockStore) SeedData

func (s *MockStore) SeedData(table string, records []map[string]interface{}) error

SeedData populates the store with test data

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

func (*MockStore) Truncate

func (s *MockStore) Truncate(table string) error

Truncate removes all records from a table

func (*MockStore) Update

func (s *MockStore) Update(table string, set map[string]interface{}, where map[string]interface{}) (int64, error)

Update modifies records in a table

Jump to

Keyboard shortcuts

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