lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit 813e7119de7a4a2864c487c87b59eec939c366da
parent 984c4e8ee06560d78b52e3f1e58a3c4b735ccf57
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 20 Jan 2024 16:55:42 +0900

move some tests from TestFileWrite to FuzzFileWrite

Diffstat:
Mclient/file_test.go | 30++++--------------------------
1 file changed, 4 insertions(+), 26 deletions(-)

diff --git a/client/file_test.go b/client/file_test.go @@ -166,15 +166,6 @@ func TestFileRead(t *testing.T) { // It writes some bytes to a testFile using File.Write and checks if // the underlying content of testFile is changed correctly. func TestFileWrite(t *testing.T) { - tests := []struct{ - b []byte - }{ - {[]byte("")}, - {[]byte("fuga")}, - {[]byte("fugafuga")}, - {[]byte("fugafugafuga")}, - {make([]byte, 9000)}, - } ctx, cancel := context.WithCancel(context.Background()) cfs, err := mount(ctx, testfs) if err != nil { @@ -187,22 +178,6 @@ func TestFileWrite(t *testing.T) { } orig := bytes.Clone(tf.content) defer func() { tf.content = bytes.Clone(orig) }() - for i, test := range tests { - cf, err := cfs.OpenFile("dir/file", lib9p.O_RDWR) - if err != nil { - t.Fatal(err) - } - _, err = cf.(lib9p.WriterFile).Write(test.b) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(tf.content[:len(test.b)], test.b) { - t.Errorf("%d: not written propperly: want: %v, got: %v", - i, string(test.b), string(tf.content[:len(test.b)])) - } - cf.Close() - tf.content = bytes.Clone(orig) - } // consecutive writes to the same file without closing it. ctnt0 := []byte("hogehoge") ctnt1 := []byte("fugafuga") @@ -226,6 +201,10 @@ func TestFileWrite(t *testing.T) { } func FuzzFileWrite(f *testing.F) { + for _, seed := range []string{"", "fuga", "fugafuga", "fugafugafuga"} { + f.Add([]byte(seed)) + } + f.Add(make([]byte, 9000)) ctx, cancel := context.WithCancel(context.Background()) cfs, err := mount(ctx, testfs) if err != nil { @@ -238,7 +217,6 @@ func FuzzFileWrite(f *testing.F) { } orig := bytes.Clone(tf.content) f.Fuzz(func(t *testing.T, in []byte) { - t.Log(in) defer func() { tf.content = bytes.Clone(orig) }() cf, err := cfs.OpenFile("dir/file", lib9p.O_RDWR) if err != nil {