testhelpers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0 Package testhelpers provide some helper functions that are useful for testing

Index

Constants

This section is empty.

Variables

View Source
var NullHostnameResolver = &fakeHostnameResolver{}

Functions

func Eventually

func Eventually(t *testing.T, timeout time.Duration, testFunc func(_ require.TestingT))

Eventually retries a test until it eventually succeeds. If the timeout is reached, the test fails with the same failure as its last execution.

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func GetFreeTCPPort

func GetFreeTCPPort() (port int, err error)

GetFreeTCPPort returns a free open TCP port

func InventoryDuration

func InventoryDuration(pluginIntervalSecs int64) time.Duration

func NewFakeHostnameResolver

func NewFakeHostnameResolver(full, short string, err error) hostname.ResolverChangeNotifier

func NewMockDir

func NewMockDir(files []MockFile) (mockDir, error)

NewMockDir mocks a system directory and creates the given `MockFile` inside the new temp directory.

func PopulateDeltas

func PopulateDeltas(dataDir string, entityKey string, deltasInfos []FakeDeltaEntry)

PopulateDeltas creates a set of synthetic, fake deltas for a given entity, in the given data directory. The deltas will be inserted in the dataDir/.delta_repo folder.

func Setenv

func Setenv(variable, value string) func()

Setenv sets an environment variable and returns a function that unsets the variable or restores it to its previous value

func SetupLog

func SetupLog()

SetupLog sets the log on verbose when test is run with -v flag.

Types

type FakeDeltaEntry

type FakeDeltaEntry struct {
	// Source is the categorized name of the plugin, e.g. 'packages/rpm'
	Source string
	// DeltasSize is the approximate size of all the unsent deltas for this plugin
	DeltasSize int
	// BodySize is the approximate size of the inventory JSON body for this plugin
	BodySize int
}

FakeDeltaEntry provides meta information about a plugin deltas set

type MockFile

type MockFile struct {
	ParentDir string
	Name      string
	Content   string
}

type PostDeltaTracer

type PostDeltaTracer struct {
	Sources          []map[string]interface{}
	Errors           []error
	PostDeltas       func(_ []string, _ entity.ID, _ bool, _ ...*inventoryapi.RawDelta) (*inventoryapi.PostDeltaResponse, error)
	PostDeltasVortex func(_ entity.ID, _ []string, _ bool, _ ...*inventoryapi.RawDelta) (*inventoryapi.PostDeltaResponse, error)
}

PostDeltaTracer traces metadata about invocations to a fake inventory ingest service

func NewPostDeltaTracer

func NewPostDeltaTracer(maxDeltaSize int) *PostDeltaTracer

NewPostDeltaTracer creates a PostDeltaTracer whose PostDeltas method returns an error if the total submitted deltas are larger than the maxDeltaSize parameter.

Jump to

Keyboard shortcuts

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