table

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 5 Imported by: 34

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DescribeTable

func DescribeTable(description string, itBody interface{}, entries ...TableEntry) bool

DescribeTable describes a table-driven test.

For example:

DescribeTable("a simple table",
    func(x int, y int, expected bool) {
        Ω(x > y).Should(Equal(expected))
    },
    Entry("x > y", 1, 0, true),
    Entry("x == y", 0, 0, false),
    Entry("x < y", 0, 1, false),
)

The first argument to `DescribeTable` is a string description. The second argument is a function that will be run for each table entry. Your assertions go here - the function is equivalent to a Ginkgo It. The subsequent arguments must be of type `TableEntry`. We recommend using the `Entry` convenience constructors.

The `Entry` constructor takes a string description followed by an arbitrary set of parameters. These parameters are passed into your function.

Under the hood, `DescribeTable` simply generates a new Ginkgo `Describe`. Each `Entry` is turned into an `It` within the `Describe`.

It's important to understand that the `Describe`s and `It`s are generated at evaluation time (i.e. when Ginkgo constructs the tree of tests and before the tests run).

Individual Entries can be focused (with FEntry) or marked pending (with PEntry or XEntry). In addition, the entire table can be focused or marked pending with FDescribeTable and PDescribeTable/XDescribeTable.

A description function can be passed to Entry in place of the description. The function is then fed with the entry parameters to generate the description of the It corresponding to that particular Entry.

For example:

describe := func(desc string) func(int, int, bool) string {
	return func(x, y int, expected bool) string {
		return fmt.Sprintf("%s x=%d y=%d expected:%t", desc, x, y, expected)
	}
}

DescribeTable("a simple table",
	func(x int, y int, expected bool) {
		Ω(x > y).Should(Equal(expected))
	},
	Entry(describe("x > y"), 1, 0, true),
	Entry(describe("x == y"), 0, 0, false),
	Entry(describe("x < y"), 0, 1, false),
)

func FDescribeTable

func FDescribeTable(description string, itBody interface{}, entries ...TableEntry) bool

You can focus a table with `FDescribeTable`. This is equivalent to `FDescribe`.

func PDescribeTable

func PDescribeTable(description string, itBody interface{}, entries ...TableEntry) bool

You can mark a table as pending with `PDescribeTable`. This is equivalent to `PDescribe`.

func XDescribeTable

func XDescribeTable(description string, itBody interface{}, entries ...TableEntry) bool

You can mark a table as pending with `XDescribeTable`. This is equivalent to `XDescribe`.

Types

type TableEntry

type TableEntry struct {
	Description interface{}
	Parameters  []interface{}
	Pending     bool
	Focused     bool
	// contains filtered or unexported fields
}

TableEntry represents an entry in a table test. You generally use the `Entry` constructor.

func Entry

func Entry(description interface{}, parameters ...interface{}) TableEntry

Entry constructs a TableEntry.

The first argument is a required description (this becomes the content of the generated Ginkgo `It`). Subsequent parameters are saved off and sent to the callback passed in to `DescribeTable`.

Each Entry ends up generating an individual Ginkgo It.

func FEntry

func FEntry(description interface{}, parameters ...interface{}) TableEntry

You can focus a particular entry with FEntry. This is equivalent to FIt.

func PEntry

func PEntry(description interface{}, parameters ...interface{}) TableEntry

You can mark a particular entry as pending with PEntry. This is equivalent to PIt.

func XEntry

func XEntry(description interface{}, parameters ...interface{}) TableEntry

You can mark a particular entry as pending with XEntry. This is equivalent to XIt.

Jump to

Keyboard shortcuts

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