Documentation ¶
Overview ¶
Package saver contains the part of the analyser that uses the analyser to save failing tests.
Index ¶
- Variables
- func ArchiveSubject(ar Archiver, sname, dest string, nameMap normaliser.Map, obs ...Observer) error
- func OnArchive(s ArchiveMessage, obs ...Observer)
- func OnArchiveFileAdded(sname, file string, i int, obs ...Observer)
- func OnArchiveFileMissing(sname, missing string, i int, obs ...Observer)
- func OnArchiveFinish(sname string, obs ...Observer)
- func OnArchiveStart(sname string, dest string, nfiles int, obs ...Observer)
- type ArchiveMessage
- type ArchiveMessageKind
- type Archiver
- type Observer
- type Option
- type Pathset
- type RunPathset
- type Saver
- type TGZWriter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrArchiveMakerNil = errors.New("archive maker function nil")
ErrArchiveMakerNil is the error produced when the archive maker supplied to New is nil.
var ( // ErrArchiverNil occurs when we try to archive a subject with no archiver. ErrArchiverNil = errors.New("archiver nil") )
Functions ¶
func ArchiveSubject ¶
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 ¶
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 ¶
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 ¶
OnArchiveFinish sends an archive finish 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 ¶
Option is the type of options to New.
func ObserveWith ¶
ObserveWith appends obs to the observer list for this saver.
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 ¶
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 ¶
DirList gets the list of directories in the save pathset, ordered by subject number.
func (*Pathset) SubjectRun ¶
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.
type TGZWriter ¶
type TGZWriter struct {
// contains filtered or unexported fields
}
TGZWriter is a wrapper over a gzipped archive writer.
func NewTGZWriter ¶
func NewTGZWriter(w io.WriteCloser) *TGZWriter
NewTGZWriter creates a new tarball writer on top of the basic writer w.
func (*TGZWriter) ArchiveFile ¶
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.