Skip to content

Commit e481efe

Browse files
committed
refactor: clean up dependencies
1 parent 0ce263f commit e481efe

File tree

23 files changed

+429
-159
lines changed

23 files changed

+429
-159
lines changed

.licenserc.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ header:
77
- '**/*.go'
88
- '**/*.s'
99

10-
comment: on-failure
10+
paths-ignore:
11+
- 'internal/httpguts/**'
12+
13+
comment: on-failure

CREDITS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
github.com/stretchr/testify
21
golang.org/x/sync
32
golang.org/x/sys

cache/asynccache/asynccache_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"testing"
2020
"time"
2121

22-
"github.com/stretchr/testify/assert"
22+
"github.com/bytedance/gopkg/internal/assert"
2323
)
2424

2525
func TestGetOK(t *testing.T) {
@@ -36,18 +36,18 @@ func TestGetOK(t *testing.T) {
3636
c := NewAsyncCache(op)
3737

3838
v, err := c.Get(key)
39-
assert.NoError(t, err)
39+
assert.Nil(t, err)
4040
assert.Equal(t, v.(string), ret)
4141

4242
time.Sleep(time.Second / 2)
4343
ret = "change"
4444
v, err = c.Get(key)
45-
assert.NoError(t, err)
45+
assert.Nil(t, err)
4646
assert.NotEqual(t, v.(string), ret)
4747

4848
time.Sleep(time.Second)
4949
v, err = c.Get(key)
50-
assert.NoError(t, err)
50+
assert.Nil(t, err)
5151
assert.Equal(t, v.(string), ret)
5252
}
5353

@@ -70,7 +70,7 @@ func TestGetErr(t *testing.T) {
7070
c := NewAsyncCache(op)
7171

7272
v, err := c.Get(key)
73-
assert.Error(t, err)
73+
assert.True(t, err != nil)
7474
assert.Nil(t, v)
7575

7676
time.Sleep(time.Second / 2)
@@ -79,7 +79,7 @@ func TestGetErr(t *testing.T) {
7979

8080
time.Sleep(time.Second + 10*time.Millisecond)
8181
v, err = c.Get(key)
82-
assert.NoError(t, err)
82+
assert.Nil(t, err)
8383
assert.Equal(t, v.(string), ret)
8484
}
8585

check_branch_name.sh

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

cloud/metainfo/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"strings"
2020

21-
"golang.org/x/net/http/httpguts"
21+
"github.com/bytedance/gopkg/internal/httpguts"
2222
)
2323

2424
// HTTP header prefixes.

cloud/metainfo/http_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ func TestToHTTPHeader(t *testing.T) {
110110
assert(t, h.Get(metainfo.HTTPPrefixPersistent+"abc") == "def")
111111
}
112112

113+
func TestToHTTPHeaderDiscardInvalid(t *testing.T) {
114+
h := make(http.Header)
115+
c := context.Background()
116+
c = metainfo.WithValue(c, "valid", "ok")
117+
c = metainfo.WithValue(c, "bad key", "dropped")
118+
c = metainfo.WithPersistentValue(c, "persist", "still-ok")
119+
c = metainfo.WithPersistentValue(c, "bad", "line\nbreak")
120+
121+
metainfo.ToHTTPHeader(c, h)
122+
123+
assert(t, len(h) == 2, h)
124+
assert(t, h.Get(metainfo.HTTPPrefixTransient+"valid") == "ok")
125+
assert(t, h.Get(metainfo.HTTPPrefixPersistent+"persist") == "still-ok")
126+
}
127+
113128
func TestHTTPHeader(t *testing.T) {
114129
h := make(metainfo.HTTPHeader)
115130
h.Set("Hello", "halo")

collection/zset/zset_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/bytedance/gopkg/internal/assert"
2627
"github.com/bytedance/gopkg/lang/fastrand"
27-
"github.com/stretchr/testify/assert"
2828
)
2929

3030
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
@@ -39,7 +39,7 @@ func randString(prefix string) string {
3939

4040
func TestFloat64Set(t *testing.T) {
4141
z := NewFloat64()
42-
assert.Zero(t, z.Len())
42+
assert.True(t, z.Len() == 0)
4343
}
4444

4545
func TestFloat64SetAdd(t *testing.T) {
@@ -156,7 +156,7 @@ func TestFloat64SetRank_UpdateScore(t *testing.T) {
156156
for _, v := range vs {
157157
r := z.Rank(v)
158158
assert.NotEqual(t, -1, r)
159-
assert.Greater(t, z.Len(), r)
159+
assert.True(t, z.Len() > r)
160160

161161
// verify rank by traversing level 0
162162
actualRank := 0
@@ -237,11 +237,16 @@ func testInternalSpan(t *testing.T, z *Float64Set) {
237237
assert.NotEqual(t, -1, toRank)
238238

239239
// span = to.rank - from.rank
240-
assert.Equalf(t, span, toRank-fromRank, "from %q (score: , rank: %d) to %q (score: %d, rank: %d), expect span: %d, actual: %d",
241-
from, fromScore, fromRank, to, toScore, toRank, span, toRank-fromRank)
240+
if span != toRank-fromRank {
241+
t.Fatalf("from %q (score: %v, rank: %d) to %q (score: %v, rank: %d), expect span: %d, actual: %d",
242+
from, fromScore, fromRank, to, toScore, toRank, span, toRank-fromRank)
243+
}
242244
} else { // from -> nil
243245
// span = skiplist.len - from.rank
244-
assert.Equalf(t, l.length-fromRank, x.loadSpan(i), "%q (score: , rank: %d)", from, fromScore, fromRank)
246+
if l.length-fromRank != x.loadSpan(i) {
247+
t.Fatalf("%q (score: %v, rank: %d): expect span %d, actual %d",
248+
from, fromScore, fromRank, l.length-fromRank, x.loadSpan(i))
249+
}
245250
}
246251
}
247252
}
@@ -408,8 +413,8 @@ func testFloat64SetRangeByScore(t *testing.T, rev bool) {
408413
}
409414
var prev *float64
410415
for _, n := range ns {
411-
assert.LessOrEqual(t, min, n.Score)
412-
assert.GreaterOrEqual(t, max, n.Score)
416+
assert.True(t, min <= n.Score)
417+
assert.True(t, max >= n.Score)
413418
if prev != nil {
414419
if rev {
415420
assert.True(t, *prev >= n.Score)
@@ -598,7 +603,7 @@ func TestUnionFloat64(t *testing.T) {
598603

599604
func TestUnionFloat64_Empty(t *testing.T) {
600605
z := UnionFloat64()
601-
assert.Zero(t, z.Len())
606+
assert.True(t, z.Len() == 0)
602607
}
603608

604609
func TestInterFloat64(t *testing.T) {
@@ -626,7 +631,7 @@ func TestInterFloat64(t *testing.T) {
626631

627632
func TestInterFloat64_Empty(t *testing.T) {
628633
z := InterFloat64()
629-
assert.Zero(t, z.Len())
634+
assert.True(t, z.Len() == 0)
630635
}
631636

632637
func TestInterFloat64_Simple(t *testing.T) {
@@ -638,7 +643,7 @@ func TestInterFloat64_Simple(t *testing.T) {
638643
z3.Add(0, "2")
639644

640645
z := InterFloat64(z1, z2, z3)
641-
assert.Zero(t, z.Len())
646+
assert.True(t, z.Len() == 0)
642647
}
643648

644649
func BenchmarkRankAfterDelete(b *testing.B) {

go.mod

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ module github.com/bytedance/gopkg
33
go 1.18
44

55
require (
6-
github.com/stretchr/testify v1.9.0
7-
golang.org/x/net v0.24.0
8-
golang.org/x/sync v0.8.0
9-
golang.org/x/sys v0.19.0
10-
)
11-
12-
require (
13-
github.com/davecgh/go-spew v1.1.1 // indirect
14-
github.com/pmezard/go-difflib v1.0.0 // indirect
15-
golang.org/x/text v0.14.0 // indirect
16-
gopkg.in/yaml.v3 v3.0.1 // indirect
6+
golang.org/x/sync v0.11.0
7+
golang.org/x/sys v0.30.0
178
)

go.sum

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
6-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7-
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
8-
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
9-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
10-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
11-
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
12-
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
13-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
14-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
15-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
16-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
17-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
18-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1+
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
2+
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
3+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
4+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

internal/assert/assert.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2025 ByteDance Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package assert
16+
17+
import (
18+
"reflect"
19+
"testing"
20+
)
21+
22+
func Equal(t *testing.T, expected, actual any) {
23+
t.Helper()
24+
if !reflect.DeepEqual(expected, actual) {
25+
t.Fatalf("expected %#v, got %#v", expected, actual)
26+
}
27+
}
28+
29+
func NotEqual(t *testing.T, expected, actual any) {
30+
t.Helper()
31+
if reflect.DeepEqual(expected, actual) {
32+
t.Fatalf("did not expect %#v", actual)
33+
}
34+
}
35+
36+
func True(t *testing.T, cond bool) {
37+
t.Helper()
38+
if !cond {
39+
t.Fatal("expected true")
40+
}
41+
}
42+
43+
func False(t *testing.T, cond bool) {
44+
t.Helper()
45+
if cond {
46+
t.Fatal("expected false")
47+
}
48+
}
49+
50+
func Nil(t *testing.T, v any) {
51+
t.Helper()
52+
if isNil(v) {
53+
return
54+
}
55+
t.Fatalf("expected nil, got %#v", v)
56+
}
57+
58+
func isNil(v any) bool {
59+
if v == nil {
60+
return true
61+
}
62+
rv := reflect.ValueOf(v)
63+
switch rv.Kind() {
64+
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
65+
return rv.IsNil()
66+
default:
67+
return false
68+
}
69+
}

0 commit comments

Comments
 (0)