Skip to content

Commit c3abb96

Browse files
simplify testing setup (#71)
1 parent 17a8299 commit c3abb96

File tree

5 files changed

+44
-68
lines changed

5 files changed

+44
-68
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
name: Unit tests (Go ${{ matrix.go }})
1111
steps:
1212
- uses: actions/checkout@v5
13+
with:
14+
submodules: recursive
1315
- uses: actions/setup-go@v6
1416
with:
1517
go-version: ${{ matrix.go }}
@@ -18,6 +20,8 @@ jobs:
1820
run: go run example/main.go
1921
- name: Run tests
2022
run: go test -v -cover -coverprofile coverage.txt -race -shuffle=on .
23+
- name: Run interop tests
24+
run: go test -shuffle=on -v ./interop
2125
- name: Upload coverage to Codecov
2226
if: ${{ !cancelled() }}
2327
uses: codecov/codecov-action@v5
@@ -27,25 +31,3 @@ jobs:
2731
files: coverage.txt
2832
env_vars: GO
2933
token: ${{ secrets.CODECOV_TOKEN }}
30-
integration:
31-
strategy:
32-
fail-fast: false
33-
matrix:
34-
go: [ "1.24.x", "1.25.x" ]
35-
runs-on: ubuntu-latest
36-
name: Integration tests (Go ${{ matrix.go }})
37-
steps:
38-
- uses: actions/checkout@v5
39-
with:
40-
submodules: 'recursive'
41-
- uses: actions/setup-go@v6
42-
with:
43-
go-version: ${{ matrix.go }}
44-
- run: go version
45-
- name: Run interop tests
46-
run: go test -v ./integrationtests/interop/
47-
- name: Run integration tests
48-
run: |
49-
for i in {1..25}; do
50-
go test -v -race -shuffle=on ./integrationtests/self
51-
done

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "integrationtests/interop/qifs"]
2-
path = integrationtests/interop/qifs
1+
[submodule "interop/qifs"]
2+
path = interop/qifs
33
url = https://github.com/qpackers/qifs.git
Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package self
1+
package qpack_test
22

