Skip to content

add banlist and tests #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 25, 2019
Merged

add banlist and tests #94

merged 3 commits into from
Sep 25, 2019

Conversation

rybit
Copy link
Member

@rybit rybit commented Sep 20, 2019

This is a port of what is in the proxy. I wanted to add it to commons so we could export it to other projects (e.g. nfsvr). Also I added tests and the ability to ban per path.

@rybit rybit requested a review from smoya September 20, 2019 00:27
)

func init() {
logrus.SetLevel(logrus.DebugLevel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are not using the global logrus instance in banlist.go, why do we need to set the level here? Just do it on the logger tl instead so you do not modify the global one (which could be used by another tests, etc)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using the global logrus instance in testing, I'm not sure if there is a way to actually set this from env vars automatically (😭). That is then injected into the banlist.

I think it might be overkill to start a new logger each time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see still why we use the global one. At the end you can translate all the log initialization of this test to

l := logrus.New()
l.SetLevel(logrus.DebugLevel)
l.WithField("test", t.Name())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't really matter at all actually. I truly don't care. Global | not in tests is not a big deal for me. If you're testing log lines and hooks you should init a new one there. So there isn't a big impact either way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it

}

func tl(t *testing.T) logrus.FieldLogger {
return logrus.WithField("test", t.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return logrus.WithField("test", t.Name())
return logrus.New().WithField("test", t.Name())

Otherwise you are modifying the global instance. We can't ensure no one else is using it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, we want to use the global one so that we can globally set the level|format

func TestBanlistBanning(t *testing.T) {
bl := testList(t, &Config{
URLs: []string{"villians.com/the/joker"},
Domains: []string{"sick.com"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😷 🤧 🤒

Domains: []string{"something.com"},
})

assert.Len(t, bl.urls(), 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor:

Suggested change
assert.Len(t, bl.urls(), 0)
assert.Empty(t, bl.urls())

path string
}

func New(log logrus.FieldLogger, path string) *Banlist {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor:

Suggested change
func New(log logrus.FieldLogger, path string) *Banlist {
func New(log logrus.FieldLogger, filepath string) *Banlist {

It confuses me the fact that I did not know if we were talking about a URL path or a filepath.

}

func (b *Banlist) Close() {
signal.Stop(b.ch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rybit rybit merged commit bd38f31 into master Sep 25, 2019
@rybit rybit deleted the add-ban-list branch September 25, 2019 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants