testutils

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright 2023- IBM Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var TmpDir = filepath.Join(projectpath.Root, "temp") // cleaned up after the test is done

Functions

func CheckActualVsExpectedOutputMatch

func CheckActualVsExpectedOutputMatch(t *testing.T, expectedOutputFileName, actualOutput, testInfo, testingPkg string)

CheckActualVsExpectedOutputMatch: testing helping func - checks if actual output matches expected output, if not generates actual output file if --update flag is on, writes the actual output to the expected output file

func CheckErrorContainment

func CheckErrorContainment(t *testing.T, testInfo, expectedErrorMsg, actualErrMsg string)

CheckErrorContainment: helping func - if the actual error/warning message does not contain the expected error, fail the test with relevant info

func ConnlistTestNameByTestArgs

func ConnlistTestNameByTestArgs(dirName, focusWorkload, format string, exposureFlag bool) (testName, expectedOutputFileName string)

ConnlistTestNameByTestArgs returns connlist test name and test's expected output file from some tests args

func DiffTestNameByTestArgs

func DiffTestNameByTestArgs(ref1, ref2, format string) (testName, expectedOutputFileName string)

DiffTestNameByTestArgs returns diff test name and test's expected output file from some tests args

func GenerateTempDirWithPods added in v1.3.0

func GenerateTempDirWithPods(origDir, srcName, srcNs, dstName, dstNs string) error

GenerateTempDirWithPods generates new temporary dir that copies origDir and adds yaml files of Pod kind matching the input workload resources of the src and dst the function returns the path of the generated temp dir.

func GetTestDirPath

func GetTestDirPath(dirName string) string

helping func - returns test's dir path from test's dir name

func WarnOnErrorReadingFile

func WarnOnErrorReadingFile(err error, file string)

Types

type PodInfo added in v1.3.0

type PodInfo struct {
	Name      string            `yaml:"name"`
	Namespace string            `yaml:"namespace,omitempty"`
	Labels    map[string]string `yaml:"labels,omitempty"`
}

PodInfo contains metadata of the pod so we can : 1. extract relevant workload from input resources 2. generate relevant pod template

type TestLogger added in v1.3.0

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

implements logger.Logger (to be used with connlist-analyzer)

func NewTestLogger added in v1.3.0

func NewTestLogger() *TestLogger

NewTestLogger returns a new TestLogger that writes to a buffer for testing

func (*TestLogger) Debugf added in v1.3.0

func (tl *TestLogger) Debugf(format string, o ...interface{})

Debugf writes a debug message to the log

func (*TestLogger) Errorf added in v1.3.0

func (tl *TestLogger) Errorf(err error, format string, o ...interface{})

Errorf writes an error message to the log

func (*TestLogger) GetLoggerMessages added in v1.3.0

func (tl *TestLogger) GetLoggerMessages() string

GetLoggerMessages returns logged messages as a string

func (*TestLogger) Infof added in v1.3.0

func (tl *TestLogger) Infof(format string, o ...interface{})

Infof writes an informative message to the log

func (*TestLogger) Warnf added in v1.3.0

func (tl *TestLogger) Warnf(format string, o ...interface{})

Warnf writes a warning message to the log

type WorkloadMetadata added in v1.3.0

type WorkloadMetadata struct {
	Metadata PodInfo `yaml:"metadata"`
}

workloadMetadata the yaml is unmarshal to workload metadata struct which is the only interesting part for our goals

Jump to

Keyboard shortcuts

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