Skip to content

Commit 925c1c8

Browse files
feat: v2 (#1)
1 parent 4e905bf commit 925c1c8

14 files changed

Lines changed: 2177 additions & 171 deletions

File tree

.github/workflows/build.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
8+
jobs:
9+
static-analysis:
10+
name: Static analysis
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version-file: go.mod
25+
26+
- name: Verify dependencies
27+
run: go mod verify
28+
29+
- name: Lint
30+
uses: golangci/golangci-lint-action@v6
31+
with:
32+
skip-cache: true
33+
34+
tests:
35+
name: Tests
36+
37+
runs-on: ubuntu-latest
38+
permissions:
39+
contents: read
40+
id-token: write
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Go
47+
uses: actions/setup-go@v5
48+
with:
49+
go-version-file: go.mod
50+
51+
- name: Test
52+
run: go test ./...

.golangci.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- bodyclose
5+
- dogsled
6+
- errcheck
7+
- goconst
8+
- goimports
9+
- goprintffuncname
10+
- gosec
11+
- gosimple
12+
- govet
13+
- ineffassign
14+
- misspell
15+
- nakedret
16+
- copyloopvar
17+
- staticcheck
18+
- stylecheck
19+
- typecheck
20+
- unconvert
21+
- unused
22+
- whitespace
23+
- gocyclo
24+
- exhaustive
25+
- typecheck
26+
- asciicheck
27+
- errorlint
28+
- revive
29+
30+
linters-settings:
31+
revive:
32+
ignore-generated-header: false
33+
severity: warning
34+
rules:
35+
- name: blank-imports
36+
- name: context-as-argument
37+
- name: context-keys-type
38+
- name: dot-imports
39+
- name: empty-block
40+
- name: error-naming
41+
- name: error-return
42+
- name: error-strings
43+
- name: errorf
44+
- name: if-return
45+
- name: increment-decrement
46+
- name: indent-error-flow
47+
- name: range
48+
- name: receiver-naming
49+
- name: redefines-builtin-id
50+
- name: superfluous-else
51+
- name: time-naming
52+
- name: unexported-return
53+
- name: unreachable-code
54+
- name: unused-parameter
55+
exclude: ["TEST"]
56+
- name: var-declaration
57+
- name: var-naming
58+
govet:
59+
enable-all: true
60+
disable:
61+
- fieldalignment
62+
- shadow
63+
64+
issues:
65+
exclude-rules:
66+
- source: "^//\\s*go:generate\\s"
67+
linters: [ lll ]
68+
- source: "(noinspection|TODO)"
69+
linters: [ godot ]
70+
- source: "//noinspection"
71+
linters: [ gocritic ]
72+
- path: "_test\\.go"
73+
linters:
74+
- bodyclose
75+
- dupl
76+
- funlen
77+
- goconst
78+
- gosec
79+
- noctx
80+
- wrapcheck
81+
82+
output:
83+
formats:
84+
- format: colored-line-number
85+
print-issued-lines: true
86+
print-linter-name: true
87+
sort-results: true
88+

.mockery.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
log-level: "warn"
2+
all: true
3+
dir: "{{.InterfaceDir}}/mocks"
4+
outpkg: "mocks"
5+
filename: "{{.InterfaceName | snakecase}}.go"
6+
mockname: "{{.InterfaceName}}"
7+
recursive: true
8+
packages:
9+
github.com/michalkurzeja/go-clock/v2:
10+
11+
# Deprecations compliance
12+
resolve-type-alias: false
13+
disable-version-string: true
14+
issue-845-fix: true

.travis.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

LICENSE

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
The MIT License (MIT)
1+
MIT License
22

3-
Copyright © 2021 - present Michał Kurzeja
3+
Copyright (c) 2022 Michał Kurzeja
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
611

7-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
814

9-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 0 additions & 1 deletion
This file was deleted.

Taskfile.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3'
2+
3+
silent: true
4+
5+
tasks:
6+
default:
7+
desc: "List all available tasks"
8+
cmds: [ 'task --list' ]
9+
10+
tool:mockery:
11+
desc: "Generate mocks using mockery"
12+
aliases: [ mockery, mocks ]
13+
cmds: [ 'go tool mockery' ]

clock.go

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,73 @@
11
package clock
22

33
import (
4+
"testing"
45
"time"
56

6-
"github.com/benbjohnson/clock"
7+
"github.com/jonboulle/clockwork"
78
)
89

9-
// init initializes the Clock variable with a real Clock.
10-
func init() {
11-
Restore()
10+
type Clock clockwork.Clock
11+
12+
type Timer clockwork.Timer
13+
14+
type Ticker clockwork.Ticker
15+
16+
// clk represents a global clock.
17+
var clk Clock = clockwork.NewRealClock()
18+
19+
// Mock replaces the clk with a mock frozen at the given time and returns it.
20+
func Mock(t *testing.T, now time.Time) *clockwork.FakeClock {
21+
fake := clockwork.NewFakeClockAt(now)
22+
Set(fake)
23+
t.Cleanup(func() {
24+
clk = clockwork.NewRealClock()
25+
})
26+
return fake
1227
}
1328

14-
// Clock represents a global clock.
15-
var Clock clock.Clock
29+
// Set sets the global clock.
30+
func Set(c Clock) {
31+
clk = c
32+
}
1633

1734
// After waits for the duration to elapse and then sends the current time
1835
func After(d time.Duration) <-chan time.Time {
19-
return Clock.After(d)
36+
return clk.After(d)
2037
}
2138

2239
// AfterFunc waits for the duration to elapse and then calls f in its own goroutine.
23-
func AfterFunc(d time.Duration, f func()) *clock.Timer {
24-
return Clock.AfterFunc(d, f)
40+
func AfterFunc(d time.Duration, f func()) Timer {
41+
return clk.AfterFunc(d, f)
2542
}
2643

2744
// Now returns the current local time.
2845
func Now() time.Time {
29-
return Clock.Now()
46+
return clk.Now()
3047
}
3148

3249
// Since returns the time elapsed since t.
3350
func Since(t time.Time) time.Duration {
34-
return Clock.Since(t)
51+
return clk.Since(t)
3552
}
3653

3754
// Sleep pauses the current goroutine for at least the duration d.
3855
func Sleep(d time.Duration) {
39-
Clock.Sleep(d)
56+
clk.Sleep(d)
4057
}
4158

4259
// Tick is a convenience wrapper for NewTicker providing access to the ticking channel only.
4360
func Tick(d time.Duration) <-chan time.Time {
44-
return Clock.Tick(d)
61+
return clk.NewTicker(d).Chan()
4562
}
4663

47-
// Ticker returns a new Ticker containing a channel that will send the
64+
// NewTicker returns a new Ticker containing a channel that will send the
4865
// time with a period specified by the duration argument.
49-
func Ticker(d time.Duration) *clock.Ticker {
50-
return Clock.Ticker(d)
51-
}
52-
53-
// Timer creates a new Timer that will send the current time on its channel after at least duration d.
54-
func Timer(d time.Duration) *clock.Timer {
55-
return Clock.Timer(d)
56-
}
57-
58-
// Mock replaces the Clock with a mock frozen at the given time and returns it.
59-
func Mock(now time.Time) *clock.Mock {
60-
mock := clock.NewMock()
61-
mock.Set(now)
62-
63-
Clock = mock
64-
65-
return mock
66+
func NewTicker(d time.Duration) clockwork.Ticker {
67+
return clk.NewTicker(d)
6668
}
6769

68-
// Restore replaces the Clock with the real clock.
69-
func Restore() {
70-
Clock = clock.New()
70+
// NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
71+
func NewTimer(d time.Duration) clockwork.Timer {
72+
return clk.NewTimer(d)
7173
}

0 commit comments

Comments
 (0)