jrmccluskey commented on a change in pull request #16937:
URL: https://github.com/apache/beam/pull/16937#discussion_r814193793
##########
File path: sdks/go/pkg/beam/io/textio/textio_test.go
##########
@@ -40,3 +46,68 @@ func TestRead(t *testing.T) {
}
}
+
+func TestRead(t *testing.T) {
+ f := "../../../../data/textio_test.txt"
+ p, s := beam.NewPipelineWithRoot()
+ lines := Read(s, f)
+ passert.Count(s, lines, "NumLines", 1)
+
+ if _, err := beam.Run(context.Background(), "direct", p); err != nil {
+ t.Fatalf("Failed to execute job: %v", err)
+ }
+}
+
+func TestReadAll(t *testing.T) {
+ f := "../../../../data/textio_test.txt"
+ p, s := beam.NewPipelineWithRoot()
+ files := beam.Create(s, f)
+ lines := ReadAll(s, files)
+ passert.Count(s, lines, "NumLines", 1)
+
+ if _, err := beam.Run(context.Background(), "direct", p); err != nil {
+ t.Fatalf("Failed to execute job: %v", err)
+ }
+}
+
+func TestWrite(t *testing.T) {
+ f := "../../../../data/textio_test.txt"
+ out := "text.txt"
+ p, s := beam.NewPipelineWithRoot()
+ lines := Read(s, f)
+ Write(s, out, lines)
+
+ if _, err := beam.Run(context.Background(), "direct", p); err != nil {
+ t.Fatalf("Failed to execute job: %v", err)
+ }
+
+ if _, err := os.Stat(out); errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("Failed to write %v", out)
+ }
+ defer os.Remove(out)
+
+ outfileContents, _ := os.ReadFile(out)
+ infileContents, _ := os.ReadFile(f)
+ if got, want := string(outfileContents), string(infileContents); got !=
want {
+ t.Fatalf("Write() wrote the wrong contents. Got: %v Want: %v",
got, want)
+ }
+}
+
+func TestImmediate(t *testing.T) {
+ f := "test2.txt"
+ if err := os.WriteFile(f, []byte("hello\ngo\n"), 0644); err != nil {
Review comment:
Nit: consider using os.CreateTemp (https://pkg.go.dev/os#CreateTemp)
instead of os.WriteFile for testing purposes.
##########
File path: sdks/go/pkg/beam/io/textio/textio_test.go
##########
@@ -40,3 +46,68 @@ func TestRead(t *testing.T) {
}
}
+
+func TestRead(t *testing.T) {
+ f := "../../../../data/textio_test.txt"
+ p, s := beam.NewPipelineWithRoot()
+ lines := Read(s, f)
+ passert.Count(s, lines, "NumLines", 1)
+
+ if _, err := beam.Run(context.Background(), "direct", p); err != nil {
+ t.Fatalf("Failed to execute job: %v", err)
+ }
+}
+
+func TestReadAll(t *testing.T) {
+ f := "../../../../data/textio_test.txt"
+ p, s := beam.NewPipelineWithRoot()
+ files := beam.Create(s, f)
+ lines := ReadAll(s, files)
+ passert.Count(s, lines, "NumLines", 1)
+
+ if _, err := beam.Run(context.Background(), "direct", p); err != nil {
+ t.Fatalf("Failed to execute job: %v", err)
+ }
+}
+
+func TestWrite(t *testing.T) {
+ f := "../../../../data/textio_test.txt"
Review comment:
Nit: Is there be a downside to storing this relative path as a constant?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]