fake

package
v2.4.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a map-based cache that supports fast reads via use of atomics. Writes are slow, requiring a copy of the entire cache. The zero Cache is an empty cache, ready for use.

func (*Cache) Get

func (c *Cache) Get(key interface{}, getter func() interface{}) interface{}

Get returns the value of the cache at key. If there is no value, getter is called to provide one, and the cache is updated. The getter function may be called concurrently. It should be pure, returning the same value for every call.

type FakeUploader

type FakeUploader struct {
	SkipInvalidRows     bool
	IgnoreUnknownValues bool
	TableTemplateSuffix string

	Total   int             // Total count of inserted rows.
	Rows    []*InsertionRow // Most recently inserted rows, for testing/debugging.
	Request *bqv2.TableDataInsertAllRequest
	// Set this with SetErr to return an error.  Error is cleared on each call.
	Err       error
	CallCount int // Number of times Put is called

	RejectIfMoreThan int // threshold for producing 400 error.
	// contains filtered or unexported fields
}

FakeUploader is a fake for Uploader, for use in debugging, and tests. See bigquery.Uploader for field info.

func NewFakeUploader

func NewFakeUploader() *FakeUploader

func (*FakeUploader) Put

func (u *FakeUploader) Put(ctx context.Context, src interface{}) error

Put uploads one or more rows to the BigQuery service.

If src is ValueSaver, then its Save method is called to produce a row for uploading.

If src is a struct or pointer to a struct, then a schema is inferred from it and used to create a StructSaver. The InsertID of the StructSaver will be empty.

If src is a slice of ValueSavers, structs, or struct pointers, then each element of the slice is treated as above, and multiple rows are uploaded.

Put returns a PutMultiError if one or more rows failed to be uploaded. The PutMultiError contains a RowInsertionError for each failed row.

Put will retry on temporary errors (see https://cloud.google.com/bigquery/troubleshooting-errors). This can result in duplicate rows if you do not use insert IDs. Also, if the error persists, the call will run indefinitely. Pass a context with a timeout to prevent hanging calls.

func (*FakeUploader) SetErr

func (u *FakeUploader) SetErr(err error)

type Field

type Field struct {
	Name        string       // effective field name
	NameFromTag bool         // did Name come from a tag?
	Type        reflect.Type // field type
	Index       []int        // index sequence, for reflect.Value.FieldByIndex
	ParsedTag   interface{}  // third return value of the parseTag function
	// contains filtered or unexported fields
}

A Field records information about a struct field.

type FieldCache

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

A Cache records information about the fields of struct types.

A Cache is safe for use by multiple goroutines.

func NewFieldCache

func NewFieldCache(parseTag ParseTagFunc, validate ValidateFunc, leafTypes LeafTypesFunc) *FieldCache

NewCache constructs a Cache.

Its first argument should be a function that accepts a struct tag and returns four values: an alternative name for the field extracted from the tag, a boolean saying whether to keep the field or ignore it, additional data that is stored with the field information to avoid having to parse the tag again, and an error.

Its second argument should be a function that accepts a reflect.Type and returns an error if the struct type is invalid in any way. For example, it may check that all of the struct field tags are valid, or that all fields are of an appropriate type.

func (*FieldCache) Fields

func (c *FieldCache) Fields(t reflect.Type) (List, error)

Fields returns all the exported fields of t, which must be a struct type. It follows the standard Go rules for embedded fields, modified by the presence of tags. The result is sorted lexicographically by index.

These rules apply in the absence of tags: Anonymous struct fields are treated as if their inner exported fields were fields in the outer struct (embedding). The result includes all fields that aren't shadowed by fields at higher level of embedding. If more than one field with the same name exists at the same level of embedding, it is excluded. An anonymous field that is not of struct type is treated as having its type as its name.

Tags modify these rules as follows: A field's tag is used as its name. An anonymous struct field with a name given in its tag is treated as a field having that name, rather than an embedded struct (the struct's fields will not be returned). If more than one field with the same name exists at the same level of embedding, but exactly one of them is tagged, then the tagged field is reported and the others are ignored.

type InsertionRow

type InsertionRow struct {
	// If InsertID is non-empty, BigQuery will use it to de-duplicate insertions of
	// this row on a best-effort basis.
	InsertID string
	// The data to be inserted, represented as a map from field name to Value.
	Row map[string]bigquery.Value
}

An InsertionRow represents a row of data to be inserted into a table.

type LeafTypesFunc

type LeafTypesFunc func(reflect.Type) bool

type List

type List []Field

A List is a list of Fields.

func (List) Match

func (l List) Match(name string) *Field

Match returns the field in the list whose name best matches the supplied name, nor nil if no field does. If there is a field with the exact name, it is returned. Otherwise the first field (sorted by index) whose name matches case-insensitively is returned.

func (List) MatchBytes

func (l List) MatchBytes(name []byte) *Field

MatchBytes is identical to Match, except that the argument is a byte slice.

type ParseTagFunc

type ParseTagFunc func(reflect.StructTag) (name string, keep bool, other interface{}, err error)

type ValidateFunc

type ValidateFunc func(reflect.Type) error

Jump to

Keyboard shortcuts

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