testutils

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: BSD-3-Clause, MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(entry string) string

func ConstructSchema

func ConstructSchema(schemaDef TestSchema) (schema string)

func Cont

func Cont(name string, contEntries ...string) (contStr string)

func EmptyLeaf

func EmptyLeaf(name string) string

func FormatAsDiff

func FormatAsDiff(entry string) (diffs string)

Initially the +/- for changed lines get added right in front of the element being changed. This function pulls them to the front of the line and inserts a leading space on unchanged lines. Completely blank lines (other than leading tabs) do NOT get a leading space.

func GetConfigSchema

func GetConfigSchema(buf ...[]byte) (schema.ModelSet, error)

func GetConfigSchemaSkipUnknown

func GetConfigSchemaSkipUnknown(buf ...[]byte) (schema.ModelSet, error)

func GetConfigSchemaWithWarns

func GetConfigSchemaWithWarns(buf ...[]byte,
) (schema.ModelSet, []xutils.Warning, error)

func GetFullSchema

func GetFullSchema(buf ...[]byte) (schema.ModelSet, error)

func Leaf

func Leaf(name, value string) string

func LeafList

func LeafList(name string, leafListEntries ...string) (leafListStr string)

func LeafListEntry

func LeafListEntry(name string) string

func List

func List(name string, listEntries ...string) (listStr string)

func ListEntry

func ListEntry(name string, leaves ...string) (listEntryStr string)

func LogStack

func LogStack(t *testing.T)

func LogStackFatal

func LogStackFatal(t *testing.T)

func LogStackInternal

func LogStackInternal(t *testing.T, fatal bool)

func Prefix

func Prefix(entry, pfx string) string

Set of helper functions to produce correctly formatted config and that isolates test code that relies on correctly formatted config from subsequent format changes so that we are testing content not format.

func Rem

func Rem(entry string) string

func Root

func Root(rootEntries ...string) (rootStr string)

func Tab

func Tab(entry string) string

Types

type NameDef

type NameDef struct {
	Namespace string
	Prefix    string
}

type TestCase

type TestCase struct {
	Description     string            // What we are testing
	Template        string            // Template for schema
	Schema          string            // Schema snippet under test
	Schemas         []TestSchema      // Alternative to schema/template
	ExpResult       bool              // true = schema must be accepted
	ExpErrMsg       string            // Can't use empty string.  Use either
	ExpErrs         []string          // ErrMsg or Errs.
	NodesToValidate []schema.NodeSpec // Nil if no nodes to validate
}

Generic Test Case description allowing for cases where expected result may be acceptance or rejection. In the latter case we verify the error generated against the expected error (empty expected message causes test to fail). For tests we expect to pass, we can provide a set of node(s) with associated property/ies to be validated, or we can specify 'nil'.

Schemas can be provided in 2 different ways:

(a) Single schema + associated 'template'. Useful when testing a small

snippet of schema in a single module context where you don't want
to keep duplicating YANG across multiple tests.

=> Use Schema + Template fields

(b) Multiple schemas. Useful for testing multiple modules. Each

TestSchema needs to provide enough YANG to be pasted into a
generic template that contains a module, prefix and imports, but
nothing else.

=> Use Schemas

type TestSchema

type TestSchema struct {
	Name          NameDef
	Imports       []NameDef
	Includes      []string
	BelongsTo     NameDef
	Prefix        string
	SchemaSnippet string
}

Used for creating tests with multiple modules without resorting to reading them in from file as this means you can't read the schema and the test together easily.

func NewTestSchema

func NewTestSchema(namespace, prefix string) *TestSchema

func (*TestSchema) AddBelongsTo

func (ts *TestSchema) AddBelongsTo(namespace, prefix string) *TestSchema

func (*TestSchema) AddInclude

func (ts *TestSchema) AddInclude(module string) *TestSchema

func (*TestSchema) AddSchemaSnippet

func (ts *TestSchema) AddSchemaSnippet(snippet string) *TestSchema

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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