Documentation ¶
Overview ¶
Package facade is a transitional package that mimics the API of GoConvey classic. If you use it, you get a familiar syntax but no parallelism or compile-time errors from less permissive type signatures.
New code shouldn't use it.
Arguably, old code shouldn't use it either.
This thing is a very thin wrapper on top of ftt and truth/{assert,comparison,should}. There is no immediate harm mixing and matching this library with the libraries that it wraps in the same leaf code, but if you did that you might eventually need to migrate.
Index ¶
- Constants
- Variables
- func Convey(name string, t testing.TB, cb func(*ftt.Test))
- func ShouldAlmostEqualTime(expected time.Time) comparison.Func[time.Time]
- func ShouldBeLessThan[T constraints.Ordered](upper T) comparison.Func[T]
- func So[T any](t testing.TB, actual any, compare comparison.Func[T])
- type T
Constants ¶
const MaxTestLength = 100
MaxTestLength is a sensible maximum number of characters for the name of a test.
If the combined length of all tests exceeds 512 bytes, this starts causing problems with downstream services as of 2024-07-22. However, with a budget of 100 characters you get five levels, which should be enough in practice.
See b:354772098 for more information.
const ShortDuration = 3 * time.Millisecond
ShortDuration is the maximum difference allowed by similar times.
Variables ¶
var ( ShouldAlmostEqual = should.AlmostEqual[float64] ShouldBeEmpty = should.BeEmpty ShouldBeFalse = should.BeFalse ShouldBeNil = should.BeNil ShouldBeTrue = should.BeTrue ShouldContain = should.Contain[any] ShouldContainString = should.Contain[string] ShouldContainKey = should.ContainKey[any] ShouldNotContainKey = should.NotContainKey[any] ShouldEqual = should.Equal[any] ShouldEqualInt64 = should.Equal[int64] ShouldHaveLength = should.HaveLength ShouldNotBeNil = should.NotBeNil ShouldResemble = should.Match[any] ShouldContainSubstring = should.ContainSubstring ShouldBeBlank = should.BeBlank )
var DangerousShouldResemble = should.Resemble[any]
DangerousShouldResemble uses the legacy behavior, which reaches inside protos (for example, it is not proto-aware) and ignores unexported fields.
This function should only be used to port an ornery test to the glorious new FTT world.
Functions ¶
func Convey ¶
Convey is a replacement for legacy Convey. Subconveys need a T argument, however.
If the test name exceeds 100 characters, we will "helpfully" panic. See b:354772098 for details.
func ShouldAlmostEqualTime ¶
ShouldAlmostEqualTime compares two times and checks that they are similar.
This is a compatibility function that exists only to allow bad tests that don't mock the clock to pass and not block rewrite efforts.
Code that uses the clock should touch it through go.chromium.org/luci/common/clock , and go.chromium.org/luci/common/clock/testclock .
The time would then be set in a test like:
func TestWhatever(t *testing.T) { t.Parallel() ctx := context.Background() tc, ctx := testclock.UseTime(context.Background(), testclock.TestRecentTimeUTC) // do stuff }
Do not use this function for any other purpose.
func ShouldBeLessThan ¶
func ShouldBeLessThan[T constraints.Ordered](upper T) comparison.Func[T]
ShouldBeLessThan is a generic function that wraps should.BeLessThan.
This avoids needless duplication for ints, int64s, strings, and other stuff.
Most of the comparisons below could also be made generic, but I'm choosing to genericize things on an as-needed basis to keep the code in this library as simple as possible.