saver

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package saver contains the part of the analyser that uses the analyser to save failing tests.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrArchiveMakerNil = errors.New("archive maker function nil")

ErrArchiveMakerNil is the error produced when the archive maker supplied to New is nil.

View Source
var (
	// ErrArchiverNil occurs when we try to archive a subject with no archiver.
	ErrArchiverNil = errors.New("archiver nil")
)

Functions

func ArchiveSubject

func ArchiveSubject(ar Archiver, sname, dest string, nameMap normaliser.Map, obs ...Observer) error

ArchiveSubject archives the subject defined by sname and nameMap to dest via ar, announcing progress to obs.

func OnArchive

func OnArchive(s ArchiveMessage, obs ...Observer)

OnArchive sends OnArchive to every instance observer in obs.

func OnArchiveFileAdded

func OnArchiveFileAdded(sname, file string, i int, obs ...Observer)

OnArchiveFileAdded sends an archive 'file added' message to every observer in obs. This message includes the subject name sname, the added file, and its position i in the archive.

func OnArchiveFileMissing

func OnArchiveFileMissing(sname, missing string, i int, obs ...Observer)

OnArchiveFileMissing sends an archive 'file missing' message to every observer in obs. This message includes the subject name sname, the missing file missing, and its position i in the archive.

func OnArchiveFinish

func OnArchiveFinish(sname string, obs ...Observer)

OnArchiveFinish sends an archive finish message to every observer in obs.

func OnArchiveStart

func OnArchiveStart(sname string, dest string, nfiles int, obs ...Observer)

OnArchiveStart sends an archive start message to every observer in obs.

Types

type ArchiveMessage

type ArchiveMessage struct {
	// Kind contains the kind of archive message being sent.
	Kind ArchiveMessageKind
	// SubjectName is the name of the subject being archived.
	SubjectName string
	// File is the target file of the archive message.
	File string
	// Index is the index of the file, or the number of files being archived, depending on the message kind.
	Index int
}

ArchiveMessage represents an OnArchive message.

type ArchiveMessageKind

type ArchiveMessageKind uint8
const (
	// ArchiveStart denotes the start of an archival run.
	// Dest contains the destination archive; Index contains the number of files to add.
	ArchiveStart ArchiveMessageKind = iota
	// ArchiveFileAdded states that the file with the given index was present and added.
	ArchiveFileAdded
	// ArchiveFileMissing states that the file with the given index was missing and skipped.
	ArchiveFileMissing
	// ArchiveFinish denotes the end of an archival run.
	ArchiveFinish
)

type Archiver

type Archiver interface {
	// ArchiveFile archives the file at rpath, storing it in the archive as wpath and with permissions mode.
	ArchiveFile(rpath, wpath string, mode int64) error

	// Closer captures that an Archiver can be closed; this should free all resources attached to the archiver.
	io.Closer
}

Archiver is the interface of types that can archive subject files.

type Observer

type Observer interface {
	// OnArchive lets the observer know that an archive action has occurred.
	OnArchive(s ArchiveMessage)
}

Observer represents the observer interface for savers.

type Option

type Option func(*Saver) error

Option is the type of options to New.

func ObserveWith

func ObserveWith(obs ...Observer) Option

ObserveWith appends obs to the observer list for this saver.

func Options

func Options(ops ...Option) Option

Options applies each option in ops in turn.

type Pathset

type Pathset struct {
	// Dirs maps 'interesting' statuses to directories.
	Dirs [status.Last + 1]string
}

Pathset contains the pre-computed paths for saving 'interesting' run results.

func NewPathset

func NewPathset(root string) *Pathset

NewPathset creates a save pathset rooted at root.

Example

ExampleNewPathset is a runnable example for NewPathset.

package main

import (
	"fmt"
	"path/filepath"

	"github.com/c4-project/c4t/internal/stage/analyser/saver"

	"github.com/c4-project/c4t/internal/subject/status"
)

func main() {
	p := saver.NewPathset("saved")

	for s := status.FirstBad; s <= status.Last; s++ {
		fmt.Printf("%s: %s\n", s, filepath.ToSlash(p.Dirs[s]))
	}

}
Output:

