testutil

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0, NCSA Imports: 13 Imported by: 0

Documentation

Overview

Package testutil contains common utilities to test Kythe libraries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepEqual added in v0.0.9

func DeepEqual[T any](expected, got T, opts ...cmp.Option) error

DeepEqual determines if expected is deeply equal to got, returning a detailed error if not. It is okay for expected and got to be protobuf message values.

func Errorf added in v0.0.7

func Errorf(t testing.TB, msg string, err error, args ...any)

Errorf is equivalent to t.Errorf(msg, err, args...) if err != nil.

func Fatalf added in v0.0.59

func Fatalf(t testing.TB, msg string, err error, args ...any)

Fatalf is equivalent to t.Fatalf(msg, err, args...) if err != nil.

func JSONEqual added in v0.0.30

func JSONEqual(expected, got []byte) error

JSONEqual compares two bytes assuming they are json, using encoding/json and DeepEqual.

func RandBytes

func RandBytes(bytes []byte)

RandBytes fills the given slice with random bytes

func RandStr

func RandStr(size int) string

RandStr returns a random string of the given length

func SetFlag added in v0.0.64

func SetFlag(t testing.TB, flagName string, value string)

SetFlag sets a flag to a value for the duration of the test, resetting it to the flag's default value during cleanup.

func TestFilePath added in v0.0.29

func TestFilePath(t *testing.T, path string) string

TestFilePath takes a path and resolves it based on the testdir. If it cannot successfully do so, it calls t.Fatal and abandons.

func TrimmedEqual added in v0.0.29

func TrimmedEqual(got, want []byte) (bool, string)

TrimmedEqual compares two strings after collapsing irrelevant whitespace at the beginning or end of lines. It returns both a boolean indicating equality, as well as any relevant diff.

func YAMLEqual added in v0.0.30

func YAMLEqual(expected, got []byte) error

YAMLEqual compares two bytes assuming they are yaml, by converting to json and doing an ordering-agnostic comparison. Note this carries some restrictions because yaml->json conversion fails for nil or binary map keys.

Types

This section is empty.

Jump to

Keyboard shortcuts

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