Skip to content

Commit

Permalink
Make more consts (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Apr 8, 2023
1 parent 7c372c0 commit 2e49e1b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions cipher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func BenchmarkCipher(b *testing.B) {
}
}

// sinkValue makes variable used and prevents dead code elimination.
func sinkValue(v int64) {
if r := rand.Float32(); r > 2 {
panic(fmt.Sprintf("impossible %g: %v", r, v))
Expand Down
3 changes: 2 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var (
textTailErrUpgradeRequired = errorText(ErrHandshakeUpgradeRequired)
)

var (
const (
// Every new header must be added to TestHeaderNames test.
headerHost = "Host"
headerUpgrade = "Upgrade"
headerConnection = "Connection"
Expand Down
46 changes: 46 additions & 0 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ws
import (
"bufio"
"io/ioutil"
"net/textproto"
"net/url"
"testing"

Expand Down Expand Up @@ -37,6 +38,51 @@ func TestParseHttpVersion(t *testing.T) {
}
}

func TestHeaderNames(t *testing.T) {
testCases := []struct {
have, want string
}{
{
have: headerHost,
want: headerHostCanonical,
},
{
have: headerUpgrade,
want: headerUpgradeCanonical,
},
{
have: headerConnection,
want: headerConnectionCanonical,
},
{
have: headerSecVersion,
want: headerSecVersionCanonical,
},
{
have: headerSecProtocol,
want: headerSecProtocolCanonical,
},
{
have: headerSecExtensions,
want: headerSecExtensionsCanonical,
},
{
have: headerSecKey,
want: headerSecKeyCanonical,
},
{
have: headerSecAccept,
want: headerSecAcceptCanonical,
},
}

for _, tc := range testCases {
if have := textproto.CanonicalMIMEHeaderKey(tc.have); have != tc.want {
t.Errorf("have %q want %q,", have, tc.want)
}
}
}

func BenchmarkParseHttpVersion(b *testing.B) {
for _, c := range httpVersionCases {
b.Run(string(c.in), func(b *testing.B) {
Expand Down

0 comments on commit 2e49e1b

Please sign in to comment.