Skip to content

Commit

Permalink
test: add UT for MustParseRang (#2158)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhou Hao <[email protected]>
  • Loading branch information
zhouhao3 authored and gaius-qi committed Jun 28, 2023
1 parent 2db4903 commit f1f9f97
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/net/http/range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,39 @@ func TestParseURLMetaRange(t *testing.T) {
})
}
}

func TestMustParseRang(t *testing.T) {
tests := []struct {
s string
size int64
rg Range
panic bool
}{
{"bytes=0-9", 10, Range{0, 10}, false},
{"-10", 10, Range{}, true},
{"bytes=500-700,601-999", 10000, Range{}, true},
}

for _, tc := range tests {
func() {
defer func() {
if r := recover(); r != nil && !tc.panic {
t.Errorf("Unexpected panic: %v", r)
} else if r == nil && tc.panic {
t.Errorf("Expected panic but did not panic")
}
}()

erg := tc.rg
rg := MustParseRange(tc.s, tc.size)

if rg.Start != erg.Start {
t.Errorf("MustParseRange(%q).Serve = %d, want %d", tc.s, rg.Start, erg.Start)
}

if rg.Length != erg.Length {
t.Errorf("MustParseRange(%q).Length = %d, want %d", tc.s, rg.Length, erg.Length)
}
}()
}
}

0 comments on commit f1f9f97

Please sign in to comment.