mockdatasource

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package mockdatasource provides mock objects for datasource package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NopWriteCloser

func NopWriteCloser(w io.Writer) io.WriteCloser

NopWriteCloser returns a nopWriteCloser.

Types

type MockDatasource

type MockDatasource struct {
	Name          string
	Type          datasource.Type
	Database      string
	Engine        datasource.Engine
	Inline        string
	Host          string
	Port          string
	User          string
	UserPw        string
	Admin         string
	AdminPw       string
	URL           string
	URLAdmin      string
	URLNoDb       string
	Transaction   bool
	Schema        string
	FilePath      string
	TmpFilePath   string
	Gzip          bool
	Zip           bool
	FileHandle    io.Closer
	Filewriter    bool
	Tags          []string
	ErrorOpenDb   error
	ErrorOpenFile error
	ErrorReset    error
	ErrorClose    error
	FileNotExists bool
	TableExists   bool
	TableEmpty    bool
	MockedDb      *sql.DB
	WriteBuf      bytes.Buffer
}

MockDatasource is fake datasource object for test purpose.

func (*MockDatasource) CloseDatabase added in v1.3.0

func (ds *MockDatasource) CloseDatabase(log *logrus.Entry, admin bool, nodb bool) error

CloseDatabase close connection to the corresponding database only if no more used.

func (*MockDatasource) CloseFile

func (ds *MockDatasource) CloseFile(log *logrus.Entry) error

CloseFile close the file and rename the temporary file to real name (if exists).

func (*MockDatasource) FillTmplValues

func (ds *MockDatasource) FillTmplValues() datasource.TmplValues

FillTmplValues return a struct for template operation with value corresponding to the provided datasource.

func (*MockDatasource) GetEngine

func (ds *MockDatasource) GetEngine() datasource.Engine

GetEngine return the engine enum value.

func (*MockDatasource) GetHash added in v1.1.0

func (ds *MockDatasource) GetHash(log *logrus.Entry, admin bool, nodb bool) string

GetHash returns uniq hash for the datasource final destination (more than one datasource could have the same hash by example same database engine).

func (*MockDatasource) GetName

func (ds *MockDatasource) GetName() string

GetName return the name of the datasource.

func (*MockDatasource) GetNamedTag

func (ds *MockDatasource) GetNamedTag(name string) string

GetNamedTag return the value of the tag with the provided name or "" if not exists.

func (*MockDatasource) GetType

func (ds *MockDatasource) GetType() datasource.Type

GetType return the type enum value.

func (*MockDatasource) IsTableEmpty added in v1.2.2

func (ds *MockDatasource) IsTableEmpty(ctx context.Context, log *logrus.Entry, table string) (bool, error)

IsTableEmpty return true if the table empty.

func (*MockDatasource) IsTableExists added in v1.2.2

func (ds *MockDatasource) IsTableExists(ctx context.Context, log *logrus.Entry, table string) (bool, error)

IsTableExists return true if the table exists.

func (*MockDatasource) IsTransaction

func (ds *MockDatasource) IsTransaction() bool

IsTransaction return true if the datasource has transaction.

func (*MockDatasource) OpenDatabase

func (ds *MockDatasource) OpenDatabase(log *logrus.Entry, admin bool, nodb bool) (*sql.DB, error)

OpenDatabase open connection to the corresponding database.

func (*MockDatasource) OpenReadFile

func (ds *MockDatasource) OpenReadFile(log *logrus.Entry) (io.ReadCloser, error)

OpenReadFile open and return a io.ReadCloser on the WriteBuf element.

func (*MockDatasource) OpenWriteFile

func (ds *MockDatasource) OpenWriteFile(log *logrus.Entry) (io.WriteCloser, error)

OpenWriteFile open and return a io.WriteCloser on the WriteBuf element.

func (*MockDatasource) ResetFile

func (ds *MockDatasource) ResetFile(log *logrus.Entry) error

ResetFile close the file and remove the temporary file.

func (*MockDatasource) Stat

func (ds *MockDatasource) Stat() (os.FileInfo, error)

Stat returns os.FileInfo on the file of the datasource.

type MockDatasources

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

MockDatasources is fake datasources object for test purpose.

func New

func New() *MockDatasources

New returns a new Datasources object with elments initialized.

func (*MockDatasources) CloseAll

func (dss *MockDatasources) CloseAll(log *logrus.Entry)

CloseAll do nothing, return an error if path is empty.

func (*MockDatasources) Insert

func (dss *MockDatasources) Insert(limited bool, tags []string, dsTypes []datasource.Type, engines []datasource.Engine, ds []*MockDatasource)

Insert add a Mocked datasource to the array.

func (*MockDatasources) LoadAll

func (dss *MockDatasources) LoadAll(path string, log *logrus.Entry) error

LoadAll do nothing, return an error if path is empty.

func (*MockDatasources) Lookup

func (dss *MockDatasources) Lookup(log *logrus.Entry, tags []string, limitedTags []string, dsTypes []datasource.Type, engines []datasource.Engine) ([]datasource.Datasourcer, []datasource.Datasourcer, error)

Lookup : return the corresponding array of Mocked datasources WARNING: the algorithm of lookup is much simpler than the one from the object, all the parameters must be exactly the same !

Jump to

Keyboard shortcuts

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