Skip to content

Commit 740e516

Browse files
committed
Update lint rules, force testify/assert for tests
Use testify's assert package instead of the standard library's testing package.
1 parent 617de62 commit 740e516

30 files changed

+528
-1138
lines changed

.golangci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ linters-settings:
1919
recommendations:
2020
- errors
2121
forbidigo:
22+
analyze-types: true
2223
forbid:
2324
- ^fmt.Print(f|ln)?$
2425
- ^log.(Panic|Fatal|Print)(f|ln)?$
2526
- ^os.Exit$
2627
- ^panic$
2728
- ^print(ln)?$
29+
- p: ^testing.T.(Error|Errorf|Fatal|Fatalf|Fail|FailNow)$
30+
pkg: ^testing$
31+
msg: "use testify/assert instead"
2832
varnamelen:
2933
max-distance: 12
3034
min-name-length: 2
@@ -127,9 +131,12 @@ issues:
127131
exclude-dirs-use-default: false
128132
exclude-rules:
129133
# Allow complex tests and examples, better to be self contained
130-
- path: (examples|main\.go|_test\.go)
134+
- path: (examples|main\.go)
131135
linters:
136+
- gocognit
132137
- forbidigo
138+
- path: _test\.go
139+
linters:
133140
- gocognit
134141

135142
# Allow forbidden identifiers in CLI commands

api_test.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,9 @@ import (
1414

1515
func TestNewAPI(t *testing.T) {
1616
api := NewAPI()
17-
18-
if api.settingEngine == nil {
19-
t.Error("Failed to init settings engine")
20-
}
21-
22-
if api.mediaEngine == nil {
23-
t.Error("Failed to init media engine")
24-
}
25-
26-
if api.interceptorRegistry == nil {
27-
t.Error("Failed to init interceptor registry")
28-
}
17+
assert.NotNil(t, api.settingEngine, "failed to init settings engine")
18+
assert.NotNil(t, api.mediaEngine, "failed to init media engine")
19+
assert.NotNil(t, api.interceptorRegistry, "failed to init interceptor registry")
2920
}
3021

3122
func TestNewAPI_Options(t *testing.T) {
@@ -36,13 +27,9 @@ func TestNewAPI_Options(t *testing.T) {
3627
WithSettingEngine(s),
3728
)
3829

39-
if !api.settingEngine.detach.DataChannels {
40-
t.Error("Failed to set settings engine")
41-
}
42-
43-
if len(api.mediaEngine.audioCodecs) == 0 || len(api.mediaEngine.videoCodecs) == 0 {
44-
t.Error("Failed to set media engine")
45-
}
30+
assert.True(t, api.settingEngine.detach.DataChannels, "failed to set settings engine")
31+
assert.NotEmpty(t, api.mediaEngine.audioCodecs, "failed to set audio codecs")
32+
assert.NotEmpty(t, api.mediaEngine.videoCodecs, "failed to set video codecs")
4633
}
4734

4835
func TestNewAPI_OptionsDefaultize(t *testing.T) {

0 commit comments

Comments
 (0)