passert

package
v2.32.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: Apache-2.0, BSD-3-Clause, MIT Imports: 18 Imported by: 0

Documentation

Overview

Package passert contains verification transformations for testing pipelines. The transformations are not tied to any particular runner, i.e., they can notably be used for remote execution runners, such as Dataflow.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllWithinBounds

func AllWithinBounds(s beam.Scope, col beam.PCollection, lo, hi float64)

AllWithinBounds checks that a PCollection of numeric types is within the bounds [lo, high]. Checks for case where bounds are flipped and swaps them so the bounds passed to the doFn are always lo <= hi.

func Count

func Count(s beam.Scope, col beam.PCollection, name string, count int)

Count verifies the given PCollection<T> has the specified number of elements.

func Diff

func Diff(s beam.Scope, a, b beam.PCollection) (left, both, right beam.PCollection)

Diff splits 2 incoming PCollections into 3: left only, both, right only. Duplicates are preserved, so a value may appear multiple times and in multiple collections. Coder equality is used to determine equality. Should only be used for small collections, because all values are held in memory at the same time.

func Empty

func Empty(s beam.Scope, col beam.PCollection) beam.PCollection

Empty asserts that col is empty.

func Equals

func Equals(s beam.Scope, col beam.PCollection, values ...interface{}) beam.PCollection

Equals verifies the given collection has the same values as the given values, under coder equality. The values can be provided as single PCollection.

Example
p, s := beam.NewPipelineWithRoot()
col := beam.Create(s, "some", "example", "strings")

Equals(s, col, "example", "some", "strings")
err := ptest.Run(p)
fmt.Println(err == nil)
Output:

true
Example (Pcollection)
p, s := beam.NewPipelineWithRoot()
col := beam.Create(s, "some", "example", "strings")
exp := beam.Create(s, "example", "some", "strings")

Equals(s, col, exp)
err := ptest.Run(p)
fmt.Println(err == nil)
Output:

true

func EqualsFloat

func EqualsFloat(s beam.Scope, observed, expected beam.PCollection, threshold float64)

Equals float calls into TryEqualsFloat, checkong that two PCollections of non-complex numeric types are equal, with each element being within a provided threshold of an expected value. Panics if TryEqualsFloat returns an error.

func EqualsList

func EqualsList(s beam.Scope, col beam.PCollection, list interface{}) beam.PCollection

EqualsList verifies that the given collection has the same values as a given list, under coder equality. The values must be provided as an array or slice. This is equivalent to passing a beam.CreateList PCollection to Equals.

Example
p, s := beam.NewPipelineWithRoot()
col := beam.Create(s, "example", "inputs", "here")
list := [3]string{"here", "example", "inputs"}

EqualsList(s, col, list)
err := ptest.Run(p)
fmt.Println(err == nil)
Output:

true
Example (Mismatch)
p, s := beam.NewPipelineWithRoot()
col := beam.Create(s, "example", "inputs", "here")
list := [3]string{"wrong", "inputs", "here"}

EqualsList(s, col, list)
err := ptest.Run(p)
err = unwrapError(err)
fmt.Println(err)
Output:

actual PCollection does not match expected values
=========
2 correct entries (present in both)
=========
1 unexpected entries (present in actual, missing in expected)
+++
example
=========
1 missing entries (missing in actual, present in expected)
---
wrong

func False

func False(s beam.Scope, col beam.PCollection, fn interface{}) beam.PCollection

False asserts that the given predicate does not satisfy any element in the condition.

func Hash

func Hash(s beam.Scope, col beam.PCollection, name, hash string, size int)

Hash validates that the incoming PCollection<string> has the given size and base64-encoded MD5 hash code. It buffers the entire PCollection in memory and sorts it for determinism.

func Sum

func Sum(s beam.Scope, col beam.PCollection, name string, size, value int)

Sum validates that the sum and count of elements in the incoming PCollection<int> is the same as the given sum and count, under coder equality. Sum is a specialized version of Equals that avoids a lot of machinery for testing.

func True

func True(s beam.Scope, col beam.PCollection, fn interface{}) beam.PCollection

True asserts that all elements satisfy the given predicate.

func TryEqualsFloat

func TryEqualsFloat(s beam.Scope, observed, expected beam.PCollection, threshold float64) error

TryEqualsFloat checks that two PCollections of floats are equal, with each element being within a specified threshold of its corresponding element. Both PCollections are loaded into memory, sorted, and compared element by element. Returns an error if the PCollection types are complex or non-numeric.

Types

This section is empty.

Jump to

Keyboard shortcuts

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