facade

package
v0.0.0-...-e834411 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
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.

View Source
const ShortDuration = 3 * time.Millisecond

ShortDuration is the maximum difference allowed by similar times.

Variables

View Source
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
)
View Source
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

func Convey(name string, t testing.TB, cb func(*ftt.Test))

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

func ShouldAlmostEqualTime(expected time.Time) comparison.Func[time.Time]

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.

func So

func So[T any](t testing.TB, actual any, compare comparison.Func[T])

So is the equivalent of GoConvey's So. Note that it always takes three arguments.

Types

type T

type T = ftt.Test

T is a convenient alias for ftt.Test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL