testutil

package
v0.0.0-...-4ee0556 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides shared testing utilities for go_by_examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertOutput

func AssertOutput(got, want string) bool

AssertOutput is a helper function to verify program output in tests.

func CaptureOutput

func CaptureOutput(f func()) string

CaptureOutput runs the given function and captures its stdout output. It returns the captured output as a string.

func ContainsOutput

func ContainsOutput(output, substring string) bool

ContainsOutput is a helper function to check if output contains expected string.

func CreateTempFile

func CreateTempFile(dir, prefix string, content []byte) (string, func(), error)

CreateTempFile creates a temporary file with the given content. Returns the file path and a cleanup function.

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists at the given path

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists at the given path

func ListFiles

func ListFiles(dir string) ([]string, error)

ListFiles returns a list of files in the given directory

func ReadFile

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

ReadFile reads the entire file at path and returns its contents

func TempDir

func TempDir(prefix string) (string, func(), error)

TempDir creates a temporary directory and returns its path. The directory will be automatically removed when the test completes.

func WriteFile

func WriteFile(path string, data []byte) error

WriteFile writes data to a file at path

Types

type HTTPTestServer

type HTTPTestServer struct {
	*httptest.Server
	LastRequest *http.Request
}

HTTPTestServer represents a test HTTP server

func NewHTTPTestServer

func NewHTTPTestServer(handler http.HandlerFunc) *HTTPTestServer

NewHTTPTestServer creates a new test HTTP server with the given handler

func (*HTTPTestServer) Get

func (ts *HTTPTestServer) Get(path string) (int, string, error)

Get performs a GET request to the test server

Jump to

Keyboard shortcuts

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