Flagged: saved/flagged
CompileFail: saved/compile_fail
CompileTimeout: saved/compile_timeout
RunFail: saved/run_fail
RunTimeout: saved/run_timeout

func (*Pathset) DirList

func (s *Pathset) DirList() []string

DirList gets the list of directories in the save pathset, ordered by subject number.

func (*Pathset) Prepare

func (s *Pathset) Prepare() error

Prepare prepares this pathset by making its directories.

func (*Pathset) SubjectRun

func (s *Pathset) SubjectRun(st status.Status, time time.Time) (*RunPathset, error)
Example

ExamplePathset_SubjectRun is a runnable example for SubjectRun.

package main

import (
	"fmt"
	"path/filepath"
	"time"

	"github.com/c4-project/c4t/internal/stage/analyser/saver"

	"github.com/c4-project/c4t/internal/subject/status"
)

func main() {
	p := saver.NewPathset("saved")
	t := time.Date(2015, time.October, 21, 7, 28, 0, 0, time.FixedZone("UTC-8", -8*60*60))
	stf, _ := p.SubjectRun(status.CompileFail, t)
	fmt.Println("root:", filepath.ToSlash(stf.DirRoot))
	fmt.Println("plan:", filepath.ToSlash(stf.FilePlan))

}
Output:

root: saved/compile_fail/2015/10/21/07_28_00
plan: saved/compile_fail/2015/10/21/07_28_00/plan.json.gz

type RunPathset

type RunPathset struct {
	// The root directory of the run's pathset.
	DirRoot string

	// The file to which the run's plan should be saved.
	FilePlan string
}

RunPathset represents a pathset containing a saved run.

func (*RunPathset) Prepare

func (s *RunPathset) Prepare() error

Prepare prepares this pathset by making its directories.

func (*RunPathset) SubjectTarFile

func (s *RunPathset) SubjectTarFile(sname string) string

SubjectTarFile gets the path to which a tarball for subject sname should be saved.

Example

ExampleRunPathset_SubjectTarFile is a runnable example for SubjectTarFile.

package main

import (
	"fmt"
	"path/filepath"
	"time"

	"github.com/c4-project/c4t/internal/stage/analyser/saver"

	"github.com/c4-project/c4t/internal/subject/status"
)

func main() {
	p := saver.NewPathset("saved")
	t := time.Date(2015, time.October, 21, 7, 28, 0, 0, time.FixedZone("UTC-8", -8*60*60))
	rp, _ := p.SubjectRun(status.CompileFail, t)
	fmt.Println(filepath.ToSlash(rp.SubjectTarFile("foo")))

}
Output:

saved/compile_fail/2015/10/21/07_28_00/foo.tar.gz

type Saver

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

Saver contains the state used when saving 'interesting' subjects.

func New

func New(paths *Pathset, archiveMaker func(path string) (Archiver, error), ops ...Option) (*Saver, error)

New constructs a saver with the pathset paths, archive maker archiveMaker, and options ops.

func (*Saver) Run

func (s *Saver) Run(a analysis.Analysis) error

Run runs the saving stage over the analyser a.

type TGZWriter

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

TGZWriter is a wrapper over a gzipped archive writer.

func CreateTGZ

func CreateTGZ(path string) (*TGZWriter, error)

CreateTGZ creates the file at path and opens a TGZWriter into it.

func NewTGZWriter

func NewTGZWriter(w io.WriteCloser) *TGZWriter

NewTGZWriter creates a new tarball writer on top of the basic writer w.

func (*TGZWriter) ArchiveFile

func (t *TGZWriter) ArchiveFile(rpath, wpath string, mode int64) error

ArchiveFile tars the file at rpath to wpath within this archive archive, and with the flags mode. If rpath is empty, no tarring occurs. If rpath doesn't exist, an error occurs unless NotFoundCb is set and handles the error in a different way.

func (*TGZWriter) Close

func (t *TGZWriter) Close() error

Close closes all of this writer's inner writers in order, returning the first error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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