Skip to content

Commit fb4115d

Browse files
authored
remove testify dependency (#478)
1 parent 3274c76 commit fb4115d

File tree

7 files changed

+169
-124
lines changed

7 files changed

+169
-124
lines changed

discord/icon_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/disgoorg/json/v2"
7-
"github.com/stretchr/testify/assert"
87
)
98

109
type iconTest struct {
@@ -20,13 +19,21 @@ func TestIcon_MarshalJSON(t *testing.T) {
2019
}
2120

2221
data, err := json.Marshal(v)
23-
assert.NoError(t, err)
24-
assert.Equal(t, `{"icon":"data:image/jpeg;base64,data"}`, string(data))
25-
26-
v = iconTest{
27-
Icon: nil,
22+
if err != nil {
23+
t.Fatalf("unexpected error marshaling: %v", err)
24+
}
25+
expected := `{"icon":"data:image/jpeg;base64,data"}`
26+
if string(data) != expected {
27+
t.Errorf("expected %s, got %s", expected, string(data))
2828
}
29+
30+
v = iconTest{Icon: nil}
2931
data, err = json.Marshal(v)
30-
assert.NoError(t, err)
31-
assert.Equal(t, "{}", string(data))
32+
if err != nil {
33+
t.Fatalf("unexpected error marshaling: %v", err)
34+
}
35+
expected = "{}"
36+
if string(data) != expected {
37+
t.Errorf("expected %s, got %s", expected, string(data))
38+
}
3239
}

discord/permissions_test.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/disgoorg/json/v2"
7-
"github.com/stretchr/testify/assert"
87
)
98

109
type permissionTestStruct struct {
@@ -17,30 +16,52 @@ func TestPermissions_MarshalJSON(t *testing.T) {
1716
}
1817

1918
jsonPerms, err := json.Marshal(someStruct)
20-
assert.NoError(t, err)
21-
assert.Equal(t, "{\"permissions\":\"67108928\"}", string(jsonPerms))
19+
if err != nil {
20+
t.Fatalf("unexpected error marshaling: %v", err)
21+
}
22+
23+
expected := `{"permissions":"67108928"}`
24+
if string(jsonPerms) != expected {
25+
t.Errorf("expected %s, got %s", expected, string(jsonPerms))
26+
}
2227
}
2328

2429
func TestPermissions_UnmarshalJSON(t *testing.T) {
2530
var someStruct permissionTestStruct
2631

27-
err := json.Unmarshal([]byte("{\"permissions\":\"67108928\"}"), &someStruct)
28-
assert.NoError(t, err)
29-
assert.Equal(t, permissionTestStruct{Permissions: PermissionAddReactions | PermissionChangeNickname}, someStruct)
32+
err := json.Unmarshal([]byte(`{"permissions":"67108928"}`), &someStruct)
33+
if err != nil {
34+
t.Fatalf("unexpected error unmarshaling: %v", err)
35+
}
36+
37+
expected := permissionTestStruct{Permissions: PermissionAddReactions | PermissionChangeNickname}
38+
if someStruct != expected {
39+
t.Errorf("expected %+v, got %+v", expected, someStruct)
40+
}
3041
}
3142

3243
func TestPermissions_Add(t *testing.T) {
33-
assert.Equal(t, PermissionAddReactions, Permissions.Add(PermissionAddReactions))
44+
got := Permissions.Add(PermissionAddReactions)
45+
if got != PermissionAddReactions {
46+
t.Errorf("expected %v, got %v", PermissionAddReactions, got)
47+
}
3448
}
3549

3650
func TestPermissions_Remove(t *testing.T) {
37-
assert.Equal(t, PermissionManageChannels, (PermissionAddReactions | PermissionManageChannels).Remove(PermissionAddReactions))
51+
got := (PermissionAddReactions | PermissionManageChannels).Remove(PermissionAddReactions)
52+
if got != PermissionManageChannels {
53+
t.Errorf("expected %v, got %v", PermissionManageChannels, got)
54+
}
3855
}
3956

4057
func TestPermissions_Has(t *testing.T) {
41-
assert.True(t, PermissionAddReactions.Has(PermissionAddReactions))
58+
if !PermissionAddReactions.Has(PermissionAddReactions) {
59+
t.Errorf("expected PermissionAddReactions to have PermissionAddReactions")
60+
}
4261
}
4362

