testutil

package
v0.0.0-...-45eeedb Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testutil implements a fake GNMI server with the ability to stub responses and fake schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GNMIPath

func GNMIPath(t testing.TB, s string) *gpb.Path

mustPath converts a string to its path proto.

func GetSchemaStruct

func GetSchemaStruct() func() *ytypes.Schema

Types

type Device

type Device struct {
	SuperContainer *SuperContainer `path:"super-container" module:"yang-module"`
}

Device is the fake root.

func (*Device) IsYANGGoStruct

func (*Device) IsYANGGoStruct()

func (*Device) Validate

func (*Device) Validate(opts ...ygot.ValidationOption) error

func (*Device) ΛBelongingModule

func (*Device) ΛBelongingModule() string

func (*Device) ΛEnumTypeMap

func (*Device) ΛEnumTypeMap() map[string][]reflect.Type

type EnumType

type EnumType int64

EnumType is used as an enum type in various tests in the ytypes package.

func (EnumType) IsYANGGoEnum

func (EnumType) IsYANGGoEnum()

func (EnumType) String

func (e EnumType) String() string

func (EnumType) ΛMap

func (EnumType) ΛMap() map[string]map[int64]ygot.EnumDefinition

type EnumType2

type EnumType2 int64

EnumType2 is used as an enum type in various tests in the ytypes package.

func (EnumType2) IsYANGGoEnum

func (EnumType2) IsYANGGoEnum()

func (EnumType2) ΛMap

func (EnumType2) ΛMap() map[string]map[int64]ygot.EnumDefinition

type FakeGNMI

type FakeGNMI struct {
	// contains filtered or unexported fields
}

FakeGNMI is a running fake GNMI server.

func StartGNMI

func StartGNMI(port int) (*FakeGNMI, error)

StartGNMI launches a new fake GNMI server on the given port

func (*FakeGNMI) Dial

func (g *FakeGNMI) Dial(ctx context.Context, opts ...grpc.DialOption) (gpb.GNMIClient, error)

Dial dials the fake gNMI client and returns a gNMI client stub.

func (*FakeGNMI) GetRequests

func (g *FakeGNMI) GetRequests() []*gpb.GetRequest

GetRequests returns the set of GetRequests sent to the gNMI server.

func (*FakeGNMI) Requests

func (g *FakeGNMI) Requests() []*gpb.SubscribeRequest

Requests returns the set of SubscribeRequests sent to the gNMI server.

func (*FakeGNMI) Stub

func (g *FakeGNMI) Stub() *Stubber

Stub reset the stubbed responses to empty and returns a handle to add new ones.

type LeafContainerStruct

type LeafContainerStruct struct {
	Uint64Leaf          *uint64       `path:"uint64-leaf" shadow-path:"state/uint64-leaf"`
	EnumLeaf            EnumType      `path:"enum-leaf"`
	UnionLeaf           UnionLeafType `path:"union-leaf"`
	UnionLeaf2          EnumType      `path:"union-leaf2"`
	UnionLeafSingleType []string      `path:"union-stleaflist"`
}

func (*LeafContainerStruct) IsYANGGoStruct

func (*LeafContainerStruct) IsYANGGoStruct()

func (*LeafContainerStruct) To_UnionLeafType

func (*LeafContainerStruct) To_UnionLeafType(i interface{}) (UnionLeafType, error)

func (*LeafContainerStruct) Validate

func (*LeafContainerStruct) Validate(opts ...ygot.ValidationOption) error

func (*LeafContainerStruct) ΛBelongingModule

func (*LeafContainerStruct) ΛBelongingModule() string

func (*LeafContainerStruct) ΛEnumTypeMap

func (*LeafContainerStruct) ΛEnumTypeMap() map[string][]reflect.Type

type Model

type Model struct {
	SingleKey map[int32]*Model_SingleKey `path:"a/single-key"`
}

func (*Model) IsYANGGoStruct

func (*Model) IsYANGGoStruct()

func (*Model) NewSingleKey

func (t *Model) NewSingleKey(Key int32) (*Model_SingleKey, error)

NewSingleKey is a *generated* method for Model which may be used by an unmarshal function in ytype's reflect library, and is kept here in case.

func (*Model) RenameSingleKey

func (t *Model) RenameSingleKey(oldK, newK int32) error

RenameSingleKey is a *generated* method for Model which may be used by an unmarshal function in ytype's reflect library, and is kept here in case. RenameSingleKey renames an entry in the list SingleKey within the Model struct. The entry with key oldK is renamed to newK updating the key within the value.

