Skip to content

Commit 94f92b2

Browse files
committed
ci: add more test tools
1 parent c4c0f9c commit 94f92b2

File tree

14 files changed

+247
-52
lines changed

14 files changed

+247
-52
lines changed

.github/workflows/go.test.yml

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,65 @@
1-
name: Go
2-
1+
name: CI
32
on:
43
push:
4+
branches:
5+
- "**"
6+
tags-ignore:
7+
- "v*.*.*"
58
pull_request:
6-
9+
branches:
10+
- "**"
711
jobs:
8-
build:
12+
tests:
13+
name: Unit and integrations tests
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
go: ["1.25.1"]
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version: ${{ matrix.go }}
23+
- name: Run tests
24+
run: |
25+
make test+coverage
26+
- uses: shogo82148/actions-goveralls@v1
27+
with:
28+
path-to-profile: coverage.txt
29+
30+
31+
spellcheck:
32+
name: Spellcheck
933
runs-on: ubuntu-latest
1034
steps:
11-
- uses: actions/checkout@v4
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-go@v5
37+
with:
38+
go-version: "1.25.1"
39+
cache: false
40+
- name: Run spellcheck
41+
run: |
42+
go install github.com/client9/misspell/cmd/misspell@latest
43+
misspell -error docs
1244
13-
- name: Set up Go
14-
uses: actions/setup-go@v4
15-
with:
16-
go-version: '1.23.4'
45+
lint:
46+
name: Lint
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: actions/setup-go@v5
51+
with:
52+
go-version: "1.25.1"
53+
cache: false
54+
- name: Run lint
55+
uses: golangci/golangci-lint-action@v8
56+
with:
57+
version: v2.4
58+
args: --timeout 5m
1759

18-
- name: Test
19-
run: make test
60+
govulncheck:
61+
name: Check vulnerabilities
62+
runs-on: ubuntu-latest
63+
steps:
64+
- id: govulncheck
65+
uses: golang/govulncheck-action@v1

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test.go
2-
tmp/
2+
tmp/
3+
coverage.txt

.golangci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- bodyclose
5+
- copyloopvar
6+
- gocyclo
7+
- inamedparam
8+
- misspell
9+
- revive
10+
- testifylint
11+
- whitespace
12+
- unused
13+
- staticcheck
14+
- ineffassign
15+
- govet
16+
- sqlclosecheck
17+
- errcheck
18+
settings:
19+
gocyclo:
20+
min-complexity: 18
21+
govet:
22+
disable:
23+
- shadow
24+
- fieldalignment
25+
enable-all: true
26+
misspell:
27+
locale: US
28+
revive:
29+
rules:
30+
- name: var-naming
31+
disabled: false
32+
arguments:
33+
- [] # AllowList
34+
- ["DTO"] # DenyList
35+
- name: unused-parameter
36+
disabled: false
37+
- name: use-any
38+
disabled: false
39+
testifylint:
40+
disable:
41+
- require-error
42+
- error-nil
43+
- formatter
44+
- encoded-compare
45+
staticcheck:
46+
checks: ["all", "-QF1001"]
47+
exclusions:
48+
generated: strict
49+
rules:
50+
- linters:
51+
- gocyclo
52+
path: _test\.go
53+
- path: (.+)\.go$
54+
text: should have a package comment
55+
paths:
56+
- .github
57+
- resources
58+
issues:
59+
max-issues-per-linter: 0
60+
max-same-issues: 0
61+
formatters:
62+
enable:
63+
- gofmt
64+
settings:
65+
gofmt:
66+
simplify: true
67+
exclusions:
68+
generated: strict
69+
paths:
70+
- .github
71+
- resources

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
test:
22
go test -race -v ./...
3-
3+
4+
test+coverage:
5+
go test -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... ./...
6+
47
changelog:
58
auto-changelog --output CHANGELOG.md
69

10+
lint:
11+
golangci-lint run --timeout=5m ./...

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<img src="debugo.png" width="500" title="debugo">
55
</p>
66