4463
func TestPermissions_Missing(t *testing.T) {
45-
assert.True(t, PermissionManageChannels.Missing(PermissionAddReactions))
64+
if !PermissionManageChannels.Missing(PermissionAddReactions) {
65+
t.Errorf("expected PermissionManageChannels to be missing PermissionAddReactions")
66+
}
4667
}

gateway/identify_rate_limiter_test.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"sync"
66
"testing"
77
"time"
8-
9-
"github.com/stretchr/testify/assert"
108
)
119

1210
func TestIdentifyRateLimiterImpl(t *testing.T) {
@@ -19,17 +17,21 @@ func TestIdentifyRateLimiterImpl(t *testing.T) {
1917
var wg sync.WaitGroup
2018
for shardID := range 3 {
2119
wg.Add(1)
22-
go func() {
20+
go func(id int) {
2321
defer wg.Done()
24-
err := r.Wait(context.Background(), shardID)
25-
assert.NoError(t, err)
26-
r.Unlock(shardID)
27-
}()
22+
err := r.Wait(context.Background(), id)
23+
if err != nil {
24+
t.Errorf("unexpected error for shard %d: %v", id, err)
25+
}
26+
r.Unlock(id)
27+
}(shardID)
2828
}
2929
wg.Wait()
3030

3131
expected := start.Add(200 * time.Millisecond)
32-
assert.WithinDuration(t, expected, time.Now(), 10*time.Millisecond)
32+
if !time.Now().After(expected.Add(-10*time.Millisecond)) || !time.Now().Before(expected.Add(10*time.Millisecond)) {
33+
t.Errorf("expected current time to be within 10ms of %v, got %v", expected, time.Now())
34+
}
3335
}
3436

3537
func TestIdentifyRateLimiterImpl_WithMaxConcurrency(t *testing.T) {
@@ -42,17 +44,21 @@ func TestIdentifyRateLimiterImpl_WithMaxConcurrency(t *testing.T) {
4244
var wg sync.WaitGroup
4345
for shardID := range 6 {
4446
wg.Add(1)
45-
go func() {
47+
go func(id int) {
4648
defer wg.Done()
47-
err := r.Wait(context.Background(), shardID)
48-
assert.NoError(t, err)
49-
r.Unlock(shardID)
50-
}()
49+
err := r.Wait(context.Background(), id)
50+
if err != nil {
51+
t.Errorf("unexpected error for shard %d: %v", id, err)
52+
}
53+
r.Unlock(id)
54+
}(shardID)
5155
}
5256
wg.Wait()
5357

5458
expected := start.Add(100 * time.Millisecond)
55-
assert.WithinDuration(t, expected, time.Now(), 10*time.Millisecond)
59+
if !time.Now().After(expected.Add(-10*time.Millisecond)) || !time.Now().Before(expected.Add(10*time.Millisecond)) {
60+
t.Errorf("expected current time to be within 10ms of %v, got %v", expected, time.Now())
61+
}
5662
}
5763

5864
func TestIdentifyRateLimiterImpl_WaitWithTimeout(t *testing.T) {
@@ -64,11 +70,15 @@ func TestIdentifyRateLimiterImpl_WaitWithTimeout(t *testing.T) {
6470
defer cancel()
6571

6672
err := r.Wait(ctx, 0)
67-
assert.NoError(t, err)
73+
if err != nil {
74+
t.Fatalf("unexpected error on first wait: %v", err)
75+
}
6876

6977
err = r.Wait(ctx, 0)
70-
if assert.Error(t, err) {
71-
assert.Equal(t, context.DeadlineExceeded, err)
78+
if err == nil {
79+
t.Errorf("expected error on second wait due to timeout, got nil")
80+
} else if err != context.DeadlineExceeded {
81+
t.Errorf("expected DeadlineExceeded error, got %v", err)
7282
}
7383

7484
r.Unlock(0)

go.mod

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ require (
88
github.com/disgoorg/snowflake/v2 v2.0.3
99
github.com/gorilla/websocket v1.5.3
1010
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad
11-
github.com/stretchr/testify v1.10.0
1211
golang.org/x/crypto v0.39.0
1312
)
1413

15-
require (
16-
github.com/davecgh/go-spew v1.1.1 // indirect
17-
github.com/pmezard/go-difflib v1.0.0 // indirect
18-
golang.org/x/sys v0.33.0 // indirect
19-
gopkg.in/yaml.v3 v3.0.1 // indirect
20-
)
14+
require golang.org/x/sys v0.33.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
1818
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
1919
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
2020
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
21-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
22-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2321
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2422
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)