]> Cypherpunks.ru repositories - gostls13.git/commitdiff
embed/internal/embedtest: test openFile.ReadAt with non-zero offset
authorTobias Klauser <tklauser@distanz.ch>
Thu, 13 Apr 2023 15:57:42 +0000 (17:57 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 14 Apr 2023 20:10:16 +0000 (20:10 +0000)
Also fix log messages to report expected values in the standard "got foo,
want bar" format.

Change-Id: I6a9fd4abe1f86c2651c72c2bf7ac4588028e5923
Reviewed-on: https://go-review.googlesource.com/c/go/+/484715
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

src/embed/internal/embedtest/embed_test.go

index c925942191f9aa6143f3b9b9ac464929a61066d2..a6e673a7bc2b62560f28067fba44691b38f66958 100644 (file)
@@ -184,7 +184,7 @@ func TestOffset(t *testing.T) {
                t.Fatal("Open:", err)
        }
 
-       const want = "hello, world\n"
+       want := "hello, world\n"
 
        // Read the entire file.
        got := make([]byte, len(want))
@@ -227,9 +227,24 @@ func TestOffset(t *testing.T) {
                t.Fatal("ReadAt:", err)
        }
        if n != len(want) {
-               t.Fatal("ReadAt:", n)
+               t.Fatalf("ReadAt: got %d bytes, want %d bytes", n, len(want))
        }
        if string(got) != want {
-               t.Fatalf("ReadAt: %q", got)
+               t.Fatalf("ReadAt: got %q, want %q", got, want)
+       }
+
+       // Use ReadAt with non-zero offset.
+       off = int64(7)
+       want = want[off:]
+       got = make([]byte, len(want))
+       n, err = at.ReadAt(got, off)
+       if err != nil {
+               t.Fatal("ReadAt:", err)
+       }
+       if n != len(want) {
+               t.Fatalf("ReadAt: got %d bytes, want %d bytes", n, len(want))
+       }
+       if string(got) != want {
+               t.Fatalf("ReadAt: got %q, want %q", got, want)
        }
 }