33
import (
44
"bytes"
5+
"fmt"
56
"math/rand/v2"
67
"testing"
78
_ "unsafe" // for go:linkname
@@ -34,19 +35,7 @@ func getEncoder() (*qpack.Encoder, *bytes.Buffer) {
3435
return qpack.NewEncoder(output), output
3536
}
3637

37-
func TestEncodingAndDecodingSingleHeaderField(t *testing.T) {
38-
hf := qpack.HeaderField{
39-
Name: randomString(15),
40-
Value: randomString(15),
41-
}
42-
encoder, output := getEncoder()
43-
require.NoError(t, encoder.WriteField(hf))
44-
headerFields, err := qpack.NewDecoder(nil).DecodeFull(output.Bytes())
45-
require.NoError(t, err)
46-
require.Equal(t, []qpack.HeaderField{hf}, headerFields)
47-
}
48-
49-
func TestEncodingAndDecodingMultipleHeaderFields(t *testing.T) {
38+
func TestEncodeDecode(t *testing.T) {
5039
hfs := []qpack.HeaderField{
5140
{Name: "foo", Value: "bar"},
5241
{Name: "lorem", Value: "ipsum"},
@@ -61,34 +50,6 @@ func TestEncodingAndDecodingMultipleHeaderFields(t *testing.T) {
6150
require.Equal(t, hfs, headerFields)
6251
}
6352

64-
func TestEncodingAndDecodingMultipleRequests(t *testing.T) {
65-
hfs1 := []qpack.HeaderField{{Name: "foo", Value: "bar"}}
66-
hfs2 := []qpack.HeaderField{
67-
{Name: "lorem", Value: "ipsum"},
68-
{Name: randomString(15), Value: randomString(20)},
69-
}
70-
encoder, output := getEncoder()
71-
for _, hf := range hfs1 {
72-
require.NoError(t, encoder.WriteField(hf))
73-
}
74-
req1 := append([]byte{}, output.Bytes()...)
75-
output.Reset()
76-
for _, hf := range hfs2 {
77-
require.NoError(t, encoder.WriteField(hf))
78-
}
79-
req2 := append([]byte{}, output.Bytes()...)
80-
81-
var headerFields []qpack.HeaderField
82-
decoder := qpack.NewDecoder(func(hf qpack.HeaderField) { headerFields = append(headerFields, hf) })
83-
_, err := decoder.Write(req1)
84-
require.NoError(t, err)
85-
require.Equal(t, hfs1, headerFields)
86-
headerFields = nil
87-
_, err = decoder.Write(req2)
88-
require.NoError(t, err)
89-
require.Equal(t, hfs2, headerFields)
90-
}
91-
9253
// replace one character by a random character at a random position
9354
func replaceRandomCharacter(s string) string {
9455
pos := rand.IntN(len(s))
@@ -105,13 +66,22 @@ func replaceRandomCharacter(s string) string {
10566

10667
func check(t *testing.T, encoded []byte, hf qpack.HeaderField) {
10768
t.Helper()
69+
10870
headerFields, err := qpack.NewDecoder(nil).DecodeFull(encoded)
10971
require.NoError(t, err)
11072
require.Len(t, headerFields, 1)
11173
require.Equal(t, hf, headerFields[0])
11274
}
11375

114-
func TestUsingStaticTableForFieldNamesWithoutValues(t *testing.T) {
76+
func TestStaticTableForFieldNamesWithoutValues(t *testing.T) {
77+
for i := range 10 {
78+
t.Run(fmt.Sprintf("run %d", i), func(t *testing.T) {
79+
testStaticTableForFieldNamesWithoutValues(t)
80+
})
81+
}
82+
}
83+
84+
func testStaticTableForFieldNamesWithoutValues(t *testing.T) {
11585
var hf qpack.HeaderField
11686
for {
11787
if entry := staticTable[rand.IntN(len(staticTable))]; len(entry.Value) == 0 {
@@ -131,7 +101,15 @@ func TestUsingStaticTableForFieldNamesWithoutValues(t *testing.T) {
131101
require.Greater(t, output.Len(), encodedLen)
132102
}
133103

134-
func TestUsingStaticTableForFieldNamesWithCustomValues(t *testing.T) {
104+
func TestStaticTableForFieldNamesWithCustomValues(t *testing.T) {
105+
for i := range 10 {
106+
t.Run(fmt.Sprintf("run %d", i), func(t *testing.T) {
107+
testStaticTableForFieldNamesWithCustomValues(t)
108+
})
109+
}
110+
}
111+
112+
func testStaticTableForFieldNamesWithCustomValues(t *testing.T) {
135113
var hf qpack.HeaderField
136114
for {
137115
if entry := staticTable[rand.IntN(len(staticTable))]; len(entry.Value) == 0 {
@@ -155,6 +133,14 @@ func TestUsingStaticTableForFieldNamesWithCustomValues(t *testing.T) {
155133
}
156134

157135
func TestStaticTableForFieldNamesWithValues(t *testing.T) {
136+
for i := range 10 {
137+
t.Run(fmt.Sprintf("run %d", i), func(t *testing.T) {
138+
testStaticTableForFieldNamesWithValues(t)
139+
})
140+
}
141+
}
142+
143+
func testStaticTableForFieldNamesWithValues(t *testing.T) {
158144
var hf qpack.HeaderField
159145
for {
160146
// Only use values with at least 2 characters.
@@ -180,6 +166,14 @@ func TestStaticTableForFieldNamesWithValues(t *testing.T) {
180166
}
181167

182168
func TestStaticTableForFieldValues(t *testing.T) {
169+
for i := range 10 {
170+
t.Run(fmt.Sprintf("run %d", i), func(t *testing.T) {
171+
testStaticTableForFieldValues(t)
172+
})
173+
}
174+
}
175+
176+
func testStaticTableForFieldValues(t *testing.T) {
183177
var hf qpack.HeaderField
184178
for {
185179
// Only use values with at least 2 characters.

0 commit comments

Comments
 (0)