testutil

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

README

testutil

The testutil package provides shared testing utilities for the garf project.

Functions

CreateTemporaryNetrc

Creates a temporary .netrc file with the specified content and returns its path. The file is created with 0600 permissions for security.

func CreateTemporaryNetrc(t *testing.T, content string) string
WithEnv

Temporarily sets environment variables for the duration of a test function. It automatically restores the original values when the test completes.

func WithEnv(t *testing.T, env map[string]string, fn func())

Usage

import "github.com/albertocavalcante/garf/pkg/testutil"

func TestExample(t *testing.T) {
    // Create a temporary .netrc file
    netrcPath := testutil.CreateTemporaryNetrc(t, "machine example.com login user password pass")
    
    // Set environment variables temporarily
    testutil.WithEnv(t, map[string]string{"NETRC": netrcPath}, func() {
        // Your test code here
    })
} 

Documentation

Overview

Package testutil provides shared testing utilities for the garf project.

Index

Constants

View Source
const (
	// NetrcFilePermissions defines the secure permissions for .netrc files (0600).
	NetrcFilePermissions = 0o600
)

Variables

This section is empty.

Functions

func CreateTemporaryNetrc

func CreateTemporaryNetrc(t *testing.T, content string) string

CreateTemporaryNetrc creates a temporary .netrc file with the specified content. The file is created with 0600 permissions for security.

func WithEnv

func WithEnv(t *testing.T, env map[string]string, fn func())

WithEnv temporarily sets environment variables for the duration of a test function. It automatically restores the original values when the test completes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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