schemafake

package
v0.0.0-...-6fa03d5 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package schemafake defines a fake implementation of a gNMI device with a known schema which is used to validate tests within the gNMITest framework.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Timestamp is a function used to specify the timestamp to be used in Notifications
	// returned from the fake. It can be overridden in calling code to ensure that a
	// deterministic result is returned.
	Timestamp = func() int64 { return time.Now().UnixNano() }
)

Functions

This section is empty.

Types

type Target

type Target struct {
	gpb.UnimplementedGNMIServer // Implement the gNMI server interface.
	// contains filtered or unexported fields
}

Target defines the gNMI fake target.

func New

func New(schemas map[string]*ytypes.Schema) (*Target, error)

New creates a new schemaefake using the specified map of schemas. The schemas map is keyed by the origin name, with the value being a Schema specification.

func (*Target) Get

func (t *Target) Get(ctx context.Context, r *gpb.GetRequest) (*gpb.GetResponse, error)

Get implements the gNMI Get RPC. The request received from the client is extracted from the GetRequest received from the client. Each path is retrieved from the target's data tree, and subsequently marshalled into a gNMI Notification. Each path in the GetRequest is handled separately, such that there is no guarantee of consistency across separate paths within the GetRequest. Prefixing is performed within the results of each path expansion within the request.

func (*Target) Load

func (t *Target) Load(b []byte, origin string, opts ...ytypes.UnmarshalOpt) error

Load unmarshals the JSON supplied in b into the supplied origin, using the options specified into the target's root using the stored unmarshal function.

func (*Target) Start

func (t *Target) Start(cert, key string) (uint64, func(), error)

Start starts the fake gNMI server with the specified certificate and key. It returns the TCP port the fake is listening on, a function to stop the server and an optional error if the server cannot be started.

func (*Target) Subscribe

func (t *Target) Subscribe(stream gpb.GNMI_SubscribeServer) error

Subscribe handles the gNMI bi-directional streaming Subscribe RPC. SubscribeRequest messages are read from the client, and the target streams responses back according to the type of subscription specified.

Currently, this implementation only supports the ONCE subscription mode.

Jump to

Keyboard shortcuts

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