all: Even more boring linter fixes (#5501)

This commit is contained in:
Jakob Borg 2019-02-02 11:45:17 +01:00 committed by GitHub
parent df5c1eaf01
commit 0b2cabbc31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 131 additions and 104 deletions

View File

@ -81,7 +81,7 @@ func (w *AtomicWriter) Close() error {
}
// Try to not leave temp file around, but ignore error.
defer w.fs.Remove(w.next.Name())
defer func() { _ = w.fs.Remove(w.next.Name()) }()
if err := w.next.Sync(); err != nil {
w.err = err
@ -110,7 +110,7 @@ func (w *AtomicWriter) Close() error {
// fsync the directory too
if fd, err := w.fs.Open(filepath.Dir(w.next.Name())); err == nil {
fd.Sync()
_ = fd.Sync()
fd.Close()
}

View File

@ -42,7 +42,7 @@ func TryRename(filesystem fs.Filesystem, from, to string) error {
func Rename(filesystem fs.Filesystem, from, to string) error {
// Don't leave a dangling temp file in case of rename error
if !(runtime.GOOS == "windows" && strings.EqualFold(from, to)) {
defer filesystem.Remove(from)
defer func() { _ = filesystem.Remove(from) }()
}
return TryRename(filesystem, from, to)
}
@ -94,13 +94,13 @@ func withPreparedTarget(filesystem fs.Filesystem, from, to string, f func() erro
// Make sure the destination directory is writeable
toDir := filepath.Dir(to)
if info, err := filesystem.Stat(toDir); err == nil && info.IsDir() && info.Mode()&0200 == 0 {
filesystem.Chmod(toDir, 0755)
defer filesystem.Chmod(toDir, info.Mode())
_ = filesystem.Chmod(toDir, 0755)
defer func() { _ = filesystem.Chmod(toDir, info.Mode()) }()
}
// On Windows, make sure the destination file is writeable (or we can't delete it)
if runtime.GOOS == "windows" {
filesystem.Chmod(to, 0666)
_ = filesystem.Chmod(to, 0666)
if !strings.EqualFold(from, to) {
err := filesystem.Remove(to)
if err != nil && !fs.IsNotExist(err) {

View File

@ -26,9 +26,9 @@ func TestInWriteableDir(t *testing.T) {
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, ".")
os.Mkdir("testdata", 0700)
os.Mkdir("testdata/rw", 0700)
os.Mkdir("testdata/ro", 0500)
_ = os.Mkdir("testdata", 0700)
_ = os.Mkdir("testdata/rw", 0700)
_ = os.Mkdir("testdata/ro", 0500)
create := func(name string) error {
fd, err := os.Create(name)
@ -87,7 +87,7 @@ func TestInWritableDirWindowsRemove(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.Chmod("testdata/windows/ro/readonlynew", 0700)
defer func() { _ = os.Chmod("testdata/windows/ro/readonlynew", 0700) }()
defer os.RemoveAll("testdata")
create := func(name string) error {
@ -99,12 +99,12 @@ func TestInWritableDirWindowsRemove(t *testing.T) {
return nil
}
os.Mkdir("testdata", 0700)
_ = os.Mkdir("testdata", 0700)
os.Mkdir("testdata/windows", 0500)
os.Mkdir("testdata/windows/ro", 0500)
create("testdata/windows/ro/readonly")
os.Chmod("testdata/windows/ro/readonly", 0500)
_ = os.Mkdir("testdata/windows", 0500)
_ = os.Mkdir("testdata/windows/ro", 0500)
_ = create("testdata/windows/ro/readonly")
_ = os.Chmod("testdata/windows/ro/readonly", 0500)
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, ".")
@ -128,8 +128,8 @@ func TestInWritableDirWindowsRemoveAll(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.Chmod("testdata/windows/ro/readonlynew", 0700)
defer os.RemoveAll("testdata")
defer func() { _ = os.Chmod("testdata/windows/ro/readonlynew", 0700) }()
defer func() { _ = os.RemoveAll("testdata") }()
create := func(name string) error {
fd, err := os.Create(name)
@ -140,12 +140,12 @@ func TestInWritableDirWindowsRemoveAll(t *testing.T) {
return nil
}
os.Mkdir("testdata", 0700)
_ = os.Mkdir("testdata", 0700)
os.Mkdir("testdata/windows", 0500)
os.Mkdir("testdata/windows/ro", 0500)
create("testdata/windows/ro/readonly")
os.Chmod("testdata/windows/ro/readonly", 0500)
_ = os.Mkdir("testdata/windows", 0500)
_ = os.Mkdir("testdata/windows/ro", 0500)
_ = create("testdata/windows/ro/readonly")
_ = os.Chmod("testdata/windows/ro/readonly", 0500)
if err := os.RemoveAll("testdata/windows"); err != nil {
t.Errorf("Unexpected error: %s", err)
@ -162,8 +162,8 @@ func TestInWritableDirWindowsRename(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.Chmod("testdata/windows/ro/readonlynew", 0700)
defer os.RemoveAll("testdata")
defer func() { _ = os.Chmod("testdata/windows/ro/readonlynew", 0700) }()
defer func() { _ = os.RemoveAll("testdata") }()
create := func(name string) error {
fd, err := os.Create(name)
@ -174,12 +174,12 @@ func TestInWritableDirWindowsRename(t *testing.T) {
return nil
}
os.Mkdir("testdata", 0700)
_ = os.Mkdir("testdata", 0700)
os.Mkdir("testdata/windows", 0500)
os.Mkdir("testdata/windows/ro", 0500)
create("testdata/windows/ro/readonly")
os.Chmod("testdata/windows/ro/readonly", 0500)
_ = os.Mkdir("testdata/windows", 0500)
_ = os.Mkdir("testdata/windows/ro", 0500)
_ = create("testdata/windows/ro/readonly")
_ = os.Chmod("testdata/windows/ro/readonly", 0500)
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, ".")
@ -232,7 +232,7 @@ func TestIsDeleted(t *testing.T) {
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata")
testFs.MkdirAll("dir", 0777)
_ = testFs.MkdirAll("dir", 0777)
for _, f := range []string{"file", "del.file", "dir.file", "dir/file"} {
fd, err := testFs.Create(f)
if err != nil {
@ -242,7 +242,7 @@ func TestIsDeleted(t *testing.T) {
}
if runtime.GOOS != "windows" {
// Can't create unreadable dir on windows
testFs.MkdirAll("inacc", 0777)
_ = testFs.MkdirAll("inacc", 0777)
if err := testFs.Chmod("inacc", 0000); err == nil {
if _, err := testFs.Lstat("inacc/file"); fs.IsPermission(err) {
// May fail e.g. if tests are run as root -> just skip
@ -265,6 +265,6 @@ func TestIsDeleted(t *testing.T) {
}
}
testFs.Chmod("inacc", 0777)
_ = testFs.Chmod("inacc", 0777)
os.RemoveAll("testdata")
}

View File

@ -25,7 +25,7 @@ func TestTraversesSymlink(t *testing.T) {
defer os.RemoveAll(tmpDir)
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir)
fs.MkdirAll("a/b/c", 0755)
_ = fs.MkdirAll("a/b/c", 0755)
if err = osutil.DebugSymlinkForTestsOnly(filepath.Join(fs.URI(), "a", "b"), filepath.Join(fs.URI(), "a", "l")); err != nil {
if runtime.GOOS == "windows" {
t.Skip("Symlinks aren't working")
@ -78,7 +78,7 @@ func TestIssue4875(t *testing.T) {
defer os.RemoveAll(tmpDir)
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir)
testFs.MkdirAll("a/b/c", 0755)
_ = testFs.MkdirAll("a/b/c", 0755)
if err = osutil.DebugSymlinkForTestsOnly(filepath.Join(testFs.URI(), "a", "b"), filepath.Join(testFs.URI(), "a", "l")); err != nil {
if runtime.GOOS == "windows" {
t.Skip("Symlinks aren't working")
@ -107,7 +107,7 @@ func BenchmarkTraversesSymlink(b *testing.B) {
os.RemoveAll("testdata")
defer os.RemoveAll("testdata")
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata")
fs.MkdirAll("a/b/c", 0755)
_ = fs.MkdirAll("a/b/c", 0755)
for i := 0; i < b.N; i++ {
traversesSymlinkResult = osutil.TraversesSymlink(fs, "a/b/c")

View File

@ -132,8 +132,8 @@ func getTCPConnectionPair() (net.Conn, net.Conn, error) {
}
// Set the buffer sizes etc as usual
dialer.SetTCPOptions(conn0)
dialer.SetTCPOptions(conn1)
_ = dialer.SetTCPOptions(conn0)
_ = dialer.SetTCPOptions(conn1)
return conn0, conn1, nil
}

View File

@ -35,7 +35,7 @@ func repeatedDeviceID(v byte) (d DeviceID) {
func NewDeviceID(rawCert []byte) DeviceID {
var n DeviceID
hf := sha256.New()
hf.Write(rawCert)
_, _ = hf.Write(rawCert)
hf.Sum(n[:0])
return n
}

View File

@ -64,9 +64,13 @@ func TestMarshallingDeviceID(t *testing.T) {
n2 := DeviceID{}
bs, _ := n0.MarshalText()
n1.UnmarshalText(bs)
if err := n1.UnmarshalText(bs); err != nil {
t.Fatal(err)
}
bs, _ = n1.MarshalText()
n2.UnmarshalText(bs)
if err := n2.UnmarshalText(bs); err != nil {
t.Fatal(err)
}
if n2.String() != n0.String() {
t.Errorf("String marshalling error; %q != %q", n2.String(), n0.String())

View File

@ -7,12 +7,9 @@ import (
"encoding/binary"
"encoding/hex"
"io"
"regexp"
"testing"
)
var spaceRe = regexp.MustCompile(`\s`)
func TestVersion14Hello(t *testing.T) {
// Tests that we can send and receive a version 0.14 hello message.

View File

@ -175,7 +175,6 @@ type rawConnection struct {
closed chan struct{}
closeOnce sync.Once
sendCloseOnce sync.Once
writerExited chan struct{}
compression Compression
}
@ -227,7 +226,10 @@ func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiv
// Start creates the goroutines for sending and receiving of messages. It must
// be called exactly once after creating a connection.
func (c *rawConnection) Start() {
go c.readerLoop()
go func() {
err := c.readerLoop()
c.internalClose(err)
}()
go c.writerLoop()
go c.pingSender()
go c.pingReceiver()
@ -336,10 +338,6 @@ func (c *rawConnection) ping() bool {
}
func (c *rawConnection) readerLoop() (err error) {
defer func() {
c.internalClose(err)
}()
fourByteBuf := make([]byte, 4)
state := stateInitial
for {

View File

@ -69,8 +69,8 @@ func TestClose(t *testing.T) {
t.Error("Ping should not return true")
}
c0.Index("default", nil)
c0.Index("default", nil)
_ = c0.Index("default", nil)
_ = c0.Index("default", nil)
if _, err := c0.Request("default", "foo", 0, 0, nil, 0, false); err == nil {
t.Error("Request should return an error")
@ -225,8 +225,8 @@ func testMarshal(t *testing.T, prefix string, m1, m2 message) bool {
bs1, _ := json.MarshalIndent(m1, "", " ")
bs2, _ := json.MarshalIndent(m2, "", " ")
if !bytes.Equal(bs1, bs2) {
ioutil.WriteFile(prefix+"-1.txt", bs1, 0644)
ioutil.WriteFile(prefix+"-2.txt", bs2, 0644)
_ = ioutil.WriteFile(prefix+"-1.txt", bs1, 0644)
_ = ioutil.WriteFile(prefix+"-2.txt", bs2, 0644)
return false
}

View File

@ -67,7 +67,7 @@ func Intn(n int) int {
// suitable for use a predictable random seed.
func SeedFromBytes(bs []byte) int64 {
h := md5.New()
h.Write(bs)
_, _ = h.Write(bs)
s := h.Sum(nil)
// The MD5 hash of the byte slice is 16 bytes long. We interpret it as two
// uint64s and XOR them together.

View File

@ -114,7 +114,7 @@ func (p *Process) Start(bin string, args ...string) error {
}
func (p *Process) wait() {
p.cmd.Wait()
_ = p.cmd.Wait()
if p.logfd != nil {
p.stopErr = p.checkForProblems(p.logfd)

View File

@ -27,7 +27,7 @@ func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs [
}
conn := tls.Client(rconn, configForCerts(certs))
conn.SetDeadline(time.Now().Add(timeout))
_ = conn.SetDeadline(time.Now().Add(timeout))
if err := performHandshakeAndValidation(conn, uri); err != nil {
return protocol.SessionInvitation{}, err
@ -75,7 +75,7 @@ func JoinSession(invitation protocol.SessionInvitation) (net.Conn, error) {
Key: invitation.Key,
}
conn.SetDeadline(time.Now().Add(10 * time.Second))
_ = conn.SetDeadline(time.Now().Add(10 * time.Second))
err = protocol.WriteMessage(conn, request)
if err != nil {
return nil, err
@ -86,7 +86,7 @@ func JoinSession(invitation protocol.SessionInvitation) (net.Conn, error) {
return nil, err
}
conn.SetDeadline(time.Time{})
_ = conn.SetDeadline(time.Time{})
switch msg := message.(type) {
case protocol.Response:

View File

@ -116,7 +116,7 @@ func Validate(buf, hash []byte, weakHash uint32) bool {
return true
}
// Copy error or mismatch, go to next algo.
rd.Seek(0, io.SeekStart)
_, _ = rd.Seek(0, io.SeekStart)
}
if len(hash) > 0 {

View File

@ -112,10 +112,10 @@ func TestAdler32Variants(t *testing.T) {
hf2 := rollingAdler32.New()
checkFn := func(data []byte) bool {
hf1.Write(data)
_, _ = hf1.Write(data)
sum1 := hf1.Sum32()
hf2.Write(data)
_, _ = hf2.Write(data)
sum2 := hf2.Sum32()
hf1.Reset()
@ -127,7 +127,7 @@ func TestAdler32Variants(t *testing.T) {
// protocol block sized data
data := make([]byte, protocol.MinBlockSize)
for i := 0; i < 5; i++ {
rand.Read(data)
_, _ = rand.Read(data)
if !checkFn(data) {
t.Errorf("Hash mismatch on block sized data")
}
@ -145,13 +145,13 @@ func TestAdler32Variants(t *testing.T) {
windowSize := 128
hf3 := rollingAdler32.New()
hf3.Write(data[:windowSize])
_, _ = hf3.Write(data[:windowSize])
for i := windowSize; i < len(data); i++ {
if i%windowSize == 0 {
// let the reference function catch up
hf2.Reset()
hf2.Write(data[i-windowSize : i])
_, _ = hf2.Write(data[i-windowSize : i])
// verify that they are in sync with the rolling function
sum2 := hf2.Sum32()

View File

@ -17,7 +17,7 @@ import (
"time"
"unicode/utf8"
"github.com/rcrowley/go-metrics"
metrics "github.com/rcrowley/go-metrics"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/ignore"
@ -108,10 +108,10 @@ func (w *walker) walk(ctx context.Context) chan ScanResult {
go func() {
hashFiles := w.walkAndHashFiles(ctx, toHashChan, finishedChan)
if len(w.Subs) == 0 {
w.Filesystem.Walk(".", hashFiles)
_ = w.Filesystem.Walk(".", hashFiles)
} else {
for _, sub := range w.Subs {
w.Filesystem.Walk(sub, hashFiles)
_ = w.Filesystem.Walk(sub, hashFiles)
}
}
close(toHashChan)
@ -223,7 +223,7 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
if fs.IsTemporary(path) {
l.Debugln("temporary:", path, "err:", err)
if err == nil && info.IsRegular() && info.ModTime().Add(w.TempLifetime).Before(now) {
w.Filesystem.Remove(path)
_ = w.Filesystem.Remove(path)
l.Debugln("removing temporary:", path, info.ModTime())
}
return nil

View File

@ -216,7 +216,7 @@ func TestNormalization(t *testing.T) {
if fd, err := testFs.OpenFile(filepath.Join("normalization", s1, s2), os.O_CREATE|os.O_EXCL, 0644); err != nil {
t.Fatal(err)
} else {
fd.Write([]byte("test"))
_, _ = fd.Write([]byte("test"))
fd.Close()
}
}
@ -257,7 +257,7 @@ func TestIssue1507(t *testing.T) {
f := make(chan ScanResult, 100)
fn := w.walkAndHashFiles(context.TODO(), h, f)
fn("", nil, protocol.ErrClosed)
_ = fn("", nil, protocol.ErrClosed)
}
func TestWalkSymlinkUnix(t *testing.T) {
@ -268,9 +268,9 @@ func TestWalkSymlinkUnix(t *testing.T) {
// Create a folder with a symlink in it
os.RemoveAll("_symlinks")
os.Mkdir("_symlinks", 0755)
_ = os.Mkdir("_symlinks", 0755)
defer os.RemoveAll("_symlinks")
os.Symlink("../testdata", "_symlinks/link")
_ = os.Symlink("../testdata", "_symlinks/link")
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, "_symlinks")
for _, path := range []string{".", "link"} {
@ -298,7 +298,7 @@ func TestWalkSymlinkWindows(t *testing.T) {
// Create a folder with a symlink in it
name := "_symlinks-win"
os.RemoveAll(name)
os.Mkdir(name, 0755)
_ = os.Mkdir(name, 0755)
defer os.RemoveAll(name)
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, name)
if err := osutil.DebugSymlinkForTestsOnly("../testdata", "_symlinks/link"); err != nil {

View File

@ -115,12 +115,12 @@ func cpuBenchOnce(duration time.Duration, newFn func() hash.Hash) float64 {
chunkSize := 100 * 1 << 10
h := newFn()
bs := make([]byte, chunkSize)
rand.Reader.Read(bs)
_, _ = rand.Reader.Read(bs)
t0 := time.Now()
b := 0
for time.Since(t0) < duration {
h.Write(bs)
_, _ = h.Write(bs)
b += chunkSize
}
h.Sum(nil)
@ -146,7 +146,7 @@ func verifyCorrectness() {
input := "Syncthing Magic Testing Value\n"
h := New()
h.Write([]byte(input))
_, _ = h.Write([]byte(input))
sum := hex.EncodeToString(h.Sum(nil))
if sum != correct {
panic("sha256 is broken")

View File

@ -12,7 +12,7 @@ import (
"strings"
"time"
"github.com/sasha-s/go-deadlock"
deadlock "github.com/sasha-s/go-deadlock"
"github.com/syncthing/syncthing/lib/logger"
)

View File

@ -186,9 +186,9 @@ func (l *DowngradingListener) AcceptNoWrapTLS() (net.Conn, bool, error) {
}
var first [1]byte
conn.SetReadDeadline(time.Now().Add(1 * time.Second))
_ = conn.SetReadDeadline(time.Now().Add(1 * time.Second))
n, err := conn.Read(first[:])
conn.SetReadDeadline(time.Time{})
_ = conn.SetReadDeadline(time.Time{})
if err != nil || n == 0 {
// We hit a read error here, but the Accept() call succeeded so we must not return an error.
// We return the connection as is with a special error which handles this
@ -308,7 +308,7 @@ JpJcUNtrf1XK49IlpWW1Ds8seQsSg7/9BQ==
c := tls.Client(c0, clientCfg)
go func() {
c.Handshake()
_ = c.Handshake()
}()
s := tls.Server(c1, serverCfg)

View File

@ -201,8 +201,8 @@ func upgradeToURL(archiveName, binary string, url string) error {
if err != nil {
return err
}
if os.Rename(fname, binary); err != nil {
os.Rename(old, binary)
if err := os.Rename(fname, binary); err != nil {
_ = os.Rename(old, binary)
return err
}
return nil

View File

@ -59,8 +59,8 @@ func (v Simple) Archive(filePath string) error {
if err != nil {
if fs.IsNotExist(err) {
l.Debugln("creating versions dir .stversions")
v.fs.Mkdir(versionsDir, 0755)
v.fs.Hide(versionsDir)
_ = v.fs.Mkdir(versionsDir, 0755)
_ = v.fs.Hide(versionsDir)
} else {
return err
}

View File

@ -239,8 +239,8 @@ func (v *Staggered) Archive(filePath string) error {
if _, err := v.versionsFs.Stat("."); err != nil {
if fs.IsNotExist(err) {
l.Debugln("creating versions dir", v.versionsFs)
v.versionsFs.MkdirAll(".", 0755)
v.versionsFs.Hide(".")
_ = v.versionsFs.MkdirAll(".", 0755)
_ = v.versionsFs.Hide(".")
} else {
return err
}

View File

@ -60,7 +60,7 @@ func TestStaggeredVersioningVersionCount(t *testing.T) {
}
sort.Strings(delete)
os.MkdirAll("testdata/.stversions", 0755)
_ = os.MkdirAll("testdata/.stversions", 0755)
defer os.RemoveAll("testdata")
v := NewStaggered("", fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata"), map[string]string{"maxAge": strconv.Itoa(365 * 86400)}).(*Staggered)

View File

@ -65,7 +65,7 @@ func (t *Trashcan) Archive(filePath string) error {
if err := t.fs.MkdirAll(versionsDir, 0777); err != nil {
return err
}
t.fs.Hide(versionsDir)
_ = t.fs.Hide(versionsDir)
}
l.Debugln("archiving", filePath)
@ -84,7 +84,7 @@ func (t *Trashcan) Archive(filePath string) error {
// Set the mtime to the time the file was deleted. This is used by the
// cleanout routine. If this fails things won't work optimally but there's
// not much we can do about it so we ignore the error.
t.fs.Chtimes(archivedPath, time.Now(), time.Now())
_ = t.fs.Chtimes(archivedPath, time.Now(), time.Now())
return nil
}
@ -144,7 +144,7 @@ func (t *Trashcan) cleanoutArchive() error {
if info.ModTime().Before(cutoff) {
// The file is too old; remove it.
t.fs.Remove(path)
_ = t.fs.Remove(path)
} else {
// Keep this file, and remember it so we don't unnecessarily try
// to remove this directory.

View File

@ -42,7 +42,7 @@ func TestTrashcanCleanout(t *testing.T) {
oldTime := time.Now().Add(-8 * 24 * time.Hour)
for _, tc := range testcases {
os.MkdirAll(filepath.Dir(tc.file), 0777)
_ = os.MkdirAll(filepath.Dir(tc.file), 0777)
if err := ioutil.WriteFile(tc.file, []byte("data"), 0644); err != nil {
t.Fatal(err)
}

View File

@ -65,46 +65,71 @@ func TestAggregate(t *testing.T) {
folderCfg := defaultFolderCfg.Copy()
folderCfg.ID = "Aggregate"
ctx, _ := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
a := newAggregator(folderCfg, ctx)
// checks whether maxFilesPerDir events in one dir are kept as is
for i := 0; i < maxFilesPerDir; i++ {
a.newEvent(fs.Event{filepath.Join("parent", strconv.Itoa(i)), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: filepath.Join("parent", strconv.Itoa(i)),
Type: fs.NonRemove,
}, inProgress)
}
if l := len(getEventPaths(a.root, ".", a)); l != maxFilesPerDir {
t.Errorf("Unexpected number of events stored, got %v, expected %v", l, maxFilesPerDir)
}
// checks whether maxFilesPerDir+1 events in one dir are aggregated to parent dir
a.newEvent(fs.Event{filepath.Join("parent", "new"), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: filepath.Join("parent", "new"),
Type: fs.NonRemove,
}, inProgress)
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"parent"})
// checks that adding an event below "parent" does not change anything
a.newEvent(fs.Event{filepath.Join("parent", "extra"), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: filepath.Join("parent", "extra"),
Type: fs.NonRemove,
}, inProgress)
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"parent"})
// again test aggregation in "parent" but with event in subdirs
a = newAggregator(folderCfg, ctx)
for i := 0; i < maxFilesPerDir; i++ {
a.newEvent(fs.Event{filepath.Join("parent", strconv.Itoa(i)), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: filepath.Join("parent", strconv.Itoa(i)),
Type: fs.NonRemove,
}, inProgress)
}
a.newEvent(fs.Event{filepath.Join("parent", "sub", "new"), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: filepath.Join("parent", "sub", "new"),
Type: fs.NonRemove,
}, inProgress)
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"parent"})
// test aggregation in root
a = newAggregator(folderCfg, ctx)
for i := 0; i < maxFiles; i++ {
a.newEvent(fs.Event{strconv.Itoa(i), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: strconv.Itoa(i),
Type: fs.NonRemove,
}, inProgress)
}
if len(getEventPaths(a.root, ".", a)) != maxFiles {
t.Errorf("Unexpected number of events stored in root")
}
a.newEvent(fs.Event{filepath.Join("parent", "sub", "new"), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: filepath.Join("parent", "sub", "new"),
Type: fs.NonRemove,
}, inProgress)
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"."})
// checks that adding an event when "." is already stored is a noop
a.newEvent(fs.Event{"anythingelse", fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: "anythingelse",
Type: fs.NonRemove,
}, inProgress)
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"."})
a = newAggregator(folderCfg, ctx)
@ -115,7 +140,10 @@ func TestAggregate(t *testing.T) {
}
for _, dir := range dirs {
for i := 0; i < filesPerDir; i++ {
a.newEvent(fs.Event{filepath.Join(dir, strconv.Itoa(i)), fs.NonRemove}, inProgress)
a.newEvent(fs.Event{
Name: filepath.Join(dir, strconv.Itoa(i)),
Type: fs.NonRemove,
}, inProgress)
}
}
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"."})

View File

@ -42,7 +42,7 @@ func BenchmarkWeakHashAdler32(b *testing.B) {
hf := adler32.New()
for i := 0; i < b.N; i++ {
hf.Write(data)
_, _ = hf.Write(data)
}
_ = hf.Sum32()
@ -52,7 +52,7 @@ func BenchmarkWeakHashAdler32(b *testing.B) {
func BenchmarkWeakHashAdler32Roll(b *testing.B) {
data := make([]byte, size)
hf := adler32.New()
hf.Write(data)
_, _ = hf.Write(data)
b.ResetTimer()
@ -70,7 +70,7 @@ func BenchmarkWeakHashRabinKarp64(b *testing.B) {
hf := rabinkarp64.New()
for i := 0; i < b.N; i++ {
hf.Write(data)
_, _ = hf.Write(data)
}
_ = hf.Sum64()