X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Ftoss_test.go;h=000653d7be96cf60c8b0fd4a09961836bea880d8;hb=HEAD;hp=b17fc7ba6ec8e2f4acc2f81965dc6051472fc4bd;hpb=d386e5b28dc603ac4ffac10337f322e15bc92d80;p=nncp.git diff --git a/src/toss_test.go b/src/toss_test.go index b17fc7b..eb83309 100644 --- a/src/toss_test.go +++ b/src/toss_test.go @@ -22,7 +22,6 @@ import ( "crypto/rand" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strconv" @@ -56,7 +55,7 @@ func TestTossExec(t *testing.T) { for i, recipient := range recipients { recipients[i] = recipient % 8 } - spool, err := ioutil.TempDir("", "testtoss") + spool, err := os.MkdirTemp("", "testtoss") if err != nil { panic(err) } @@ -112,15 +111,13 @@ func TestTossExec(t *testing.T) { if len(dirFiles(rxPath)) == 0 { continue } - ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec-1, - false, false, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceExec - 1}) 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) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceExec}) if len(dirFiles(rxPath)) == 0 { return false } @@ -132,13 +129,12 @@ func TestTossExec(t *testing.T) { filepath.Join(spool, "mbox"), ), } - ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec, - false, false, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceExec}) if len(dirFiles(rxPath)) != 0 { return false } } - mbox, err := ioutil.ReadFile(filepath.Join(spool, "mbox")) + mbox, err := os.ReadFile(filepath.Join(spool, "mbox")) if err != nil { return false } @@ -174,7 +170,7 @@ func TestTossFile(t *testing.T) { } files[strconv.Itoa(i)] = data } - spool, err := ioutil.TempDir("", "testtoss") + spool, err := os.MkdirTemp("", "testtoss") if err != nil { panic(err) } @@ -200,7 +196,7 @@ func TestTossFile(t *testing.T) { hasher.Write(fileData) fileName := Base32Codec.EncodeToString(hasher.Sum(nil)) src := filepath.Join(spool, fileName) - if err := ioutil.WriteFile(src, fileData, os.FileMode(0600)); err != nil { + if err := os.WriteFile(src, fileData, os.FileMode(0600)); err != nil { panic(err) } if err := ctx.TxFile( @@ -219,14 +215,12 @@ 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) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceFile}) 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) { + if ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceFile}) { return false } if len(dirFiles(rxPath)) != 0 { @@ -236,7 +230,7 @@ func TestTossFile(t *testing.T) { hasher := MTHNew(0, 0) hasher.Write(fileData) fileName := Base32Codec.EncodeToString(hasher.Sum(nil)) - data, err := ioutil.ReadFile(filepath.Join(incomingPath, fileName)) + data, err := os.ReadFile(filepath.Join(incomingPath, fileName)) if err != nil { panic(err) } @@ -254,7 +248,7 @@ func TestTossFile(t *testing.T) { func TestTossFileSameName(t *testing.T) { f := func(filesRaw uint8) bool { files := int(filesRaw)%8 + 1 - spool, err := ioutil.TempDir("", "testtoss") + spool, err := os.MkdirTemp("", "testtoss") if err != nil { panic(err) } @@ -275,7 +269,7 @@ func TestTossFileSameName(t *testing.T) { } ctx.Neigh[*nodeOur.Id] = nodeOur.Their() srcPath := filepath.Join(spool, "junk") - if err = ioutil.WriteFile( + if err = os.WriteFile( srcPath, []byte("doesnotmatter"), os.FileMode(0600), @@ -302,8 +296,7 @@ func TestTossFileSameName(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.Neigh[*nodeOur.Id].Incoming = &incomingPath - ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile, - false, false, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceFile}) expected := make(map[string]struct{}) expected["samefile"] = struct{}{} for i := 0; i < files-1; i++ { @@ -315,10 +308,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) @@ -330,7 +320,7 @@ func TestTossFreq(t *testing.T) { if len(fileSizes) == 0 { return true } - spool, err := ioutil.TempDir("", "testtoss") + spool, err := os.MkdirTemp("", "testtoss") if err != nil { panic(err) } @@ -378,19 +368,17 @@ func TestTossFreq(t *testing.T) { txPath := filepath.Join(spool, ctx.Self.Id.String(), string(TTx)) 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) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceFreq}) 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) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceFreq}) if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 { return false } for fileName, fileData := range files { - if err := ioutil.WriteFile( + if err := os.WriteFile( filepath.Join(spool, fileName), fileData, os.FileMode(0600), @@ -398,8 +386,7 @@ func TestTossFreq(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFreq, - false, false, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: DefaultNiceFreq}) if len(dirFiles(txPath)) == 0 || len(dirFiles(rxPath)) != 0 { return false } @@ -448,7 +435,7 @@ func TestTossTrns(t *testing.T) { } datum[i] = data } - spool, err := ioutil.TempDir("", "testtoss") + spool, err := os.MkdirTemp("", "testtoss") if err != nil { panic(err) } @@ -494,7 +481,7 @@ func TestTossTrns(t *testing.T) { } hasher := MTHNew(0, 0) hasher.Write(dst.Bytes()) - if err := ioutil.WriteFile( + if err := os.WriteFile( filepath.Join(rxPath, Base32Codec.EncodeToString(hasher.Sum(nil))), dst.Bytes(), os.FileMode(0600), @@ -502,13 +489,12 @@ func TestTossTrns(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, TRx, 123, - false, false, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, &TossOpts{Nice: 123}) if len(dirFiles(rxPath)) != 0 { return false } for _, filename := range dirFiles(txPath) { - dataRead, err := ioutil.ReadFile(filepath.Join(txPath, filename)) + dataRead, err := os.ReadFile(filepath.Join(txPath, filename)) if err != nil { panic(err) } @@ -518,10 +504,7 @@ func TestTossTrns(t *testing.T) { } } } - if len(datum) > 0 { - return false - } - return true + return len(datum) == 0 } if err := quick.Check(f, nil); err != nil { t.Error(err)