Documentation
¶
Overview ¶
Package must provide a set of helper functions which panic on error.
Functions are designed to simplify error handling in test code by panicking on errors, reducing boilerplate, and error checking in test cases.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func First ¶
First returns the first element in the slice or T's zero value if the slice is empty. It panics with the value of the "err" if it is not nil.
Example ¶
nolint:unparam
package main
import (
"fmt"
"github.com/ctx42/testing/pkg/must"
)
func main() {
type Row struct{ Name string }
// Query to a database returning rows.
query := func() ([]Row, error) {
return []Row{{"a"}, {"b"}}, nil
}
have := must.First(query())
fmt.Println(have)
}
Output: {a}
func Single ¶
Single returns the first element in the slice or T's zero value if the slice is empty. It panics with the value of "err" if it is not nil or with the value of errExpSingle if slices have more than one element.
Example ¶
nolint:unparam
package main
import (
"fmt"
"github.com/ctx42/testing/pkg/must"
)
func main() {
type Row struct{ Name string }
// Query to a database returning rows.
query := func() ([]Row, error) {
return []Row{{"a"}}, nil
}
// Will panic if a database returned more than one error.
have := must.Single(query())
fmt.Println(have)
}
Output: {a}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.