Skip to content

Commit e2bac20

Browse files
committed
linting: fix missing type assertion checks (forcetypeassert)
priority.go:50:2: right hand must be only type assertion (forcetypeassert) *fq = append(*fq, x.(*prioritizedFrame)) ^ priority.go:104:2: type assertion must be checked (forcetypeassert) frame := heap.Pop(q.queue).(*prioritizedFrame).frame ^ priority_test.go:66:6: type assertion must be checked (forcetypeassert) if frame.(*spdy.DataFrame).StreamId != i { ^ priority_test.go:67:55: type assertion must be checked (forcetypeassert) t.Fatalf("Wrong frame\nActual: %d\nExpecting: %d", frame.(*spdy.DataFrame).StreamId, i) ^ priority_test.go:89:6: type assertion must be checked (forcetypeassert) if frame.(*spdy.DataFrame).StreamId != i { ^ priority_test.go:90:55: type assertion must be checked (forcetypeassert) t.Fatalf("Wrong frame\nActual: %d\nExpecting: %d", frame.(*spdy.DataFrame).StreamId, i) ^ spdy_test.go:847:3: right hand must be only type assertion (forcetypeassert) netconn, _, _ := w.(http.Hijacker).Hijack() ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 66c6b01 commit e2bac20

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

priority.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ func (fq frameQueue) Swap(i, j int) {
4747
}
4848

4949
func (fq *frameQueue) Push(x interface{}) {
50-
*fq = append(*fq, x.(*prioritizedFrame))
50+
pf, ok := x.(*prioritizedFrame)
51+
if !ok || pf == nil {
52+
panic("frameQueue.Push: unexpected value")
53+
}
54+
*fq = append(*fq, pf)
5155
}
5256

5357
func (fq *frameQueue) Pop() interface{} {
@@ -101,7 +105,10 @@ func (q *PriorityFrameQueue) Pop() spdy.Frame {
101105
}
102106
q.c.Wait()
103107
}
104-
frame := heap.Pop(q.queue).(*prioritizedFrame).frame
108+
var frame spdy.Frame
109+
if f, ok := heap.Pop(q.queue).(*prioritizedFrame); ok {
110+
frame = f.frame
111+
}
105112
q.c.Signal()
106113
return frame
107114
}

priority_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ func TestPriorityQueueOrdering(t *testing.T) {
6262
}
6363

6464
for i := spdy.StreamId(0); i < 150; i++ {
65-
frame := queue.Pop()
66-
if frame.(*spdy.DataFrame).StreamId != i {
67-
t.Fatalf("Wrong frame\nActual: %d\nExpecting: %d", frame.(*spdy.DataFrame).StreamId, i)
65+
var sid spdy.StreamId
66+
if frame, ok := queue.Pop().(*spdy.DataFrame); ok {
67+
sid = frame.StreamId
68+
}
69+
if sid != i {
70+
t.Fatalf("Wrong frame\nActual: %d\nExpecting: %d", sid, i)
6871
}
6972
}
7073
}
@@ -85,9 +88,12 @@ func TestPriorityQueueSync(t *testing.T) {
8588

8689
wg.Wait()
8790
for i := spdy.StreamId(0); i < 150; i++ {
88-
frame := queue.Pop()
89-
if frame.(*spdy.DataFrame).StreamId != i {
90-
t.Fatalf("Wrong frame\nActual: %d\nExpecting: %d", frame.(*spdy.DataFrame).StreamId, i)
91+
var sid spdy.StreamId
92+
if frame, ok := queue.Pop().(*spdy.DataFrame); ok {
93+
sid = frame.StreamId
94+
}
95+
if sid != i {
96+
t.Fatalf("Wrong frame\nActual: %d\nExpecting: %d", sid, i)
9197
}
9298
}
9399
}

spdy_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,14 @@ func TestFramingAfterRemoteConnectionClosed(t *testing.T) {
844844

845845
w.WriteHeader(http.StatusSwitchingProtocols)
846846

847-
netconn, _, _ := w.(http.Hijacker).Hijack()
847+
hj, ok := w.(http.Hijacker)
848+
if !ok {
849+
t.Fatal("ResponseWriter should be a http.Hijacker")
850+
}
851+
netconn, _, err := hj.Hijack()
852+
if err != nil {
853+
t.Fatal(err)
854+
}
848855
conn, _ := NewConnection(netconn, true)
849856
go conn.Serve(func(s *Stream) {
850857
_ = s.SendReply(http.Header{}, false)

0 commit comments

Comments
 (0)