]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/toss_test.go
Correctly show seconds
[nncp.git] / src / toss_test.go
index a96f78bd68afb6f28141ee361e37eaa1e802a4be..807c49a9ea55c8222a0fa9c7c3ada15faf03bbd1 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2021 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
@@ -26,10 +26,11 @@ import (
        "os"
        "path/filepath"
        "strconv"
+       "strings"
        "testing"
        "testing/quick"
 
-       "github.com/davecgh/go-xdr/xdr2"
+       xdr "github.com/davecgh/go-xdr/xdr2"
        "golang.org/x/crypto/blake2b"
 )
 
@@ -96,8 +97,10 @@ func TestTossExec(t *testing.T) {
                                replyNice,
                                handle,
                                []string{"arg0", "arg1"},
-                               []byte("BODY\n"),
+                               strings.NewReader("BODY\n"),
                                1<<15,
+                               false,
+                               false,
                        ); err != nil {
                                t.Error(err)
                                return false
@@ -188,7 +191,7 @@ func TestTossFile(t *testing.T) {
                incomingPath := filepath.Join(spool, "incoming")
                for _, fileData := range files {
                        checksum := blake2b.Sum256(fileData)
-                       fileName := ToBase32(checksum[:])
+                       fileName := Base32Codec.EncodeToString(checksum[:])
                        src := filepath.Join(spool, fileName)
                        if err := ioutil.WriteFile(src, fileData, os.FileMode(0600)); err != nil {
                                panic(err)
@@ -198,7 +201,9 @@ func TestTossFile(t *testing.T) {
                                DefaultNiceFile,
                                src,
                                fileName,
+                               MaxFileSize,
                                1<<15,
+                               MaxFileSize,
                        ); err != nil {
                                t.Error(err)
                                return false
@@ -217,7 +222,7 @@ func TestTossFile(t *testing.T) {
                }
                for _, fileData := range files {
                        checksum := blake2b.Sum256(fileData)
-                       fileName := ToBase32(checksum[:])
+                       fileName := Base32Codec.EncodeToString(checksum[:])
                        data, err := ioutil.ReadFile(filepath.Join(incomingPath, fileName))
                        if err != nil {
                                panic(err)
@@ -272,7 +277,9 @@ func TestTossFileSameName(t *testing.T) {
                                DefaultNiceFile,
                                srcPath,
                                "samefile",
+                               MaxFileSize,
                                1<<15,
+                               MaxFileSize,
                        ); err != nil {
                                t.Error(err)
                                return false
@@ -356,7 +363,7 @@ func TestTossFreq(t *testing.T) {
                if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 {
                        return false
                }
-               ctx.Neigh[*nodeOur.Id].Freq = &spool
+               ctx.Neigh[*nodeOur.Id].FreqPath = &spool
                ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false)
                if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 {
                        return false
@@ -376,7 +383,12 @@ func TestTossFreq(t *testing.T) {
                }
                for job := range ctx.Jobs(ctx.Self.Id, TTx) {
                        var buf bytes.Buffer
-                       _, _, err := PktEncRead(ctx.Self, ctx.Neigh, job.Fd, &buf)
+                       fd, err := os.Open(job.Path)
+                       if err != nil {
+                               t.Error(err)
+                               return false
+                       }
+                       _, _, err = PktEncRead(ctx.Self, ctx.Neigh, fd, &buf)
                        if err != nil {
                                t.Error(err)
                                return false
@@ -441,14 +453,13 @@ func TestTossTrns(t *testing.T) {
                os.MkdirAll(txPath, os.FileMode(0700))
                for _, data := range datum {
                        pktTrans := Pkt{
-                               Magic:   MagicNNCPPv2,
+                               Magic:   MagicNNCPPv3,
                                Type:    PktTypeTrns,
                                PathLen: blake2b.Size256,
-                               Path:    new([MaxPathSize]byte),
                        }
                        copy(pktTrans.Path[:], nodeOur.Id[:])
                        var dst bytes.Buffer
-                       if err := PktEncWrite(
+                       if _, err := PktEncWrite(
                                ctx.Self,
                                ctx.Neigh[*nodeOur.Id],
                                &pktTrans,
@@ -463,7 +474,7 @@ func TestTossTrns(t *testing.T) {
                        }
                        checksum := blake2b.Sum256(dst.Bytes())
                        if err := ioutil.WriteFile(
-                               filepath.Join(rxPath, ToBase32(checksum[:])),
+                               filepath.Join(rxPath, Base32Codec.EncodeToString(checksum[:])),
                                dst.Bytes(),
                                os.FileMode(0600),
                        ); err != nil {