Skip to content

Commit 805eb21

Browse files
committed
Add example coverage for tracing
1 parent 983d19a commit 805eb21

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
# Executable itself when building locally.
24
quickhook
35

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# quickhook
22

33
![Build Status](https://github.com/dirk/quickhook/actions/workflows/push.yml/badge.svg)
4-
![codecov](https://codecov.io/github/dirk/quickhook/branch/main/graph/badge.svg?token=FRMS9TRJ93)
4+
[![codecov](https://codecov.io/github/dirk/quickhook/branch/main/graph/badge.svg?token=FRMS9TRJ93)](https://app.codecov.io/github/dirk/quickhook)
55

66
Quickhook is a Git hook runner designed for speed. It is opinionated where it matters: hooks are executables organized by directory and must exit with a non-zero code on error. Everything else is up to you!
77

hooks/pre_commit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
func initGitForPreCommit(t *testing.T) test.TempDir {
1818
tempDir := test.NewTempDir(t, 1)
19-
tempDir.RequireExec("git", "init", "--quiet", ".")
19+
tempDir.RequireExec("git", "init", "--initial-branch=main", "--quiet", ".")
2020
tempDir.RequireExec("git", "config", "--local", "user.name", "example")
2121
tempDir.RequireExec("git", "config", "--local", "user.email", "[email protected]")
2222
tempDir.WriteFile([]string{"example.txt"}, "Changed!")
@@ -173,7 +173,7 @@ func TestMutatingCanAccessGit(t *testing.T) {
173173
{
174174
"stderr",
175175
"#!/bin/sh \n git status 1>&2",
176-
"accesses-git: On branch master",
176+
"accesses-git: On branch main",
177177
},
178178
}
179179
for _, tt := range ptyTests {

tracing/tracing.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ import (
88
type Span struct {
99
name string
1010
start time.Time
11-
end *time.Time
11+
end time.Time
1212
}
1313

1414
func NewSpan(name string) *Span {
15+
start := time.Now()
1516
span := &Span{
1617
name: name,
17-
start: time.Now(),
18-
end: nil,
18+
start: start,
19+
end: start,
1920
}
2021
spans = append(spans, span)
2122
return span
2223
}
2324

2425
func (span *Span) End() {
25-
now := time.Now()
26-
span.end = &now
26+
span.end = time.Now()
2727
}
2828

2929
func (span *Span) Elapsed() time.Duration {
@@ -41,7 +41,7 @@ func Start() func() {
4141
millis := elapsed.Milliseconds()
4242
var human string
4343
if millis <= 2 {
44-
human = fmt.Sprintf("%dns", elapsed.Microseconds())
44+
human = fmt.Sprintf("%dus", elapsed.Microseconds())
4545
} else {
4646
human = fmt.Sprintf("%dms", millis)
4747
}

tracing/tracing_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tracing
2+
3+
import "time"
4+
5+
func ExampleStart() {
6+
finish := Start()
7+
span := NewSpan("short")
8+
span.end = span.start.Add(time.Nanosecond * 12_300)
9+
span = NewSpan("long")
10+
span.end = span.start.Add(time.Microsecond * 23_400)
11+
finish()
12+
// Output:
13+
// Traced 2 span(s):
14+
// short 12us
15+
// long 23ms
16+
}

0 commit comments

Comments
 (0)