application

package
v0.0.0-...-cc5f285 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists error = fmt.Errorf("Thing already exists")

Functions

This section is empty.

Types

type App

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

func New

func New(r ThingReader, w ThingWriter) App

func (App) AddRelatedThing

func (a App) AddRelatedThing(ctx context.Context, thingId string, data []byte) error

func (App) CreateOrUpdateThing

func (a App) CreateOrUpdateThing(ctx context.Context, data []byte) error

func (App) CreateThing

func (a App) CreateThing(ctx context.Context, data []byte) error

func (App) IsValidThing

func (a App) IsValidThing(data []byte) (bool, error)

func (App) PatchThing

func (a App) PatchThing(ctx context.Context, thingId string, patch []byte) error

func (App) QueryThings

func (a App) QueryThings(ctx context.Context, conditions map[string][]string) (QueryResult, error)

func (App) RetrieveRelatedThings

func (a App) RetrieveRelatedThings(ctx context.Context, thingId string) ([]byte, error)

func (App) RetrieveThing

func (a App) RetrieveThing(ctx context.Context, thingId string) ([]byte, error)

func (App) Seed

func (a App) Seed(ctx context.Context, data io.Reader) error

func (App) UpdateThing

func (a App) UpdateThing(ctx context.Context, data []byte) error

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type QueryResult

type QueryResult struct {
	Things     []byte
	Count      int
	Limit      int
	Offset     int
	Number     *int
	Size       *int
	TotalCount int64
}

type Thing

type Thing struct {
	Id       string   `json:"id"`
	Type     string   `json:"type"`
	Location Location `json:"location"`
	Tenant   string   `json:"tenant"`
}

type ThingReader

type ThingReader interface {
	QueryThings(ctx context.Context, conditions ...storage.ConditionFunc) (storage.QueryResult, error)
	RetrieveThing(ctx context.Context, thingId string) ([]byte, string, error)
	RetrieveRelatedThings(ctx context.Context, thingId string) ([]byte, error)
}

type ThingReaderMock

type ThingReaderMock struct {
	// QueryThingsFunc mocks the QueryThings method.
	QueryThingsFunc func(ctx context.Context, conditions ...storage.ConditionFunc) (storage.QueryResult, error)

	// RetrieveRelatedThingsFunc mocks the RetrieveRelatedThings method.
	RetrieveRelatedThingsFunc func(ctx context.Context, thingId string) ([]byte, error)

	// RetrieveThingFunc mocks the RetrieveThing method.
	RetrieveThingFunc func(ctx context.Context, thingId string) ([]byte, string, error)
	// contains filtered or unexported fields
}

ThingReaderMock is a mock implementation of ThingReader.

func TestSomethingThatUsesThingReader(t *testing.T) {

	// make and configure a mocked ThingReader
	mockedThingReader := &ThingReaderMock{
		QueryThingsFunc: func(ctx context.Context, conditions ...storage.ConditionFunc) (storage.QueryResult, error) {
			panic("mock out the QueryThings method")
		},
		RetrieveRelatedThingsFunc: func(ctx context.Context, thingId string) ([]byte, error) {
			panic("mock out the RetrieveRelatedThings method")
		},
		RetrieveThingFunc: func(ctx context.Context, thingId string) ([]byte, string, error) {
			panic("mock out the RetrieveThing method")
		},
	}

	// use mockedThingReader in code that requires ThingReader
	// and then make assertions.

}

func (*ThingReaderMock) QueryThings

func (mock *ThingReaderMock) QueryThings(ctx context.Context, conditions ...storage.ConditionFunc) (storage.QueryResult, error)

QueryThings calls QueryThingsFunc.

func (*ThingReaderMock) QueryThingsCalls

func (mock *ThingReaderMock) QueryThingsCalls() []struct {
	Ctx        context.Context
	Conditions []storage.ConditionFunc
}

QueryThingsCalls gets all the calls that were made to QueryThings. Check the length with:

len(mockedThingReader.QueryThingsCalls())

func (*ThingReaderMock) RetrieveRelatedThings

func (mock *ThingReaderMock) RetrieveRelatedThings(ctx context.Context, thingId string) ([]byte, error)

