filewalktestutil

package
v0.0.0-...-e2c53ed Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

Package cloudeng.io/file/filewalk/filewalktestutil

import cloudeng.io/file/filewalk/filewalktestutil

Package filewalktestutil provides utilities for testing code that uses filewalk.FS.

Types

Type MockFS
type MockFS struct {
	// contains filtered or unexported fields
}

MockFS implements filewalk.FS for testing purposes. Note that:

  1. It does not support soft links.
  2. It does not support Open on directories, instead, LevelScanner should be used.
  3. It only supports paths that begin with the root directory passed to NewMockFS.
Functions
func NewMockFS(root string, opts ...Option) (*MockFS, error)

NewMockFS creates a new MockFS rooted at root. All paths must start with root.

Methods
func (m *MockFS) Base(pathname string) string
func (m *MockFS) IsNotExist(err error) bool
func (m *MockFS) IsPermissionError(err error) bool
func (m *MockFS) Join(components ...string) string
func (m *MockFS) LevelScanner(pathname string) filewalk.LevelScanner
func (m *MockFS) Lstat(ctx context.Context, path string) (file.Info, error)
func (m *MockFS) Open(pathname string) (fs.File, error)
func (m *MockFS) OpenCtx(_ context.Context, pathname string) (fs.File, error)
func (m *MockFS) Readlink(_ context.Context, _ string) (string, error)
func (m *MockFS) Scheme() string
func (m *MockFS) Stat(_ context.Context, pathname string) (file.Info, error)
func (m *MockFS) String() string
func (m *MockFS) SysXAttr(_ any, merge file.XAttr) any
func (m *MockFS) XAttr(_ context.Context, pathname string, fi file.Info) (file.XAttr, error)
Type Option
type Option func(o *options)
Functions
func WithYAMLConfig(config string) Option

WithYAMLConfig specifies the YAML config to use for creating a mock filesystem.

Documentation

Overview

Package filewalktestutil provides utilities for testing code that uses filewalk.FS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan(ctx context.Context, fs filewalk.FS, prefix string) ([]filewalk.Entry, error)

func ScanNames

func ScanNames(ctx context.Context, fs filewalk.FS, prefix string) ([]string, error)

func WalkContents

func WalkContents(ctx context.Context, fs filewalk.FS, roots ...string) (prefixes, names []string, err error)

Types

type MockFS

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

MockFS implements filewalk.FS for testing purposes. Note that:

  1. It does not support soft links.
  2. It does not support Open on directories, instead, LevelScanner should be used.
  3. It only supports paths that begin with the root directory passed to NewMockFS.

func NewMockFS

func NewMockFS(root string, opts ...Option) (*MockFS, error)

NewMockFS creates a new MockFS rooted at root. All paths must start with root.

func (*MockFS) Base

func (m *MockFS) Base(pathname string) string

func (*MockFS) IsNotExist

func (m *MockFS) IsNotExist(err error) bool

func (*MockFS) IsPermissionError

func (m *MockFS) IsPermissionError(err error) bool

func (*MockFS) Join

func (m *MockFS) Join(components ...string) string

func (*MockFS) LevelScanner

func (m *MockFS) LevelScanner(pathname string) filewalk.LevelScanner

func (*MockFS) Lstat

func (m *MockFS) Lstat(ctx context.Context, path string) (file.Info, error)

func (*MockFS) Open

func (m *MockFS) Open(pathname string) (fs.File, error)

func (*MockFS) OpenCtx

func (m *MockFS) OpenCtx(_ context.Context, pathname string) (fs.File, error)
func (m *MockFS) Readlink(_ context.Context, _ string) (string, error)

func (*MockFS) Scheme

func (m *MockFS) Scheme() string

func (*MockFS) Stat

func (m *MockFS) Stat(_ context.Context, pathname string) (file.Info, error)

func (*MockFS) String

func (m *MockFS) String() string

func (*MockFS) SysXAttr

func (m *MockFS) SysXAttr(_ any, merge file.XAttr) any

func (*MockFS) XAttr

func (m *MockFS) XAttr(_ context.Context, pathname string, fi file.Info) (file.XAttr, error)

type Option

type Option func(o *options)

func WithYAMLConfig

func WithYAMLConfig(config string) Option

WithYAMLConfig specifies the YAML config to use for creating a mock filesystem.

type Walker

type Walker struct {
	sync.Mutex
	FS       filewalk.FS
	Prefixes []string
	Names    []string
}

func (*Walker) Contents

func (w *Walker) Contents(ctx context.Context, _ *struct{}, prefix string, contents []filewalk.Entry) (file.InfoList, error)

func (*Walker) Done

func (w *Walker) Done(_ context.Context, _ *struct{}, _ string, err error) error

func (*Walker) Prefix

func (w *Walker) Prefix(_ context.Context, _ *struct{}, prefix string, _ file.Info, _ error) (bool, file.InfoList, error)

Jump to

Keyboard shortcuts

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