Documentation ¶
Overview ¶
Package xtest implements common functionality for unit tests. This includes support for assertions in multiple goroutines to Goconvey, and temporary test file/folder helpers.
Parallel goconvey blocks cannot contain other goconvey blocks.
Example:
func TestParallel(t *testing.T) { Convey("Test parallel goroutines", t, Parallel(func(sc *SC) { x := 1 sc.SoMsg("x", x, ShouldEqual, 1) }, func(sc *SC) { y := 1 sc.SoMsg("y", y, ShouldEqual, 1) })) }
Note that inside parallel blocks, Convey methods should be explicitly invoked on the local convey object (e.g., sc).
Index ¶
- func ExpandPath(file string) string
- func FailOnErr(t *testing.T, err error)
- func MustMarshalJSONToFile(t *testing.T, v interface{}, baseName string)
- func MustParseAS(s string) addr.AS
- func MustParseIA(s string) addr.IA
- func MustReadFromFile(t *testing.T, baseName string) []byte
- func MustTempDir(dir, prefix string) (string, func())
- func MustTempFileName(dir, prefix string) string
- func MustWriteToFile(t *testing.T, b []byte, baseName string)
- func Parallel(f, g func(sc *SC)) func(c C)
- func SoMsgError(msg string, err error, shouldBeError bool)
- func TempFileName(dir, prefix string) (string, error)
- type SC
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustMarshalJSONToFile ¶
MustMarshalJSONToFile marshals v and writes the result to file testdata/baseName. If the file exists, it is truncated; if it doesn't exist, it is created. On errors, t.Fatal() is called.
func MustParseAS ¶
MustParseAS parses s and returns the corresponding addr.AS object. It panics if s is not valid AS representation
func MustParseIA ¶
MustParseIA parses s and returns the corresponding addr.IA object. It panics if s is not a valid ISD-AS representation.
func MustReadFromFile ¶
MustReadFromFile reads testdata/baseName and returns the raw content. On errors, t.Fatal() is called.
func MustTempDir ¶
MustTempDir creates a new temporary directory under dir with the specified prefix. If the function encounters an error it panics. The second return value is a clean-up function that can be called to recursively delete the entire directory.
func MustTempFileName ¶
MustTempFileName is a wrapper around TempFileName. The function panics if an error occurs. It is intended for tests where error handling is not necessary, and for chaining functions.
func MustWriteToFile ¶
MustWriteToFile writes b to file testdata/baseName. If the file exists, it is truncated; if it doesn't exist, it is created. On errors, t.Fatal() is called.
func SoMsgError ¶
SoMsgError wraps nil/non-nil error Goconvey assertions into a single yes/no error check. The assertions pass if err is nil and shouldBeError is false, or if err is non-nil and shouldBeError is true. In the latter case, no equality check is performed.
func TempFileName ¶
TempFileName creates a temporary file in dir with the specified prefix, and then closes and deletes the file and returns its name. It is useful for testing packages that care about a unique path without being able to overwrite it (e.g., UNIX domain socket addresses or databases).
Types ¶
Directories ¶
Path | Synopsis |
---|---|
Package graph implements a multigraph model of a SCION network for use in tests.
|
Package graph implements a multigraph model of a SCION network for use in tests. |
Package loopback defines a net.PacketConn implementation where sent messages are echoed back on the same connection.
|
Package loopback defines a net.PacketConn implementation where sent messages are echoed back on the same connection. |
Package p2p (point to point) defines a net.PacketConn implementation where messages are exchanged via channels.
|
Package p2p (point to point) defines a net.PacketConn implementation where messages are exchanged via channels. |