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, reduce 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 value of err if err 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 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 value of err if err is not nil or with value of errExpSingle if slices has 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 database returning rows.
query := func() ([]Row, error) {
return []Row{{"a"}}, nil
}
// Will panic if 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.