7+
[![Coverage Status](https://coveralls.io/repos/github/YoSev/debugo/badge.svg?branch=main)](https://coveralls.io/github/YoSev/debugo?branch=main)
8+
79
A lightweight, colorful, and flexible debugging utility for Go — inspired by [debug](https://github.com/debug-js/debug) in Node.js.
810

911
`debugo` provides namespaced, timestamped, and color-coded logging with support for inclusion/exclusion patterns and pluggable output streams.

debugo.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package debugo
22

33
import (
44
"io"
5-
"os"
65
"sync"
76
"time"
87

@@ -44,10 +43,6 @@ func (d *Debugger) SetOutput(output io.Writer) {
4443
d.mutex.Lock()
4544
defer d.mutex.Unlock()
4645

47-
if output == nil {
48-
output = os.Stderr
49-
}
50-
5146
d.output = output
5247
}
5348

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/yosev/debugo
22

3-
go 1.23.4
3+
go 1.25.1
44

55
require (
66
github.com/fatih/color v1.18.0

namespace.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ func matchPattern(namespace, pattern string) bool {
4949
base := strings.TrimSuffix(pattern, ":?")
5050
// Match exactly the base or the base followed by anything
5151
regexPattern := "^" + regexp.QuoteMeta(base) + "(:.*)?$"
52-
re, err := regexp.Compile(regexPattern)
53-
if err != nil {
54-
return false
55-
}
52+
re, _ := regexp.Compile(regexPattern) // can not fail due to QuoteMeta
5653
return re.MatchString(namespace)
5754
}
5855

namespace_test.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,77 @@ func TestMatchNamespace(t *testing.T) {
1111

1212
// Empty debug string
1313
SetNamespace("")
14-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
14+
assert.False(t, l.matchNamespace(), "they should be equal")
1515

1616
// Single wildcard
1717
SetNamespace("*")
18-
assert.Equal(t, l.matchNamespace(), true, "they should be equal")
18+
assert.True(t, l.matchNamespace(), "they should be equal")
1919

2020
// Single negative pattern
2121
SetNamespace("-test:*")
22-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
22+
assert.False(t, l.matchNamespace(), "they should be equal")
2323

2424
// Multiple negative patterns
2525
SetNamespace("-test:a,-test:b")
26-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
26+
assert.False(t, l.matchNamespace(), "they should be equal")
2727

2828
// Leading/trailing spaces in debug string
2929
SetNamespace(" test:a ")
30-
assert.Equal(t, l.matchNamespace(), true, "they should be equal")
30+
assert.True(t, l.matchNamespace(), "they should be equal")
3131

3232
// Overlapping inclusion and exclusion
3333
SetNamespace("test:*, -test:a")
34-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
34+
assert.False(t, l.matchNamespace(), "they should be equal")
3535

3636
// Overlapping inclusion and exclusion
3737
SetNamespace("*, -test:a")
38-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
38+
assert.False(t, l.matchNamespace(), "they should be equal")
3939

4040
// Overlapping inclusion and exclusion
4141
SetNamespace("*, -test:?")
42-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
42+
assert.False(t, l.matchNamespace(), "they should be equal")
4343

4444
// Overlapping inclusion and exclusion
4545
SetNamespace("*, -test:*")
46-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
46+
assert.False(t, l.matchNamespace(), "they should be equal")
4747

4848
// Exact match
4949
SetNamespace("test:a")
50-
assert.Equal(t, l.matchNamespace(), true, "they should be equal")
50+
assert.True(t, l.matchNamespace(), "they should be equal")
5151

5252
// Case sensitivity
5353
SetNamespace("TEST:A")
54-
assert.Equal(t, l.matchNamespace(), true, "they should be equal") // Assuming case-sensitive
54+
assert.True(t, l.matchNamespace(), "they should be equal") // Assuming case-sensitive
5555

5656
// No namespace provided
5757
l = New("")
5858
SetNamespace("test:*")
59-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
59+
assert.False(t, l.matchNamespace(), "they should be equal")
6060

6161
// Non-matching wildcards
6262
SetNamespace("test:x*")
63-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
63+
assert.False(t, l.matchNamespace(), "they should be equal")
6464

6565
// Invalid patterns
6666
SetNamespace("--test:*")
67-
assert.Equal(t, l.matchNamespace(), false, "they should be equal")
67+
assert.False(t, l.matchNamespace(), "they should be equal")
6868

6969
// --- Optional pattern tests ---
7070
l = New("info")
7171
SetNamespace("info:?")
72-
assert.Equal(t, l.matchNamespace(), true, "should match the base namespace")
72+
assert.True(t, l.matchNamespace(), "should match the base namespace")
7373

7474
l = New("info:test")
7575
SetNamespace("info:?")
76-
assert.Equal(t, l.matchNamespace(), true, "should match the namespace with suffix")
76+
assert.True(t, l.matchNamespace(), "should match the namespace with suffix")
7777

7878
l = New("info:test:sub")
7979
SetNamespace("info:?")
80-
assert.Equal(t, l.matchNamespace(), true, "should match namespace with deeper suffix")
80+
assert.True(t, l.matchNamespace(), "should match namespace with deeper suffix")
8181

8282
l = New("other")
8383
SetNamespace("info:?")
84-
assert.Equal(t, l.matchNamespace(), false, "should not match unrelated namespace")
84+
assert.False(t, l.matchNamespace(), "should not match unrelated namespace")
8585
}
8686

8787
func TestMatchPattern(t *testing.T) {
@@ -133,3 +133,10 @@ func TestMatchPattern(t *testing.T) {
133133
})
134134
}
135135
}
136+
137+
func TestMatchpatterns(t *testing.T) {
138+
ok := matchPattern("namespace", "[invalid")
139+
assert.False(t, ok)
140+
ok = matchPattern("namespace", "[invalid:?")
141+
assert.False(t, ok)
142+
}

runtime.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ type Timestamp struct {
3232
Format string
3333
}
3434

35-
// Set the global color usage for debugging.
35+
// SetUseColors sets the global color usage for debugging.
3636
func SetUseColors(use bool) {
3737
runtime.mutex.Lock()
3838
defer runtime.mutex.Unlock()
3939

4040
runtime.useColors = use
4141
}
4242

43-
// GetNamespace retrieves the current global color usage for debugging.
43+
// GetUseColors retrieves the current global color usage for debugging.
4444
func GetUseColors() bool {
4545
runtime.mutex.RLock()
4646
defer runtime.mutex.RUnlock()
4747

4848
return runtime.useColors
4949
}
5050

51-
// Set the global namespace for debugging.
51+
// SetNamespace sets the global namespace for debugging.
5252
func SetNamespace(namespace string) {
5353
runtime.mutex.Lock()
5454
defer runtime.mutex.Unlock()
@@ -64,31 +64,31 @@ func GetNamespace() string {
6464
return runtime.namespace
6565
}
6666

67-
// Sets the global timestamp configuration for debugging.
67+
// SetTimestamp sets the global timestamp configuration for debugging.
6868
func SetTimestamp(timestamp *Timestamp) {
6969
runtime.mutex.Lock()
7070
defer runtime.mutex.Unlock()
7171

7272
runtime.timestamp = timestamp
7373
}
7474

75-
// Retrieves the current global timestamp configuration for debugging.
75+
// GetTimestamp retrieves the current global timestamp configuration for debugging.
7676
func GetTimestamp() *Timestamp {
7777
runtime.mutex.RLock()
7878
defer runtime.mutex.RUnlock()
7979

8080
return runtime.timestamp
8181
}
8282

83-
// Sets the global output configuration for debugging.
83+
// SetOutput sets the global output configuration for debugging.
8484
func SetOutput(output io.Writer) {
8585
runtime.mutex.Lock()
8686
defer runtime.mutex.Unlock()
8787

8888
runtime.output = output
8989
}
9090

91-
// Retrieves the current global output configuration for debugging.
91+
// GetOutput retrieves the current global output configuration for debugging.
9292
func GetOutput() io.Writer {
9393
runtime.mutex.RLock()
9494
defer runtime.mutex.RUnlock()

0 commit comments

Comments
 (0)