fixture

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2019 License: MIT Imports: 9 Imported by: 0

README

bt-fixture

bt-fixture is a test-fixture management library for the Cloud Bigtable.

GoDoc CircleCI Go Report Card

Management the fixtures of the database for testing.

Features

  • Load the Cloud Bigtable columns fixture by a yaml file
  • Before cleanup a table
  • Types
    • int and float types in a fixture convert to big-endian 8-byte values

Usage

  • Import bt-fixture package and setup a fixture file
package main

import (
  fixture "github.com/takashabe/bt-fixture"
)

func main() {
  // omit the error handling
  f, _ := fixture.New("test-project", "test-instance")
  f.Load("testdata/fixture.yaml")
}

Fixture file format

table: person
column_families:
  - family: d
    columns:
      - key: 1##a
        rows:
          name: a
          age: 10
          height: 140.0
        version: 2018-05-19 00:00:00 +00:00
      - key: 1##a
        rows:
          name: a
          abe: 11
          height: 140.0
        version: 2019-05-19 00:00:00 +00:00
  - family: e
    columns:
      - key: 2##b
        rows:
          name: b
          age: 20
          height: 180.0
        version: 2018-05-19 00:00:00 +00:00
  • Example output:
$cbt read person
----------------------------------------
1##a
  d:age                                    @ 2019/05/19-00:00:00.000000
    "\x00\x00\x00\x00\x00\x00\x00\v"
  d:age                                    @ 2018/05/19-00:00:00.000000
    "\x00\x00\x00\x00\x00\x00\x00\n"
  d:height                                 @ 2019/05/19-00:00:00.000000
    "@a\x80\x00\x00\x00\x00\x00"
  d:height                                 @ 2018/05/19-00:00:00.000000
    "@a\x80\x00\x00\x00\x00\x00"
  d:name                                   @ 2019/05/19-00:00:00.000000
    "a"
  d:name                                   @ 2018/05/19-00:00:00.000000
    "a"
----------------------------------------
2##b
  e:age                                    @ 2018/05/19-00:00:00.000000
    "\x00\x00\x00\x00\x00\x00\x00\x14"
  e:height                                 @ 2018/05/19-00:00:00.000000
    "@f\x80\x00\x00\x00\x00\x00"
  e:name                                   @ 2018/05/19-00:00:00.000000
    "b"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailReadFile   = errors.New("failed to read file")
	ErrInvalidFixture = errors.New("invalid fixture file format")
	ErrUnknownFileExt = errors.New("unknown file ext")
)

error variables

Functions

func MarshalBigEndian added in v0.2.0

func MarshalBigEndian(v interface{}) ([]byte, error)

MarshalBigEndian returns the BigEndian byte encoding of v

Types

type ColumnFamilies

type ColumnFamilies struct {
	Family  string    `yaml:"family"`
	Columns []Columns `yaml:"columns"`
}

ColumnFamilies represent mapping ColumnFamilies with the fixture

type Columns

type Columns struct {
	Key     string                 `yaml:"key"`
	Rows    map[string]interface{} `yaml:"rows"`
	Version Version                `yaml:"version"`
}

Columns represent mapping Columns with the fixture

type Fixture

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

Fixture provide fixture methods

func New added in v0.1.0

func New(project, instance string, opts ...Option) (*Fixture, error)

New returns initialized Fixture

func (*Fixture) Load

func (f *Fixture) Load(path string) error

Load load .yml script

type Marshaler added in v0.2.0

type Marshaler func(v interface{}) ([]byte, error)

Marshaler provides endocing value

type Option added in v0.2.0

type Option func(*Fixture)

Option represents functionl-option-pattern

func WithMarshaler added in v0.2.0

func WithMarshaler(m Marshaler) Option

WithMarshaler setting the Marshaler

type QueryModelWithYaml

type QueryModelWithYaml struct {
	Table          string           `yaml:"table"`
	ColumnFamilies []ColumnFamilies `yaml:"column_families"`
}

QueryModelWithYaml represent fixture yaml file mapper

type Version

type Version struct {
	time.Time
}

Version represent specific timestamp

func (*Version) UnmarshalYAML

func (v *Version) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implemented Unmarshaler of the Version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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