RetrieveRelatedThings calls RetrieveRelatedThingsFunc.

func (*ThingReaderMock) RetrieveRelatedThingsCalls

func (mock *ThingReaderMock) RetrieveRelatedThingsCalls() []struct {
	Ctx     context.Context
	ThingId string
}

RetrieveRelatedThingsCalls gets all the calls that were made to RetrieveRelatedThings. Check the length with:

len(mockedThingReader.RetrieveRelatedThingsCalls())

func (*ThingReaderMock) RetrieveThing

func (mock *ThingReaderMock) RetrieveThing(ctx context.Context, thingId string) ([]byte, string, error)

RetrieveThing calls RetrieveThingFunc.

func (*ThingReaderMock) RetrieveThingCalls

func (mock *ThingReaderMock) RetrieveThingCalls() []struct {
	Ctx     context.Context
	ThingId string
}

RetrieveThingCalls gets all the calls that were made to RetrieveThing. Check the length with:

len(mockedThingReader.RetrieveThingCalls())

type ThingWriter

type ThingWriter interface {
	CreateThing(ctx context.Context, v []byte) error
	UpdateThing(ctx context.Context, v []byte) error
	AddRelatedThing(ctx context.Context, thingId string, v []byte) error
}

type ThingWriterMock

type ThingWriterMock struct {
	// AddRelatedThingFunc mocks the AddRelatedThing method.
	AddRelatedThingFunc func(ctx context.Context, thingId string, v []byte) error

	// CreateThingFunc mocks the CreateThing method.
	CreateThingFunc func(ctx context.Context, v []byte) error

	// UpdateThingFunc mocks the UpdateThing method.
	UpdateThingFunc func(ctx context.Context, v []byte) error
	// contains filtered or unexported fields
}

ThingWriterMock is a mock implementation of ThingWriter.

func TestSomethingThatUsesThingWriter(t *testing.T) {

	// make and configure a mocked ThingWriter
	mockedThingWriter := &ThingWriterMock{
		AddRelatedThingFunc: func(ctx context.Context, thingId string, v []byte) error {
			panic("mock out the AddRelatedThing method")
		},
		CreateThingFunc: func(ctx context.Context, v []byte) error {
			panic("mock out the CreateThing method")
		},
		UpdateThingFunc: func(ctx context.Context, v []byte) error {
			panic("mock out the UpdateThing method")
		},
	}

	// use mockedThingWriter in code that requires ThingWriter
	// and then make assertions.

}

func (*ThingWriterMock) AddRelatedThing

func (mock *ThingWriterMock) AddRelatedThing(ctx context.Context, thingId string, v []byte) error

AddRelatedThing calls AddRelatedThingFunc.

func (*ThingWriterMock) AddRelatedThingCalls

func (mock *ThingWriterMock) AddRelatedThingCalls() []struct {
	Ctx     context.Context
	ThingId string
	V       []byte
}

AddRelatedThingCalls gets all the calls that were made to AddRelatedThing. Check the length with:

len(mockedThingWriter.AddRelatedThingCalls())

func (*ThingWriterMock) CreateThing

func (mock *ThingWriterMock) CreateThing(ctx context.Context, v []byte) error

CreateThing calls CreateThingFunc.

func (*ThingWriterMock) CreateThingCalls

func (mock *ThingWriterMock) CreateThingCalls() []struct {
	Ctx context.Context
	V   []byte
}

CreateThingCalls gets all the calls that were made to CreateThing. Check the length with:

len(mockedThingWriter.CreateThingCalls())

func (*ThingWriterMock) UpdateThing

func (mock *ThingWriterMock) UpdateThing(ctx context.Context, v []byte) error

UpdateThing calls UpdateThingFunc.

func (*ThingWriterMock) UpdateThingCalls

func (mock *ThingWriterMock) UpdateThingCalls() []struct {
	Ctx context.Context
	V   []byte
}

UpdateThingCalls gets all the calls that were made to UpdateThing. Check the length with:

len(mockedThingWriter.UpdateThingCalls())

Jump to

Keyboard shortcuts

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