Documentation
¶
Overview ¶
Package test bundles a bunch of useful functions useful for testing purposes, particular useful in conjunction with the standard go test harness
The AssertMainThread() and AssertNonMainThread() functions require a bit of explanation. When compiled with the "assertions" tag these functions will panic if the calling function is in the wrong thread. Otherwise they are stubbed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertMainThread ¶
func AssertMainThread()
AssertMainThread is a stub for when "assertions" build tag is missing.
func AssertNonMainThread ¶
func AssertNonMainThread()
AssertNonMainThread is a stub for when "assertions" build tag is missing.
func Equate ¶
Equate is used to test equality between one value and another. Generally, both values must be of the same type but if a is of type uint16, b can be uint16 or int. The reason for this is that a literal number value is of type int. It is very convenient to write something like this, without having to cast the expected number value:
var r uint16 r = someFunction() test.Equate(t, r, 10)
This is by no means a comprehensive comparison function. With a bit more work with the reflect package we could generalise the testing a lot more. At is is however, it's good enough.
func ExpectedFailure ¶
ExpectedFailure tests argument v for a failure condition suitable for it's type. Currentlly support types:
bool -> bool == false error -> error != nil
If type is nil then the test will fail.
func ExpectedSuccess ¶
ExpectedSuccess tests argument v for a success condition suitable for it's type. Currentlly support types:
bool -> bool == true error -> error == nil
If type is nil then the test will succeed.
Types ¶
type CappedWriter ¶ added in v0.20.0
type CappedWriter struct {
// contains filtered or unexported fields
}
CapperWriter is an implementation of io.Writer that stops buffering once a predefined size is reached.
func NewCappedWriter ¶ added in v0.20.0
func NewCappedWriter(size int) (*CappedWriter, error)
NewCappedWriter is the preferred method of initialisation for the CappedWriter type.
func (*CappedWriter) Reset ¶ added in v0.20.0
func (r *CappedWriter) Reset()
Reset empties the ring writer's buffer
func (*CappedWriter) String ¶ added in v0.20.0
func (r *CappedWriter) String() string
type CompareWriter ¶ added in v0.20.0
type CompareWriter struct {
// contains filtered or unexported fields
}
CompareWriter is an implementation of the io.CompareWriter interface. It should be used to capture output and to compare with predefined strings.
func (*CompareWriter) Clear ¶ added in v0.20.0
func (tw *CompareWriter) Clear()
clear string empties the buffer.
func (*CompareWriter) Compare ¶ added in v0.20.0
func (tw *CompareWriter) Compare(s string) bool
Compare buffered output with predefined/example string.
func (*CompareWriter) String ¶ added in v0.20.0
func (tw *CompareWriter) String() string
implements Stringer interface.
type RingWriter ¶ added in v0.20.0
type RingWriter struct {
// contains filtered or unexported fields
}
RingWriter is an implementation of io.Writer that will keep the buffer to a predefined size, keeping the most recent writes and dropping the earlier writes as appropriate.
func NewRingWriter ¶ added in v0.20.0
func NewRingWriter(size int) (*RingWriter, error)
NewRingWriter is the preferred method of initialisation for the CappedWriter type.
func (*RingWriter) Reset ¶ added in v0.20.0
func (r *RingWriter) Reset()
Reset empties the ring writer's buffer
func (*RingWriter) String ¶ added in v0.20.0
func (r *RingWriter) String() string