Documentation ¶
Overview ¶
Package testutils contains code that is useful in tests.
Index ¶
- Constants
- Variables
- func CreateGrpcConnection(t *testing.T, grpcAddress string, opts ...grpc.DialOption) *grpc.ClientConn
- func CreateRandomString(n int) string
- func EnsureServiceHealthy(t testing.TB, grpcAddr, httpAddr string, ...)
- func MakeSliceWithGenerator[T any](n uint64, generator func(n uint64) any) []T
- func MakeStringWithRuneset(n uint64, runeSet []rune) string
- func MustNewStruct(t *testing.T, v map[string]interface{}) *structpb.Struct
- func MustTransformDSLToProtoWithID(s string) *openfgav1.AuthorizationModel
- func NumericalStringGenerator(n uint64) any
Constants ¶
const (
AllChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
Variables ¶
var ( TupleCmpTransformer = cmp.Transformer("Sort", func(in []*openfgav1.Tuple) []*openfgav1.Tuple { out := append([]*openfgav1.Tuple(nil), in...) sort.SliceStable(out, func(i, j int) bool { if out[i].GetKey().Object != out[j].GetKey().Object { return out[i].GetKey().Object < out[j].GetKey().Object } if out[i].GetKey().Relation != out[j].GetKey().Relation { return out[i].GetKey().Relation < out[j].GetKey().Relation } if out[i].GetKey().User != out[j].GetKey().User { return out[i].GetKey().User < out[j].GetKey().User } return true }) return out }) TupleKeyCmpTransformer = cmp.Transformer("Sort", func(in []*openfgav1.TupleKey) []*openfgav1.TupleKey { out := append([]*openfgav1.TupleKey(nil), in...) sort.SliceStable(out, func(i, j int) bool { if out[i].Object != out[j].Object { return out[i].Object < out[j].Object } if out[i].Relation != out[j].Relation { return out[i].Relation < out[j].Relation } if out[i].User != out[j].User { return out[i].User < out[j].User } return true }) return out }) )
Functions ¶
func CreateGrpcConnection ¶ added in v1.5.0
func CreateGrpcConnection(t *testing.T, grpcAddress string, opts ...grpc.DialOption) *grpc.ClientConn
CreateGrpcConnection creates a grpc connection to an address and closes it when the test ends.
func CreateRandomString ¶
func EnsureServiceHealthy ¶ added in v1.4.1
func EnsureServiceHealthy(t testing.TB, grpcAddr, httpAddr string, transportCredentials credentials.TransportCredentials, httpHealthCheck bool)
EnsureServiceHealthy is a test helper that ensures that a service's grpc health endpoint is responding OK. It can also ensure that the HTTP /healthz endpoint is responding OK. If the service doesn't respond healthy in 30 seconds it fails the test.
func MakeSliceWithGenerator ¶ added in v1.3.8
MakeSliceWithGenerator generates a slice of length 'n' and populates the contents with values based on the generator provided.
func MakeStringWithRuneset ¶ added in v1.3.8
func MustNewStruct ¶ added in v1.3.8
func MustTransformDSLToProtoWithID ¶ added in v1.4.1
func MustTransformDSLToProtoWithID(s string) *openfgav1.AuthorizationModel
MustTransformDSLToProtoWithID interprets the provided string s as an FGA model and attempts to parse it using the official OpenFGA language parser. The model returned includes an auto-generated model id which assists with producing models for testing purposes.
func NumericalStringGenerator ¶ added in v1.3.8
NumericalStringGenerator generates a string representation of the provided uint value.
Types ¶
This section is empty.