]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/toss_test.go
Use bytes.Equal() instead of bytes.Compare()==0
[nncp.git] / src / toss_test.go
index 6cb68ebbc3f4fb0531f7910a451da27690425031..b17fc7ba6ec8e2f4acc2f81965dc6051472fc4bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2023 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -113,14 +113,14 @@ func TestTossExec(t *testing.T) {
                                continue
                        }
                        ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec-1,
-                               false, false, false, false, false, false, false)
+                               false, false, false, false, false, false, false, false)
                        if len(dirFiles(rxPath)) == 0 {
                                return false
                        }
                        ctx.Neigh[*nodeOur.Id].Exec = make(map[string][]string)
                        ctx.Neigh[*nodeOur.Id].Exec[handle] = []string{"/bin/sh", "-c", "false"}
                        ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec,
-                               false, false, false, false, false, false, false)
+                               false, false, false, false, false, false, false, false)
                        if len(dirFiles(rxPath)) == 0 {
                                return false
                        }
@@ -133,7 +133,7 @@ func TestTossExec(t *testing.T) {
                                ),
                        }
                        ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec,
-                               false, false, false, false, false, false, false)
+                               false, false, false, false, false, false, false, false)
                        if len(dirFiles(rxPath)) != 0 {
                                return false
                        }
@@ -150,7 +150,7 @@ func TestTossExec(t *testing.T) {
                        )
                        expected = append(expected, []byte("BODY\n")...)
                }
-               return bytes.Compare(mbox, expected) == 0
+               return bytes.Equal(mbox, expected)
        }
        if err := quick.Check(f, nil); err != nil {
                t.Error(err)
@@ -220,13 +220,13 @@ func TestTossFile(t *testing.T) {
                rxPath := filepath.Join(spool, ctx.Self.Id.String(), string(TRx))
                os.Rename(filepath.Join(spool, ctx.Self.Id.String(), string(TTx)), rxPath)
                ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile,
-                       false, false, false, false, false, false, false)
+                       false, false, false, false, false, false, false, false)
                if len(dirFiles(rxPath)) == 0 {
                        return false
                }
                ctx.Neigh[*nodeOur.Id].Incoming = &incomingPath
                if ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile,
-                       false, false, false, false, false, false, false) {
+                       false, false, false, false, false, false, false, false) {
                        return false
                }
                if len(dirFiles(rxPath)) != 0 {
@@ -240,7 +240,7 @@ func TestTossFile(t *testing.T) {
                        if err != nil {
                                panic(err)
                        }
-                       if bytes.Compare(data, fileData) != 0 {
+                       if !bytes.Equal(data, fileData) {
                                return false
                        }
                }
@@ -303,7 +303,7 @@ func TestTossFileSameName(t *testing.T) {
                os.Rename(filepath.Join(spool, ctx.Self.Id.String(), string(TTx)), rxPath)
                ctx.Neigh[*nodeOur.Id].Incoming = &incomingPath
                ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile,
-                       false, false, false, false, false, false, false)
+                       false, false, false, false, false, false, false, false)
                expected := make(map[string]struct{})
                expected["samefile"] = struct{}{}
                for i := 0; i < files-1; i++ {
@@ -379,13 +379,13 @@ func TestTossFreq(t *testing.T) {
                os.Rename(txPath, rxPath)
                os.MkdirAll(txPath, os.FileMode(0700))
                ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFreq,
-                       false, false, false, false, false, false, false)
+                       false, false, false, false, false, false, false, false)
                if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 {
                        return false
                }
                ctx.Neigh[*nodeOur.Id].FreqPath = &spool
                ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFreq,
-                       false, false, false, false, false, false, false)
+                       false, false, false, false, false, false, false, false)
                if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 {
                        return false
                }
@@ -399,7 +399,7 @@ func TestTossFreq(t *testing.T) {
                        }
                }
                ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFreq,
-                       false, false, false, false, false, false, false)
+                       false, false, false, false, false, false, false, false)
                if len(dirFiles(txPath)) == 0 || len(dirFiles(rxPath)) != 0 {
                        return false
                }
@@ -423,8 +423,7 @@ func TestTossFreq(t *testing.T) {
                        if pkt.Nice != replyNice {
                                return false
                        }
-                       dst := string(pkt.Path[:int(pkt.PathLen)])
-                       if bytes.Compare(buf.Bytes(), files[dst]) != 0 {
+                       if !bytes.Equal(buf.Bytes(), files[string(pkt.Path[:int(pkt.PathLen)])]) {
                                return false
                        }
                }
@@ -504,7 +503,7 @@ func TestTossTrns(t *testing.T) {
                        }
                }
                ctx.Toss(ctx.Self.Id, TRx, 123,
-                       false, false, false, false, false, false, false)
+                       false, false, false, false, false, false, false, false)
                if len(dirFiles(rxPath)) != 0 {
                        return false
                }
@@ -514,7 +513,7 @@ func TestTossTrns(t *testing.T) {
                                panic(err)
                        }
                        for k, data := range datum {
-                               if bytes.Compare(dataRead, data) == 0 {
+                               if bytes.Equal(dataRead, data) {
                                        delete(datum, k)
                                }
                        }