Skip to content

Commit

Permalink
filtering/rulelist: imp docs, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Dec 19, 2023
1 parent f01434b commit 5cea6a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/filtering/rulelist/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type Filter struct {
// rulesCount contains the number of rules in this rule-list filter.
rulesCount int

// checksum is a CRC32 hash used to quickly check if the rule-list filter's
// contents have changed.
// checksum is a CRC32 hash used to quickly check if the rules within a list
// file have changed.
checksum uint32

// enabled, if true, means that this rule-list filter is used for filtering.
Expand Down
16 changes: 8 additions & 8 deletions internal/filtering/rulelist/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestFilter_Refresh(t *testing.T) {
testRuleTextTitle +
testRuleTextBlocked,
)
urlParseErr := os.WriteFile(initialFile, initialData, 0o644)
require.NoError(t, urlParseErr)
writeErr := os.WriteFile(initialFile, initialData, 0o644)
require.NoError(t, writeErr)

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
pt := testutil.PanicT{}
Expand All @@ -35,8 +35,8 @@ func TestFilter_Refresh(t *testing.T) {
require.NoError(pt, err)
}))

srvURL, urlParseErr := url.Parse(srv.URL)
require.NoError(t, urlParseErr)
srvURL, urlErr := url.Parse(srv.URL)
require.NoError(t, urlErr)

testCases := []struct {
url *url.URL
Expand Down Expand Up @@ -74,11 +74,14 @@ func TestFilter_Refresh(t *testing.T) {
URLFilterID: testURLFilterID,
Enabled: true,
})
testutil.AssertErrorMsg(t, tc.wantNewErrMsg, err)
if tc.wantNewErrMsg != "" {
assert.EqualError(t, err, tc.wantNewErrMsg)

return
}

testutil.CleanupAndRequireSuccess(t, f.Close)

require.NotNil(t, f)

ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
Expand All @@ -99,9 +102,6 @@ func TestFilter_Refresh(t *testing.T) {
// Check that the cached file exists.
_, err = os.Stat(filepath.Join(cacheDir, uid.String()+".txt"))
require.NoError(t, err)

err = f.Close()
require.NoError(t, err)
})
}
}
5 changes: 4 additions & 1 deletion internal/filtering/rulelist/rulelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (

// DefaultRuleBufSize is the default length of a buffer used to read a line with
// a filtering rule, in bytes.
//
// TODO(a.garipov): Consider using [datasize.ByteSize]. It is currently only
// used as an int.
const DefaultRuleBufSize = 1024

// DefaultMaxRuleListSize is the default maximum filtering-rule list size.
Expand All @@ -25,7 +28,7 @@ type URLFilterID = int
// UID is the type for the unique IDs of filtering-rule lists.
type UID uuid.UUID

// NewUID returns a new filtering-rule list UID. Any error returned is an error
// NewUID returns a new filtering-rule list UID. Any error returned is an error
// from the cryptographic randomness reader.
func NewUID() (uid UID, err error) {
uuidv7, err := uuid.NewV7()
Expand Down

0 comments on commit 5cea6a6

Please sign in to comment.