2019-09-04 11:12:00 +00:00
|
|
|
package home
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFilters(t *testing.T) {
|
2020-02-13 11:14:30 +00:00
|
|
|
dir := prepareTestDir()
|
|
|
|
defer func() { _ = os.RemoveAll(dir) }()
|
|
|
|
|
|
|
|
Context = homeContext{}
|
|
|
|
Context.workDir = dir
|
2020-02-12 12:53:36 +00:00
|
|
|
Context.client = &http.Client{
|
2019-09-04 11:12:00 +00:00
|
|
|
Timeout: time.Minute * 5,
|
|
|
|
}
|
|
|
|
|
|
|
|
f := filter{
|
|
|
|
URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt",
|
|
|
|
}
|
|
|
|
|
|
|
|
// download
|
|
|
|
ok, err := f.update()
|
|
|
|
assert.True(t, ok && err == nil)
|
|
|
|
|
|
|
|
// refresh
|
|
|
|
ok, err = f.update()
|
|
|
|
assert.True(t, !ok && err == nil)
|
|
|
|
|
|
|
|
err = f.save()
|
|
|
|
assert.True(t, err == nil)
|
|
|
|
|
|
|
|
err = f.load()
|
|
|
|
assert.True(t, err == nil)
|
|
|
|
|
|
|
|
f.unload()
|
2020-02-13 11:14:30 +00:00
|
|
|
_ = os.Remove(f.Path())
|
2019-09-04 11:12:00 +00:00
|
|
|
}
|