15
15
package quickws
16
16
17
17
import (
18
+ "net/http"
19
+ "reflect"
18
20
"testing"
19
21
)
20
22
@@ -41,3 +43,110 @@ func Test_getHttpErrMsg(t *testing.T) {
41
43
}
42
44
})
43
45
}
46
+
47
+ func TestStringToBytes (t * testing.T ) {
48
+ type args struct {
49
+ s string
50
+ }
51
+ tests := []struct {
52
+ name string
53
+ args args
54
+ wantB []byte
55
+ }{
56
+ {
57
+ name : "test1" ,
58
+ args : args {s : "test1" },
59
+ wantB : []byte ("test1" ),
60
+ },
61
+ {
62
+ name : "test2" ,
63
+ args : args {s : "test2" },
64
+ wantB : []byte ("test2" ),
65
+ },
66
+ }
67
+ for _ , tt := range tests {
68
+ t .Run (tt .name , func (t * testing.T ) {
69
+ if gotB := StringToBytes (tt .args .s ); ! reflect .DeepEqual (gotB , tt .wantB ) {
70
+ t .Errorf ("StringToBytes() = %v, want %v" , gotB , tt .wantB )
71
+ }
72
+ })
73
+ }
74
+ }
75
+
76
+ func Test_secWebSocketAccept (t * testing.T ) {
77
+ tests := []struct {
78
+ name string
79
+ want string
80
+ }{
81
+ {name : ">0" },
82
+ }
83
+ for _ , tt := range tests {
84
+ t .Run (tt .name , func (t * testing.T ) {
85
+ if got := secWebSocketAccept (); len (got ) == 0 {
86
+ t .Errorf ("secWebSocketAccept() = %v, want %v" , got , tt .want )
87
+ }
88
+ })
89
+ }
90
+ }
91
+
92
+ func Test_secWebSocketAcceptVal (t * testing.T ) {
93
+ type args struct {
94
+ val string
95
+ }
96
+ tests := []struct {
97
+ name string
98
+ args args
99
+ want string
100
+ }{
101
+ {name : "test1" , args : args {val : "test1" }},
102
+ }
103
+ for _ , tt := range tests {
104
+ t .Run (tt .name , func (t * testing.T ) {
105
+ if got := secWebSocketAcceptVal (tt .args .val ); len (got ) == 0 {
106
+ t .Errorf ("secWebSocketAcceptVal() = %v, want %v" , got , tt .want )
107
+ }
108
+ })
109
+ }
110
+ }
111
+
112
+ func Test_needDecompression (t * testing.T ) {
113
+ type args struct {
114
+ header http.Header
115
+ }
116
+ tests := []struct {
117
+ name string
118
+ args args
119
+ want bool
120
+ }{
121
+ {name : "test1" , args : args {header : http.Header {"Sec-Websocket-Extensions" : {"permessage-deflate; server_no_context_takeover; client_no_context_takeover" }}}, want : true },
122
+ {name : "test2" , args : args {header : http.Header {"Sec-Websocket-Extensions" : {"xx" }}}, want : false },
123
+ }
124
+ for _ , tt := range tests {
125
+ t .Run (tt .name , func (t * testing.T ) {
126
+ if got := needDecompression (tt .args .header ); got != tt .want {
127
+ t .Errorf ("needDecompression() = %v, want %v" , got , tt .want )
128
+ }
129
+ })
130
+ }
131
+ }
132
+
133
+ func Test_maybeCompressionDecompression (t * testing.T ) {
134
+ type args struct {
135
+ header http.Header
136
+ }
137
+ tests := []struct {
138
+ name string
139
+ args args
140
+ want bool
141
+ }{
142
+ {name : "test1" , args : args {header : http.Header {"Sec-Websocket-Extensions" : {"permessage-deflate; server_no_context_takeover; client_no_context_takeover" }}}, want : true },
143
+ {name : "test2" , args : args {header : http.Header {"Sec-Websocket-Extensions" : {"xx" }}}, want : false },
144
+ }
145
+ for _ , tt := range tests {
146
+ t .Run (tt .name , func (t * testing.T ) {
147
+ if got := maybeCompressionDecompression (tt .args .header ); got != tt .want {
148
+ t .Errorf ("maybeCompressionDecompression() = %v, want %v" , got , tt .want )
149
+ }
150
+ })
151
+ }
152
+ }
0 commit comments