| 1 |
// Copyright 2022 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build !nethttpomithttp2 |
| 6 |
|
| 7 |
package http |
| 8 |
|
| 9 |
import ( |
| 10 |
"errors" |
| 11 |
"fmt" |
| 12 |
"testing" |
| 13 |
) |
| 14 |
|
| 15 |
type externalStreamErrorCode uint32 |
| 16 |
|
| 17 |
type externalStreamError struct { |
| 18 |
StreamID uint32 |
| 19 |
Code externalStreamErrorCode |
| 20 |
Cause error |
| 21 |
} |
| 22 |
|
| 23 |
func (e externalStreamError) Error() string { |
| 24 |
return fmt.Sprintf("ID %v, code %v", e.StreamID, e.Code) |
| 25 |
} |
| 26 |
|
| 27 |
func TestStreamError(t *testing.T) { |
| 28 |
var target externalStreamError |
| 29 |
streamErr := http2streamError(42, http2ErrCodeProtocol) |
| 30 |
ok := errors.As(streamErr, &target) |
| 31 |
if !ok { |
| 32 |
t.Fatalf("errors.As failed") |
| 33 |
} |
| 34 |
if target.StreamID != streamErr.StreamID { |
| 35 |
t.Errorf("got StreamID %v, expected %v", target.StreamID, streamErr.StreamID) |
| 36 |
} |
| 37 |
if target.Cause != streamErr.Cause { |
| 38 |
t.Errorf("got Cause %v, expected %v", target.Cause, streamErr.Cause) |
| 39 |
} |
| 40 |
if uint32(target.Code) != uint32(streamErr.Code) { |
| 41 |
t.Errorf("got Code %v, expected %v", target.Code, streamErr.Code) |
| 42 |
} |
| 43 |
} |