code

package
v0.0.0-...-fd0796e Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtendPkgName = "_curpkg_"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Restorer

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

Restorer represents a manager to restore currentFile tree which has been modified by `failpoint-ctl enable`, e.g:

// ├── foo // │ ├── foo.go // │   └── foo.go__failpoint_stash__ // ├── bar // │ ├── bar.go // │   └── bar.go__failpoint_stash__ // └── foobar // ├── foobar.go //    └── foobar.go__failpoint_stash__ // Which will be restored as below: // ├── foo // │   └── foo.go <- foo.go__failpoint_stash__ // ├── bar // │   └── bar.go <- bar.go__failpoint_stash__ // └── foobar //    └── foobar.go <- foobar.go__failpoint_stash__

func NewRestorer

func NewRestorer(path string) *Restorer

NewRestorer returns a non-nil restorer which is used to clean the workspace of the specified path

func (Restorer) Restore

func (r Restorer) Restore() error

Restore restores the currentFile tree which will delete all files generated by `failpoint-ctl enable` and replace it by fail point stashed currentFile

type Rewriter

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

Rewriter represents a rewriting tool for converting the failpoint marker functions to corresponding statements in Golang. It will traverse the specified path and filter out files which do not have failpoint injection sites, and rewrite the remain files.

func NewRewriter

func NewRewriter(path string) *Rewriter

NewRewriter returns a non-nil rewriter which is used to rewrite the specified path

func (*Rewriter) GetCurrentFile

func (r *Rewriter) GetCurrentFile() *ast.File

GetCurrentFile returns the current file which is being rewritten

func (*Rewriter) GetRewritten

func (r *Rewriter) GetRewritten() bool

GetRewritten returns whether the rewriter has rewritten the file in a RewriteFile call.

func (*Rewriter) Rewrite

func (r *Rewriter) Rewrite() error

Rewrite does the rewrite action for specified path. It contains the main steps:

1. Filter out failpoint binding files and files that have no suffix `.go` 2. Filter out files which have not imported failpoint package (implying no failpoints) 3. Parse file to `ast.File` and rewrite the AST 4. Create failpoint binding file (which contains `_curpkg_` function) if it does not exist 5. Rename original file to `original-file-name + __failpoint_stash__` 6. Replace original file content base on the new AST

func (*Rewriter) RewriteFile

func (r *Rewriter) RewriteFile(path string) (err error)

RewriteFile rewrites a single file

func (*Rewriter) SetAllowNotChecked

func (r *Rewriter) SetAllowNotChecked(b bool)

SetAllowNotChecked sets whether the rewriter allows the file which does not import failpoint package.

func (*Rewriter) SetOutput

func (r *Rewriter) SetOutput(out io.Writer)

SetOutput sets a writer and the rewrite results will write to the writer instead of generate a stash file

Jump to

Keyboard shortcuts

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