database

package
v0.0.0-...-ab5431c Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func LoadConfiguration

func LoadConfiguration(ctx context.Context) Config

func (Config) ConnStr

func (c Config) ConnStr() string

type LogValue

type LogValue struct {
	Value     float64   `json:"v"`
	Timestamp time.Time `json:"ts"`
}

type Storage

type Storage interface {
	Initialize(context.Context) error
	Add(ctx context.Context, id, label string, value float64, timestamp time.Time) error
	AddFnct(ctx context.Context, id, fnType, subType, tenant, source string, lat, lon float64) error
	History(ctx context.Context, id, label string, lastN int) ([]LogValue, error)
}

func Connect

func Connect(ctx context.Context, cfg Config) (Storage, error)

type StorageMock

type StorageMock struct {
	// AddFunc mocks the Add method.
	AddFunc func(ctx context.Context, id string, label string, value float64, timestamp time.Time) error

	// AddFnFunc mocks the AddFn method.
	AddFnFunc func(ctx context.Context, id string, fnType string, subType string, tenant string, source string, lat float64, lon float64) error

	// HistoryFunc mocks the History method.
	HistoryFunc func(ctx context.Context, id string, label string, lastN int) ([]LogValue, error)

	// InitializeFunc mocks the Initialize method.
	InitializeFunc func(contextMoqParam context.Context) 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{
		AddFunc: func(ctx context.Context, id string, label string, value float64, timestamp time.Time) error {
			panic("mock out the Add method")
		},
		AddFnFunc: func(ctx context.Context, id string, fnType string, subType string, tenant string, source string, lat float64, lon float64) error {
			panic("mock out the AddFn method")
		},
		HistoryFunc: func(ctx context.Context, id string, label string, lastN int) ([]LogValue, error) {
			panic("mock out the History method")
		},
		InitializeFunc: func(contextMoqParam context.Context) error {
			panic("mock out the Initialize method")
		},
	}

	// use mockedStorage in code that requires Storage
	// and then make assertions.

}

func (*StorageMock) Add

func (mock *StorageMock) Add(ctx context.Context, id string, label string, value float64, timestamp time.Time) error

Add calls AddFunc.

func (*StorageMock) AddCalls

func (mock *StorageMock) AddCalls() []struct {
	Ctx       context.Context
	ID        string
	Label     string
	Value     float64
	Timestamp time.Time
}

AddCalls gets all the calls that were made to Add. Check the length with:

len(mockedStorage.AddCalls())

func (*StorageMock) AddFnCalls

func (mock *StorageMock) AddFnCalls() []struct {
	Ctx     context.Context
	ID      string
	FnType  string
	SubType string
	Tenant  string
	Source  string
	Lat     float64
	Lon     float64
}

AddFnCalls gets all the calls that were made to AddFn. Check the length with:

len(mockedStorage.AddFnCalls())

func (*StorageMock) AddFnct

func (mock *StorageMock) AddFnct(ctx context.Context, id string, fnType string, subType string, tenant string, source string, lat float64, lon float64) error

AddFnct calls AddFnFunc.

func (*StorageMock) History

func (mock *StorageMock) History(ctx context.Context, id string, label string, lastN int) ([]LogValue, error)

History calls HistoryFunc.

func (*StorageMock) HistoryCalls

func (mock *StorageMock) HistoryCalls() []struct {
	Ctx   context.Context
	ID    string
	Label string
	LastN int
}

HistoryCalls gets all the calls that were made to History. Check the length with:

len(mockedStorage.HistoryCalls())

func (*StorageMock) Initialize

func (mock *StorageMock) Initialize(contextMoqParam context.Context) error

Initialize calls InitializeFunc.

func (*StorageMock) InitializeCalls

func (mock *StorageMock) InitializeCalls() []struct {
	ContextMoqParam context.Context
}

InitializeCalls gets all the calls that were made to Initialize. Check the length with:

len(mockedStorage.InitializeCalls())

Jump to

Keyboard shortcuts

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