internal

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Helpers and values which can be used in any package

Index

Constants

View Source
const P_ld_linux = "/lib64/ld-linux-x86-64.so.2"

Path to interpreter

Variables

View Source
var (
	P_libc       = findLib("libc.so.6")
	P_libm       = findLib("libm.so.6")
	P_libpcre2_8 = findLib("libpcre2-8.so.0")
	P_libpthread = findLib("libpthread.so.0")
	P_libselinux = findLib("libselinux.so.1")
)

Paths to common libraries

View Source
var (
	P_ctypes_so     = TestdataPath("_ctypes_test.cpython-314-x86_64-linux-gnu.so")
	P_empty         = TestdataPath("empty")
	P_hello_dynamic = TestdataPath("hello_dynamic")
	P_hello_pie     = TestdataPath("hello_pie")
	P_hello_static  = TestdataPath("hello_static")
	P_id            = TestdataPath("id")
	P_ldd           = TestdataPath("ldd")
	P_which         = TestdataPath("which")

	P_build_sh      = TestdataPath("hello/build.sh")
	P_hello_pie_cgo = TestdataPath("hello/hello")
	P_hello_go      = TestdataPath("hello/hello.go")

	P_symlinked_id            = TestdataPath("symlink/id2")
	P_symlinked_build_sh      = TestdataPath("symlink/hello/build.sh")
	P_symlinked_hello_dynamic = TestdataPath("symlink/hello/hello")
	P_symlinked_hello_go      = TestdataPath("symlink/hello/hello.go")
)

Paths to our test binaries

View Source
var Ld_linux_64_RE = regexp.MustCompile(`^\/lib64(?:\/.+|)\/ld-linux.*\.so(?:\..+|)$`)

Regex to check if this is a 64-bit version of `ld-linux*.so`, matches /lib64(/more/directories)/ld-linux*.so(.*)

View Source
var P_ld_linux_resolved, _ = filepath.EvalSymlinks(P_ld_linux)

Functions

func Build added in v0.3.0

func Build(tags []string) string

Build current dir with optional tags, to tmp directory, returns path to resulting binary.

Remember to `defer RemoveBuildDir()`

func Copy added in v0.3.0

func Copy(sourcePath string, target string) error

Copy a file, maintaining mode & attempting to maintain ownership.

Errors returned will be of type *fs.PathError (unless they came from io.Copy, which sadly doesn't document error details ...)

func HashFile added in v0.3.0

func HashFile(path string) ([]byte, error)

func IsDir added in v1.2.0

func IsDir(path string) bool

Follow symlinks

func PermissionDenied

func PermissionDenied(t *testing.T, filename string) *os.File

Test helper: Provides a temporary file which exists but has no read permission

func RemoveBuildDir added in v0.3.0

func RemoveBuildDir(bin string)

Cleans up the tmp directory created by Build()

func ReplaceBetween added in v0.3.0

func ReplaceBetween(original io.Reader, marker1 string, marker2 string, replacement []byte) []byte

func SameFile

func SameFile(src string, dest string) bool

Are two files identical?, Returns false on any fs/io errors.

func SameInode added in v1.0.0

func SameInode(path1 string, path2 string) (bool, error)

Are two paths refering to identical inodes?

func SetDocComment added in v0.3.0

func SetDocComment(path string, comment string) error

func StripLines added in v0.2.0

func StripLines(multiline string) []string

StripLines converts a multiline string into a []string without line termination or indentation.

func TestdataPath

func TestdataPath(path string) string

Constructs the correct absolute value of path, where path is relative to ./internal/testdata

func WorkspaceTempDir

func WorkspaceTempDir(t testing.TB) string

Constructs a TempDir under `./.tmp`

This is (almost) guaranteed to be on the same filesystem as `./internal/testdata` and therefore allow for valid hardlinks.

Types

This section is empty.

Directories

Path Synopsis
Helpers related to testdata assets.
Helpers related to testdata assets.

Jump to

Keyboard shortcuts

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