X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Ftoss_test.go;h=966b2b84ae4a0914d42ad2681e64dbca6b4e4bc1;hb=269c2d8ced7a5f0e3d887cc9a4840f09101058b5;hp=deb70f13d04553e1688daecd80e08206b510e1ea;hpb=ab7c7eca0e53661f0ba904c2a6ba752990bea367;p=nncp.git diff --git a/src/toss_test.go b/src/toss_test.go index deb70f1..966b2b8 100644 --- a/src/toss_test.go +++ b/src/toss_test.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2023 Sergey Matveev 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 @@ -97,8 +97,7 @@ func TestTossExec(t *testing.T) { handle, []string{"arg0", "arg1"}, strings.NewReader("BODY\n"), - 1<<15, - false, + 1<<15, MaxFileSize, false, nil, ); err != nil { @@ -114,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 } @@ -134,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 } @@ -151,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) @@ -165,6 +164,10 @@ func TestTossFile(t *testing.T) { } files := make(map[string][]byte) for i, fileSize := range fileSizes { + if fileSize == 0 { + // to prevent chunked send + fileSize++ + } data := make([]byte, fileSize) if _, err := io.ReadFull(rand.Reader, data); err != nil { panic(err) @@ -217,13 +220,15 @@ 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 - ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile, - false, false, false, false, false, false, false) + if ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile, + false, false, false, false, false, false, false, false) { + return false + } if len(dirFiles(rxPath)) != 0 { return false } @@ -235,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 } } @@ -298,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++ { @@ -310,10 +315,7 @@ func TestTossFileSameName(t *testing.T) { } delete(expected, filename) } - if len(expected) != 0 { - return false - } - return true + return len(expected) == 0 } if err := quick.Check(f, nil); err != nil { t.Error(err) @@ -347,6 +349,10 @@ func TestTossFreq(t *testing.T) { ctx.Neigh[*nodeOur.Id] = nodeOur.Their() files := make(map[string][]byte) for i, fileSize := range fileSizes { + if fileSize == 0 { + // to prevent chunked send + fileSize++ + } fileData := make([]byte, fileSize) if _, err := io.ReadFull(rand.Reader, fileData); err != nil { panic(err) @@ -370,13 +376,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 } @@ -390,7 +396,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 } @@ -414,8 +420,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 } } @@ -472,13 +477,12 @@ func TestTossTrns(t *testing.T) { } copy(pktTrans.Path[:], nodeOur.Id[:]) var dst bytes.Buffer - if _, err := PktEncWrite( + if _, _, err := PktEncWrite( ctx.Self, ctx.Neigh[*nodeOur.Id], &pktTrans, 123, - int64(len(data)), - 0, + 0, MaxFileSize, 1, bytes.NewReader(data), &dst, ); err != nil { @@ -496,7 +500,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 } @@ -506,15 +510,12 @@ 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) } } } - if len(datum) > 0 { - return false - } - return true + return len(datum) == 0 } if err := quick.Check(f, nil); err != nil { t.Error(err)