helper

package
v0.0.0-...-4842e19 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupAndCopyResolvConf

func BackupAndCopyResolvConf(chroot string) error

BackupAndCopyResolvConf creates a backup of /etc/resolv.conf in a chroot and copies the contents from the host system into the chroot

func BackupReplace

func BackupReplace(target string, content string) (func(error) error, error)

BackupReplace backup the target file and replace it with the given content Returns the restore function.

func BoolPtr

func BoolPtr(b bool) *bool

func CalculateSHA256

func CalculateSHA256(fileName string) (string, error)

CalculateSHA256 calculates the SHA256 sum of the file provided as an argument

func CaptureStd

func CaptureStd(toCap **os.File) (io.Reader, func(), error)

CaptureStd returns an io.Reader to read what was printed, and teardown

func CheckEmptyFields

func CheckEmptyFields(Interface interface{}, result *gojsonschema.Result, schema *jsonschema.Schema) error

CheckEmptyFields iterates through the image definition struct and checks for fields that are present but return IsZero == true. TODO: I've created a PR upstream in xeipuuv/gojsonschema https://github.com/xeipuuv/gojsonschema/pull/352 if it gets merged this can be deleted

func CheckTags

func CheckTags(searchStruct interface{}, tag string) (string, error)

CheckTags iterates through the keys in a struct and looks for a value passed in as a parameter. It returns the yaml name of the key and an error. Currently only boolean values for the tags are supported

func CopyBlob

func CopyBlob(ddArgs []string) error

CopyBlob runs `dd` to copy a blob to an image file

func CreateTarArchive

func CreateTarArchive(src, dest, compression string, debug bool) error

CreateTarArchive places all of the files from a source directory into a tar. Currently supported are uncompressed tar archives and the following compression types: gzip, xz bzip2, zstd

func Du

func Du(path string) (quantity.Size, error)

Du recurses through a directory similar to du and adds all the sizes of files together

func ExtractTarArchive

func ExtractTarArchive(src, dest string, debug bool) error

ExtractTarArchive extracts all the files from a tar. Currently supported are uncompressed tar archives and the following compression types: zip, gzip, xz bzip2, zstd

func InitCommonOpts

func InitCommonOpts() (*commands.CommonOpts, *commands.StateMachineOpts)

InitCommonOpts initializes default common options for state machines. This is used for test scenarios to avoid nil pointer dereferences

func IsRootfsStructure

func IsRootfsStructure(s *gadget.VolumeStructure) bool

IsRootfsStructure determines if the given structure is the one associated to the rootfs

func IsSystemBootStructure

func IsSystemBootStructure(s *gadget.VolumeStructure) bool

IsSystemBootStructure determines if the given structure is the system-boot one

func IsSystemDataStructure

func IsSystemDataStructure(s *gadget.VolumeStructure) bool

IsSystemDataStructure determines if the given structure is the system-data one

func IsSystemSeedStructure

func IsSystemSeedStructure(s *gadget.VolumeStructure) bool

IsSystemSeedStructure determines if the given structure is the system-seed one

func RestoreResolvConf

func RestoreResolvConf(chroot string) error

RestoreResolvConf restores the resolv.conf in the chroot from the version that was backed up by BackupAndCopyResolvConf

func RunCmd

func RunCmd(cmd *exec.Cmd, debug bool) error

func RunCmds

func RunCmds(cmds []*exec.Cmd, debug bool) error

RunCmds runs a list of commands and returns the error It stops at the first error

func RunScript

func RunScript(hookScript string) error

RunScript runs scripts from disk. Currently only used for hooks

func SafeQuantitySubtraction

func SafeQuantitySubtraction(orig, subtract quantity.Size) quantity.Size

SafeQuantitySubtraction subtracts quantities while checking for integer underflow

func SetCommandOutput

func SetCommandOutput(cmd *exec.Cmd, liveOutput bool) (cmdOutput *bytes.Buffer)

SetCommandOutput sets the output of a command to either use a multiwriter or behave as a normal command and store the output in a buffer

func SetDefaults

func SetDefaults(needsDefaults interface{}) error

SetDefaults iterates through the keys in a struct and sets default values if one is specified with a struct tag of "default". Currently only default values of strings, slice of strings, and bools are supported

func ShouldSkipStructure

func ShouldSkipStructure(structure *gadget.VolumeStructure, isSeeded bool) bool

ShouldSkipStructure returns whether a structure should be skipped during certain processing

func SliceHasElement

func SliceHasElement(haystack []string, needle string) bool

SliceHasElement searches for a string in a slice of strings and returns whether it is found

Types

type Asserter

type Asserter struct {
	*testing.T
}

Asserter for testing purposes

func (*Asserter) AssertEqual

func (asserter *Asserter) AssertEqual(want, got interface{}, cmpOpts ...cmp.Option)

AssertEqual asserts that two objects are equal using go-cmp

func (*Asserter) AssertErrContains

func (asserter *Asserter) AssertErrContains(err error, errString string)

AssertErrContains asserts that an error is non-nil, and that the error message string contains a sub-string that is passed in

func (*Asserter) AssertErrNil

func (asserter *Asserter) AssertErrNil(err error, fatal bool)

AssertErrNil asserts that an error is nil. If the boolean fatal is true, it ends the test on a non-nil error. Otherwise, it lets the test continue running but marks it as failed

type MissingFieldError

type MissingFieldError struct {
	gojsonschema.ResultErrorFields
}

MissingFieldError is used when the fields exist but are the zero value for their type

Jump to

Keyboard shortcuts

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