Skip to content

Commit

Permalink
NLB-3682: add unit tests for http3 and quic
Browse files Browse the repository at this point in the history
  • Loading branch information
xynicole committed Oct 4, 2023
1 parent 8c4b079 commit fdd9327
Showing 1 changed file with 178 additions and 0 deletions.
178 changes: 178 additions & 0 deletions analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,3 +1067,181 @@ func TestAnalyze_nap_app_protect_reconnect_period_seconds(t *testing.T) {
})
}
}

func TestAnalyze_http3(t *testing.T) {

Check failure on line 1071 in analyze_test.go

View workflow job for this annotation

GitHub Actions / Linting

Function 'TestAnalyze_http3' is too long (77 > 60) (funlen)
t.Parallel()
testcases := map[string]struct {
stmt *Directive
ctx blockCtx
wantErr bool
}{
"http3 ok": {
&Directive{
Directive: "http3",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"http3 not ok": {
&Directive{
Directive: "http3",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"http3_hq ok": {
&Directive{
Directive: "http3",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"http3_hq not ok": {
&Directive{
Directive: "http3",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"http3_max_concurrent_streams ok": {
&Directive{
Directive: "http3_max_concurrent_streams",
Args: []string{"10"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"http3_stream_buffer_size ok": {
&Directive{
Directive: "http3_stream_buffer_size",
Args: []string{"128k"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
err := analyze("nginx.conf", tc.stmt, ";", tc.ctx, &ParseOptions{})

if !tc.wantErr && err != nil {
t.Fatal(err)
}

if tc.wantErr && err == nil {
t.Fatal("expected error, got nil")
}
})
}
}

func TestAnalyze_quic(t *testing.T) {

Check failure on line 1151 in analyze_test.go

View workflow job for this annotation

GitHub Actions / Linting

Function 'TestAnalyze_quic' is too long (95 > 60) (funlen)
t.Parallel()
testcases := map[string]struct {
stmt *Directive
ctx blockCtx
wantErr bool
}{
"quic_active_connection_id_limit ok": {
&Directive{
Directive: "quic_active_connection_id_limit",
Args: []string{"2"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_bpf ok": {
&Directive{
Directive: "quic_bpf",
Args: []string{"on"},
Line: 5,
},
blockCtx{"main"},
false,
},
"quic_bpf not ok": {
&Directive{
Directive: "quic_bpf",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"quic_gso ok": {
&Directive{
Directive: "quic_gso",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_gso not ok": {
&Directive{
Directive: "quic_gso",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"quic_host_key ok": {
&Directive{
Directive: "http3_max_concurrent_streams",
Args: []string{"somefile"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_retry ok": {
&Directive{
Directive: "quic_retry",
Args: []string{"off"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_retry not ok": {
&Directive{
Directive: "quic_retry",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
err := analyze("nginx.conf", tc.stmt, ";", tc.ctx, &ParseOptions{})

if !tc.wantErr && err != nil {
t.Fatal(err)
}

if tc.wantErr && err == nil {
t.Fatal("expected error, got nil")
}
})
}
}

0 comments on commit fdd9327

Please sign in to comment.