be_struct

package
v1.0.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 6 Imported by: 0

README

be_struct

Part of expectto/be - composable test matchers for Go.


import "github.com/expectto/be/be_struct"

Package be_struct provides Be matchers on struct fields.

Usage

func HavingField
func HavingField[StructT any](fieldName string, expectedValue ...any) types.BeMatcher

HavingField succeeds if the actual value is a struct of exactly type StructT and it has a field with the given name. If an expected value (raw value or matcher) is provided, the field's value must match it too.

Example:

Expect(result).To(be_struct.HavingField[TestStruct]("Field1", "hello1"))
Expect(result).To(be_struct.HavingField[TestStruct]("Field2"))

This is the generic, compile-time-typed variant: it pins the struct type at the call site. For everyday assertions prefer the root be.HaveField — it needs no type parameter, and supports dotted paths and "Method()" specs. The naming wobble (HaveField vs HavingField) is deliberate: it separates the default matcher from this typed variant.

Documentation

Overview

Package be_struct provides Be matchers on struct fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HavingField

func HavingField[StructT any](fieldName string, expectedValue ...any) types.BeMatcher

HavingField succeeds if the actual value is a struct of exactly type StructT and it has a field with the given name. If an expected value (raw value or matcher) is provided, the field's value must match it too.

Example:

Expect(result).To(be_struct.HavingField[TestStruct]("Field1", "hello1"))
Expect(result).To(be_struct.HavingField[TestStruct]("Field2"))

This is the generic, compile-time-typed variant: it pins the struct type at the call site. For everyday assertions prefer the root be.HaveField — it needs no type parameter, and supports dotted paths and "Method()" specs. The naming wobble (HaveField vs HavingField) is deliberate: it separates the default matcher from this typed variant.

Types

This section is empty.

Jump to

Keyboard shortcuts

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