require

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

About

Package of test assertions.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualProtos

func EqualProtos(t require.TestingT, expected, actual proto.Message)

func Field

func Field(t require.TestingT, value interface{}, name string) *reflect.StructField

func FieldOption

func FieldOption(t require.TestingT, options, message proto.Message, field string)
Example
package main

import (
	"testing"

	"github.com/complex64/protoc-gen-go-firestore/v3/internal/require"
	"github.com/complex64/protoc-gen-go-firestore/v3/internal/require/testdata"
)

func main() {
	var t *testing.T // We're inside a test case.

	// message MyMessage {
	//  string message_field = 1 [
	//    (testdata.field).field_option = "field option value"
	//  ];
	// }

	// A message, with a field as annotated above.
	msg := &testdata.MyMessage{}

	// The expected option the annotation should map to.
	opts := &testdata.FieldOptions{
		FieldOption: "field option value",
	}

	require.FieldOption(t, opts, msg, "message_field") // Test passes.
}
Output:

func FieldType

func FieldType(t require.TestingT, value interface{}, name string, sample interface{})

func FileOptions

func FileOptions(t require.TestingT, options, message proto.Message)

FileOptions asserts that message has options set for its protobuf message options.

Example
package main

import (
	"testing"

	"github.com/complex64/protoc-gen-go-firestore/v3/internal/require"
	"github.com/complex64/protoc-gen-go-firestore/v3/internal/require/testdata"
)

func main() {
	var t *testing.T // We're inside a test case.

	// In options.proto:
	// option (testdata.file).file_option = "file option value";
	// message MyMessage {}

	// A message from options.proto which links to its parent file descriptor.
	msg := &testdata.MyMessage{}
	opts := &testdata.FileOptions{
		// Assertions...
	}

	require.FileOptions(t, opts, msg)
}
Output:

func MessageOption

func MessageOption(t require.TestingT, options, message proto.Message)

MessageOption asserts the message's parent file has options set on the file level.

Example
package main

import (
	"testing"

	"github.com/complex64/protoc-gen-go-firestore/v3/internal/require"
	"github.com/complex64/protoc-gen-go-firestore/v3/internal/require/testdata"
)

func main() {
	var t *testing.T // We're inside a test case.

	// message MyMessage {
	//  option (testdata.message).message_option = "option value";
	//  ...
	// }

	// A message, annotated as shown above.
	msg := &testdata.MyMessage{
		MessageField: "field value",
	}

	// The expected option the annotation should map to.
	opts := &testdata.MessageOptions{
		MessageOption: "message option value",
	}

	require.MessageOption(t, opts, msg) // Test passes.
}
Output:

func StructFieldTags

func StructFieldTags(t require.TestingT, value interface{}, name string, tags map[string]string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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