Skip to content

Commit

Permalink
Merge pull request k1LoW#570 from k1LoW/rename-id
Browse files Browse the repository at this point in the history
Rename ID to Trail
  • Loading branch information
k1LoW authored Jul 26, 2023
2 parents a98fe9b + d646a47 commit 01b241f
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 131 deletions.
38 changes: 19 additions & 19 deletions capture/runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
var _ runn.Capturer = (*cRunbook)(nil)

type cRunbook struct {
dir string
currentIDs runn.IDs
errs error
runbooks sync.Map
loadDesc bool
desc string
runners map[string]any
dir string
currentTrails runn.Trails
errs error
runbooks sync.Map
loadDesc bool
desc string
runners map[string]any
}

type runbook struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func Runbook(dir string, opts ...RunbookOption) *cRunbook {
return r
}

func (c *cRunbook) CaptureStart(ids runn.IDs, bookPath, desc string) {
func (c *cRunbook) CaptureStart(trs runn.Trails, bookPath, desc string) {
if _, err := os.Stat(bookPath); err == nil {
func() {
b, err := os.ReadFile(bookPath)
Expand All @@ -90,16 +90,16 @@ func (c *cRunbook) CaptureStart(ids runn.IDs, bookPath, desc string) {
}()
}

c.runbooks.Store(ids[0], &runbook{})
c.runbooks.Store(trs[0], &runbook{})
}

func (c *cRunbook) CaptureResult(ids runn.IDs, result *runn.RunResult) {
func (c *cRunbook) CaptureResult(trs runn.Trails, result *runn.RunResult) {
if !result.Skipped {
c.writeRunbook(ids, result.Path)
c.writeRunbook(trs, result.Path)
}
}

func (c *cRunbook) CaptureEnd(ids runn.IDs, bookPath, desc string) {}
func (c *cRunbook) CaptureEnd(trs runn.Trails, bookPath, desc string) {}

func (c *cRunbook) CaptureHTTPRequest(name string, req *http.Request) {
const dummyDsn = "[THIS IS HTTP RUNNER]"
Expand Down Expand Up @@ -436,8 +436,8 @@ func (c *cRunbook) CaptureExecStderr(stderr string) {
r.currentExecTestCond = nil
}

func (c *cRunbook) SetCurrentIDs(ids runn.IDs) {
c.currentIDs = ids
func (c *cRunbook) SetCurrentTrails(trs runn.Trails) {
c.currentTrails = trs
}

func (c *cRunbook) Errs() error {
Expand All @@ -461,9 +461,9 @@ func (c *cRunbook) setRunner(name string, value any) {
}

func (c *cRunbook) currentRunbook() *runbook {
v, ok := c.runbooks.Load(c.currentIDs[0])
v, ok := c.runbooks.Load(c.currentTrails[0])
if !ok {
c.errs = multierr.Append(c.errs, fmt.Errorf("failed to c.runbooks.Load: %s", c.currentIDs[0]))
c.errs = multierr.Append(c.errs, fmt.Errorf("failed to c.runbooks.Load: %s", c.currentTrails[0]))
return nil
}
r, ok := v.(*runbook)
Expand Down Expand Up @@ -518,10 +518,10 @@ func (c *cRunbook) appendOp(hb yaml.MapSlice, m any) yaml.MapSlice {
return hb
}

func (c *cRunbook) writeRunbook(ids runn.IDs, bookPath string) {
v, ok := c.runbooks.Load(ids[0])
func (c *cRunbook) writeRunbook(trs runn.Trails, bookPath string) {
v, ok := c.runbooks.Load(trs[0])
if !ok {
c.errs = multierr.Append(c.errs, fmt.Errorf("failed to c.runbooks.Load: %s", ids[0]))
c.errs = multierr.Append(c.errs, fmt.Errorf("failed to c.runbooks.Load: %s", trs[0]))
return
}
r, ok := v.(*runbook)
Expand Down
24 changes: 12 additions & 12 deletions capturer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type Capturer interface {
CaptureStart(ids IDs, bookPath, desc string)
CaptureResult(ids IDs, result *RunResult)
CaptureEnd(ids IDs, bookPath, desc string)
CaptureStart(trs Trails, bookPath, desc string)
CaptureResult(trs Trails, result *RunResult)
CaptureEnd(trs Trails, bookPath, desc string)

CaptureHTTPRequest(name string, req *http.Request)
CaptureHTTPResponse(name string, res *http.Response)
Expand Down Expand Up @@ -42,27 +42,27 @@ type Capturer interface {
CaptureExecStdout(stdout string)
CaptureExecStderr(stderr string)

SetCurrentIDs(ids IDs)
SetCurrentTrails(trs Trails)
Errs() error
}

type capturers []Capturer

func (cs capturers) captureStart(ids IDs, bookPath, desc string) {
func (cs capturers) captureStart(trs Trails, bookPath, desc string) {
for _, c := range cs {
c.CaptureStart(ids, bookPath, desc)
c.CaptureStart(trs, bookPath, desc)
}
}

func (cs capturers) captureResult(ids IDs, result *RunResult) {
func (cs capturers) captureResult(trs Trails, result *RunResult) {
for _, c := range cs {
c.CaptureResult(ids, result)
c.CaptureResult(trs, result)
}
}

func (cs capturers) captureEnd(ids IDs, bookPath, desc string) {
func (cs capturers) captureEnd(trs Trails, bookPath, desc string) {
for _, c := range cs {
c.CaptureEnd(ids, bookPath, desc)
c.CaptureEnd(trs, bookPath, desc)
}
}

Expand Down Expand Up @@ -209,8 +209,8 @@ func (cs capturers) captureExecStderr(stderr string) {
}
}

func (cs capturers) setCurrentIDs(ids IDs) {
func (cs capturers) setCurrentTrails(trs Trails) {
for _, c := range cs {
c.SetCurrentIDs(ids)
c.SetCurrentTrails(trs)
}
}
32 changes: 16 additions & 16 deletions cmd/rprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ var rprofCmd = &cobra.Command{
d := make([][]string, len(r))
for _, rr := range r {
var id string
switch rr.id.Type {
case runn.IDTypeRunbook:
id = fmt.Sprintf("%srunbook[%s](%s)", strings.Repeat(" ", rr.depth), rr.id.Desc, runn.ShortenPath(rr.id.RunbookPath))
case runn.IDTypeStep:
key := rr.id.StepRunnerKey
switch rr.trail.Type {
case runn.TrailTypeRunbook:
id = fmt.Sprintf("%srunbook[%s](%s)", strings.Repeat(" ", rr.depth), rr.trail.Desc, runn.ShortenPath(rr.trail.RunbookPath))
case runn.TrailTypeStep:
key := rr.trail.StepRunnerKey
if key == "" {
key = string(rr.id.StepRunnerType)
key = string(rr.trail.StepRunnerType)
}
id = fmt.Sprintf("%ssteps[%s].%s", strings.Repeat(" ", rr.depth), rr.id.StepKey, key)
case runn.IDTypeBeforeFunc:
id = fmt.Sprintf("%sbeforeFunc[%d]", strings.Repeat(" ", rr.depth), rr.id.FuncIndex)
case runn.IDTypeAfterFunc:
id = fmt.Sprintf("%safterFunc[%d]", strings.Repeat(" ", rr.depth), rr.id.FuncIndex)
id = fmt.Sprintf("%ssteps[%s].%s", strings.Repeat(" ", rr.depth), rr.trail.StepKey, key)
case runn.TrailTypeBeforeFunc:
id = fmt.Sprintf("%sbeforeFunc[%d]", strings.Repeat(" ", rr.depth), rr.trail.FuncIndex)
case runn.TrailTypeAfterFunc:
id = fmt.Sprintf("%safterFunc[%d]", strings.Repeat(" ", rr.depth), rr.trail.FuncIndex)
default:
return fmt.Errorf("invalid runID type: %s", rr.id.Type)
return fmt.Errorf("invalid runID type: %s", rr.trail.Type)
}
d = append(d, []string{id, parseDuration(rr.elapsed)})
}
Expand All @@ -133,7 +133,7 @@ func init() {
}

type row struct {
id runn.ID
trail runn.Trail
elapsed time.Duration
startedAt time.Time
stoppedAt time.Time
Expand All @@ -150,11 +150,11 @@ func appendBreakdown(p *stopw.Span, d, maxd int) ([]row, error) {
if err != nil {
return nil, err
}
var runID runn.ID
if err := json.Unmarshal(b, &runID); err != nil {
var tr runn.Trail
if err := json.Unmarshal(b, &tr); err != nil {
return nil, err
}
rr = append(rr, row{runID, s.Elapsed, s.StartedAt, s.StoppedAt, d})
rr = append(rr, row{tr, s.Elapsed, s.StartedAt, s.StoppedAt, d})
rrr, err := appendBreakdown(s, d+1, maxd)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions cmdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func NewCmdOut(out io.Writer, verbose bool) *cmdOut {
}
}

func (d *cmdOut) CaptureStart(ids IDs, bookPath, desc string) {}
func (d *cmdOut) CaptureResult(ids IDs, result *RunResult) {
func (d *cmdOut) CaptureStart(trs Trails, bookPath, desc string) {}
func (d *cmdOut) CaptureResult(trs Trails, result *RunResult) {
if !d.verbose {
switch {
case result.Err != nil:
Expand Down Expand Up @@ -72,7 +72,7 @@ func (d *cmdOut) CaptureResult(ids IDs, result *RunResult) {
}
}
}
func (d *cmdOut) CaptureEnd(ids IDs, bookPath, desc string) {}
func (d *cmdOut) CaptureEnd(trs Trails, bookPath, desc string) {}

func (d *cmdOut) CaptureHTTPRequest(name string, req *http.Request) {}
func (d *cmdOut) CaptureHTTPResponse(name string, res *http.Response) {}
Expand All @@ -98,7 +98,7 @@ func (d *cmdOut) CaptureExecCommand(command string)
func (d *cmdOut) CaptureExecStdin(stdin string) {}
func (d *cmdOut) CaptureExecStdout(stdout string) {}
func (d *cmdOut) CaptureExecStderr(stderr string) {}
func (d *cmdOut) SetCurrentIDs(ids IDs) {}
func (d *cmdOut) SetCurrentTrails(trs Trails) {}
func (d *cmdOut) Errs() error {
return d.errs
}
16 changes: 8 additions & 8 deletions debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
var _ Capturer = (*debugger)(nil)

type debugger struct {
out io.Writer
currentIDs IDs
errs error
out io.Writer
currentTrails Trails
errs error
}

func NewDebugger(out io.Writer) *debugger {
Expand All @@ -28,9 +28,9 @@ func NewDebugger(out io.Writer) *debugger {
}
}

func (d *debugger) CaptureStart(ids IDs, bookPath, desc string) {}
func (d *debugger) CaptureResult(ids IDs, result *RunResult) {}
func (d *debugger) CaptureEnd(ids IDs, bookPath, desc string) {}
func (d *debugger) CaptureStart(trs Trails, bookPath, desc string) {}
func (d *debugger) CaptureResult(trs Trails, result *RunResult) {}
func (d *debugger) CaptureEnd(trs Trails, bookPath, desc string) {}

func (d *debugger) CaptureHTTPRequest(name string, req *http.Request) {
b, _ := httputil.DumpRequest(req, true)
Expand Down Expand Up @@ -156,8 +156,8 @@ func (d *debugger) CaptureExecStderr(stderr string) {
_, _ = fmt.Fprintf(d.out, "-----START STDERR-----\n%s\n-----END STDERR-----\n", stderr)
}

func (d *debugger) SetCurrentIDs(ids IDs) {
d.currentIDs = ids
func (d *debugger) SetCurrentTrails(trs Trails) {
d.currentTrails = trs
}

func (d *debugger) Errs() error {
Expand Down
Loading

0 comments on commit 01b241f

Please sign in to comment.