daemontestutils

package
v0.0.0-...-426bf0d Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package daemontestutils exports test helpers to be used in other packages that need to change internal behaviors of the daemon.

Index

Constants

View Source
const ERROR_BUFFER_OVERFLOW = syscall.EOVERFLOW

ERROR_BUFFER_OVERFLOW is the error returned by GetAdaptersAddresses when the buffer is too small.

Variables

This section is empty.

Functions

func DefaultNetworkDetectionToMock

func DefaultNetworkDetectionToMock()

DefaultNetworkDetectionToMock sets the default options for the daemon package with mocks for success of upper level tests.

func MockWslSystemCmd

func MockWslSystemCmd(t *testing.T)

MockWslSystemCmd mocks commands running inside the WSL system distro. To use this in higher level package tests, call `DefaultNetworkDetectionToMock()` in the test package `init` function, or have a `With...()` function changing the options passed to `daemon.Serve()`.

Types

type IPAdapterAddresses

type IPAdapterAddresses struct {
	Next                *IPAdapterAddresses
	FriendlyName        string
	Description         string
	FirstUnicastAddress net.IP
}

IPAdapterAddresses redefines the wrapper type for the IP_ADAPTER_ADDRESSES structure for testing on Linux.

type MockIPAdaptersState

type MockIPAdaptersState int

MockIPAdaptersState is an enumeration of the possible states of the MockIPConfig object which influences the result of the mocked GetAdaptersAddresses implementation.

const (
	// MockError is a state that causes the GetAdaptersAddresses to always return an error.
	MockError MockIPAdaptersState = iota

	// EmptyList is a state that causes the GetAdaptersAddresses to return an empty list of adapters.
	EmptyList

	// NoHyperVAdapterInList is a state that causes the GetAdaptersAddresses to return a list without any Hyper-V adapter.
	NoHyperVAdapterInList

	// SingleHyperVAdapterInList is a state that causes the GetAdaptersAddresses to return a list with a single Hyper-V adapter, which is the WSL one.
	SingleHyperVAdapterInList

	// MultipleHyperVAdaptersInList is a state that causes the GetAdaptersAddresses to return a list with multiple Hyper-V adapters, one of which is the WSL one.
	MultipleHyperVAdaptersInList
)

type MockIPAddrsTemplate

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

MockIPAddrsTemplate is a template to fill the ipAdapterAddresses struct with mock data.

type MockIPConfig

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

MockIPConfig holds the state to control the mock implementation of the GetAdaptersAddresses Win32 API.

func NewHostIPConfigMock

func NewHostIPConfigMock(state MockIPAdaptersState) MockIPConfig

NewHostIPConfigMock initializes a mockIPConfig object with the state provided so it can be used instead of the real GetAdaptersAddresses Win32 API.

func (*MockIPConfig) GetAdaptersAddresses

func (m *MockIPConfig) GetAdaptersAddresses(_, _ uint32, _ uintptr, adapterAddresses *IPAdapterAddresses, sizePointer *uint32) (errcode error)

GetAdaptersAddresses is a mock implementation of the GetAdaptersAddresses Win32 API, based on the state of the mockIPConfig object.

Jump to

Keyboard shortcuts

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