]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/toss_test.go
Merge branch 'develop'
[nncp.git] / src / cypherpunks.ru / nncp / toss_test.go
index 037c777321a62752541cd3d46b2bfc3eb31efd5c..fb1a29fc829d088db88208445fde2a7419ff4ef8 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2019 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
@@ -51,8 +51,9 @@ func dirFiles(path string) []string {
        return names
 }
 
-func TestTossEmail(t *testing.T) {
-       f := func(recipients [16]uint8) bool {
+func TestTossExec(t *testing.T) {
+       f := func(replyNice uint8, handleRaw uint32, recipients [16]uint8) bool {
+               handle := strconv.Itoa(int(handleRaw))
                for i, recipient := range recipients {
                        recipients[i] = recipient % 8
                }
@@ -90,11 +91,13 @@ func TestTossEmail(t *testing.T) {
                        ctx.Neigh[*our.Id] = our.Their()
                }
                for _, recipient := range recipients {
-                       if err := ctx.TxMail(
+                       if err := ctx.TxExec(
                                ctx.Neigh[*privates[recipient].Id],
-                               DefaultNiceMail,
-                               "recipient",
-                               []byte{123},
+                               DefaultNiceExec,
+                               replyNice,
+                               handle,
+                               []string{"arg0", "arg1"},
+                               []byte("BODY\n"),
                                1<<15,
                        ); err != nil {
                                t.Error(err)
@@ -108,20 +111,25 @@ func TestTossEmail(t *testing.T) {
                        if len(dirFiles(rxPath)) == 0 {
                                continue
                        }
-                       ctx.Toss(ctx.Self.Id, DefaultNiceMail-1, false, false, false, false, false, false)
+                       ctx.Toss(ctx.Self.Id, DefaultNiceExec-1, false, false, false, false, false, false)
                        if len(dirFiles(rxPath)) == 0 {
                                return false
                        }
-                       ctx.Neigh[*nodeOur.Id].Sendmail = []string{"/bin/sh", "-c", "false"}
-                       ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false, false, false, false, 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, DefaultNiceExec, false, false, false, false, false, false)
                        if len(dirFiles(rxPath)) == 0 {
                                return false
                        }
-                       ctx.Neigh[*nodeOur.Id].Sendmail = []string{
+                       ctx.Neigh[*nodeOur.Id].Exec[handle] = []string{
                                "/bin/sh", "-c",
-                               fmt.Sprintf("cat >> %s", filepath.Join(spool, "mbox")),
+                               fmt.Sprintf(
+                                       "echo $NNCP_NICE $0 $1 >> %s ; cat >> %s",
+                                       filepath.Join(spool, "mbox"),
+                                       filepath.Join(spool, "mbox"),
+                               ),
                        }
-                       ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false, false, false, false, false)
+                       ctx.Toss(ctx.Self.Id, DefaultNiceExec, false, false, false, false, false, false)
                        if len(dirFiles(rxPath)) != 0 {
                                return false
                        }
@@ -132,7 +140,11 @@ func TestTossEmail(t *testing.T) {
                }
                expected := make([]byte, 0, 16)
                for i := 0; i < 16; i++ {
-                       expected = append(expected, 123)
+                       expected = append(
+                               expected,
+                               []byte(fmt.Sprintf("%d arg0 arg1\n", replyNice))...,
+                       )
+                       expected = append(expected, []byte("BODY\n")...)
                }
                return bytes.Compare(mbox, expected) == 0
        }
@@ -471,7 +483,6 @@ func TestTossTrns(t *testing.T) {
                        for k, data := range datum {
                                if bytes.Compare(dataRead, data) == 0 {
                                        delete(datum, k)
-                                       break
                                }
                        }
                }