testing

package
v0.0.0-...-12c5f08 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLink(name string) netlink.Link

AddLink sets up a dummy link for testing networking implementations on the node side

func DelLink(name string)

func MakeReadyEndpoint

func MakeReadyEndpoint(node string, addresses ...string) discovery.Endpoint

func MakeReadyEndpointList

func MakeReadyEndpointList(node string, addresses ...string) []discovery.Endpoint

makeReadyEndpointList returns a list of only one endpoint that carries the input addresses.

func MakeTerminatingNonServingEndpoint

func MakeTerminatingNonServingEndpoint(node string, addresses ...string) discovery.Endpoint

func MakeTerminatingServingEndpoint

func MakeTerminatingServingEndpoint(node string, addresses ...string) discovery.Endpoint

func MustParseIP

func MustParseIP(ipStr string) net.IP

MustParseIP is like net.ParseIP but it panics on error; use this for converting compile-time constant strings to net.IP

func MustParseIPNet

func MustParseIPNet(cidrStr string) *net.IPNet

MustParseIPNet is like netlink.ParseIPNet or net.ParseCIDR, except that it panics on error; use this for converting compile-time constant strings to net.IPNet.

func MustParseIPNets

func MustParseIPNets(ipNetStrs ...string) []*net.IPNet

MustParseIPNets is like MustParseIPNet but returns an array of *net.IPNet

func MustParseIPs

func MustParseIPs(ipStrs ...string) []net.IP

MustParseIPs is like MustParseIP but returns an array of net.IP

func MustParseMAC

func MustParseMAC(macStr string) net.HardwareAddr

MustParseMAC is like net.ParseMAC but it panics on error; use this for converting compile-time constant strings to net.HardwareAddr.

func OnSupportedPlatformsIt

func OnSupportedPlatformsIt(description string, f interface{})

OnSupportedPlatformsIt is a wrapper around ginkgo.It to determine if running the test is applicable for the current test environment. This is used to skip tests that are unable to execute in certain environments. Such as those without root or cap_net_admin privileges

func ProcessMockFn

func ProcessMockFn(mockObj *mock.Mock, mArgs TestifyMockHelper)

ProcessMockFn handles mocking of a single method call on a single mock object

func ProcessMockFnList

func ProcessMockFnList(mockObj *mock.Mock, mArgs []TestifyMockHelper)

ProcessMockFnList allows for handling mocking of multiple/differnt method calls on a single mock object

Types

type AferoDirMockHelper

type AferoDirMockHelper struct {
	DirName     string
	Permissions os.FileMode
	Files       []AferoFileMockHelper
}

type AferoFileMockHelper

type AferoFileMockHelper struct {
	FileName    string
	Permissions os.FileMode
	Content     []byte
}

type ExpectedCmd

type ExpectedCmd struct {
	// Cmd should be the command-line string of the executable name and all arguments it is expected to be called with
	Cmd string
	// LooseBatchCompare should be set if the command-line string is a batched
	// ovn-nbctl where the ordering does not matter
	LooseBatchCompare bool
	// Output is any stdout output which Cmd should produce
	Output string
	// Stderr is any stderr output which Cmd should produce
	Stderr string
	// Err is any error that should be returned for the invocation of Cmd
	Err error
	// Action is run when the fake command is "run"
	Action func() error
	// contains filtered or unexported fields
}

ExpectedCmd contains properties that the testcase expects a called command to have as well as the output that the fake command should return

type FakeExec

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

FakeExec is a convenience struct that wraps testing.FakeExec

func NewFakeExec

func NewFakeExec() *FakeExec

NewFakeExec returns a new FakeExec with a strict order compare

func NewLooseCompareFakeExec

func NewLooseCompareFakeExec() *FakeExec

NewFakeExec returns a new FakeExec with a strict order compare

func (*FakeExec) AddFakeCmd

func (f *FakeExec) AddFakeCmd(expected *ExpectedCmd)

AddFakeCmd takes the ExpectedCmd and appends its runner function to a fake command action list of the FakeExec

func (*FakeExec) AddFakeCmdsNoOutputNoError

func (f *FakeExec) AddFakeCmdsNoOutputNoError(commands []string)

AddFakeCmdsNoOutputNoError appends a list of commands to the expected command set. The command cannot return any output or error.

func (*FakeExec) CalledMatchesExpected

func (f *FakeExec) CalledMatchesExpected() bool

CalledMatchesExpected returns true if the number of commands the code under test called matches the number of expected commands in the FakeExec's list

func (*FakeExec) Command

func (f *FakeExec) Command(cmd string, args ...string) kexec.Cmd

func (*FakeExec) CommandContext

func (f *FakeExec) CommandContext(ctx context.Context, cmd string, args ...string) kexec.Cmd

CommandContext wraps arguments into exec.Cmd

func (*FakeExec) ErrorDesc

func (f *FakeExec) ErrorDesc() string

func (*FakeExec) LookPath

func (f *FakeExec) LookPath(file string) (string, error)

LookPath is for finding the path of a file

type KCmd

type KCmd func(cmd string, args ...string) kexec.Cmd

KCmd is a callback spec returning a k8s exec command

type TestifyMockHelper

type TestifyMockHelper struct {
	// OnCallMethodName - mock method that will be called.
	// Refer the `Method` field at https://godoc.org/github.com/stretchr/testify/mock#Call
	OnCallMethodName string
	// OnCallMethodArgType - argument types of the method that will be called.
	// Refer the `Arguments` field at https://godoc.org/github.com/stretchr/testify/mock#Call
	OnCallMethodArgType []string
	// OnCallMethodArgs - argument values we expect to be passed to the method.
	// Refer the `Arguments` field at https://godoc.org/github.com/stretchr/testify/mock#Call
	OnCallMethodArgs []interface{}
	// RetArgList - arguments returned by mock method when called.
	// Refer the `ReturnArguments` field at https://godoc.org/github.com/stretchr/testify/mock#Call
	RetArgList []interface{}
	// OnCallMethodsArgsStrTypeAppendCount - number of times the `string` type argument is repeated at the end.
	// NOTE: There are a couple of cases where the ovn related calls take upto 23 string arguments
	OnCallMethodsArgsStrTypeAppendCount int
	// CallTimes - number of times to return the return arguments when mock method is called
	// Refer the `Repeatability` field at https://godoc.org/github.com/stretchr/testify/mock#Call
	// NOTE: The zero value for an int is 0 in go, however, it the value for 'CallTimes' is not set, we interpret that
	// it will need to be called once.
	CallTimes int
}

TestifyMockHelper captures the arguments needed for the `On` , `Return` and 'Times` method ( refer https://godoc.org/github.com/stretchr/testify/mock#Call.On , https://godoc.org/github.com/stretchr/testify/mock#Call.Return and https://godoc.org/github.com/stretchr/testify/mock#Call.Times )

Jump to

Keyboard shortcuts

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