func (*Model) Validate

func (*Model) Validate(opts ...ygot.ValidationOption) error

func (*Model) ΛBelongingModule

func (*Model) ΛBelongingModule() string

func (*Model) ΛEnumTypeMap

func (*Model) ΛEnumTypeMap() map[string][]reflect.Type

type Model_SingleKey

type Model_SingleKey struct {
	Key   *int32 `path:"config/key|key" shadow-path:"state/key"`
	Value *int64 `path:"config/value" shadow-path:"state/value"`
}

func (*Model_SingleKey) IsYANGGoStruct

func (*Model_SingleKey) IsYANGGoStruct()

func (*Model_SingleKey) Validate

func (*Model_SingleKey) Validate(opts ...ygot.ValidationOption) error

func (*Model_SingleKey) ΛBelongingModule

func (*Model_SingleKey) ΛBelongingModule() string

func (*Model_SingleKey) ΛEnumTypeMap

func (*Model_SingleKey) ΛEnumTypeMap() map[string][]reflect.Type

func (*Model_SingleKey) ΛListKeyMap

func (t *Model_SingleKey) ΛListKeyMap() (map[string]interface{}, error)

ΛListKeyMap returns the keys of the Model_SingleKey struct, which is a YANG list entry.

type SetClient

type SetClient struct {
	gpb.GNMIClient
	// Responses are the gNMI Responses to return from calls to Set.
	Responses []*gpb.SetResponse
	// Requests received by the client are stored in the slice.
	Requests []*gpb.SetRequest
	// ResponseErrs are the errors to return from calls to Set.
	ResponseErrs []error
	// contains filtered or unexported fields
}

func (*SetClient) AddResponse

func (f *SetClient) AddResponse(resp *gpb.SetResponse, err error) *SetClient

func (*SetClient) Reset

func (f *SetClient) Reset()

func (*SetClient) Set

func (f *SetClient) Set(_ context.Context, req *gpb.SetRequest, opts ...grpc.CallOption) (*gpb.SetResponse, error)

type Stubber

type Stubber struct {
	// contains filtered or unexported fields
}

Stubber is a handle to add stubbed responses.

func (*Stubber) GetResponse

func (s *Stubber) GetResponse(gr *gpb.GetResponse, err error) *Stubber

GetResponse appends the given GetResponse as a stub response.

func (*Stubber) Notification

func (s *Stubber) Notification(n *gpb.Notification) *Stubber

Notification appends the given notification as a stub response.

func (*Stubber) Sync

func (s *Stubber) Sync() *Stubber

Sync appends a sync stub response.

type SuperContainer

type SuperContainer struct {
	LeafContainerStruct *LeafContainerStruct `path:"leaf-container-struct"`
	Model               *Model               `path:"model"`
}

func (*SuperContainer) IsYANGGoStruct

func (*SuperContainer) IsYANGGoStruct()

func (*SuperContainer) Validate

func (*SuperContainer) Validate(opts ...ygot.ValidationOption) error

func (*SuperContainer) ΛBelongingModule

func (*SuperContainer) ΛBelongingModule() string

func (*SuperContainer) ΛEnumTypeMap

func (*SuperContainer) ΛEnumTypeMap() map[string][]reflect.Type

type UnionLeafType

type UnionLeafType interface {
	Is_UnionLeafType()
}

type UnionLeafType_EnumType

type UnionLeafType_EnumType struct {
	EnumType EnumType
}

func (*UnionLeafType_EnumType) Is_UnionLeafType

func (*UnionLeafType_EnumType) Is_UnionLeafType()

func (*UnionLeafType_EnumType) ΛMap

type UnionLeafType_EnumType2

type UnionLeafType_EnumType2 struct {
	EnumType2 EnumType2
}

func (*UnionLeafType_EnumType2) Is_UnionLeafType

func (*UnionLeafType_EnumType2) Is_UnionLeafType()

func (*UnionLeafType_EnumType2) ΛMap

type UnionLeafType_String

type UnionLeafType_String struct {
	String string
}

func (*UnionLeafType_String) Is_UnionLeafType

func (*UnionLeafType_String) Is_UnionLeafType()

type UnionLeafType_Uint32

type UnionLeafType_Uint32 struct {
	Uint32 uint32
}

func (*UnionLeafType_Uint32) Is_UnionLeafType

func (*UnionLeafType_Uint32) Is_UnionLeafType()

Jump to

Keyboard shortcuts

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