mohamedawnallah commented on code in PR #37673: URL: https://github.com/apache/beam/pull/37673#discussion_r2880620054
########## sdks/go/pkg/beam/runners/dot/dot_test.go: ########## @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package dot + +import ( + "context" + "os" + "strings" + "testing" + + "github.com/apache/beam/sdks/v2/go/pkg/beam" + "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert" +) + +func TestDotRunner_GeneratesDeterministicOutput(t *testing.T) { + ctx := context.Background() + + // Create temporary DOT file + tmpFile, err := os.CreateTemp("", "dot_test_*.dot") + if err != nil { + t.Fatalf("failed to create temp file: %v", err) + } + defer os.Remove(tmpFile.Name()) + + // Set flag manually + *dotFile = tmpFile.Name() + + // Build simple pipeline + p, s := beam.NewPipelineWithRoot() + + col := beam.Create(s, "a", "b", "c") + passert.Count(s, col, "", 3) + + // Run with dot runner + _, err = Execute(ctx, p) + if err != nil { + t.Fatalf("Execute failed: %v", err) + } + + // Read generated file + data, err := os.ReadFile(tmpFile.Name()) + if err != nil { + t.Fatalf("failed to read dot file: %v", err) + } + + content := string(data) + + if !strings.HasPrefix(content, "digraph G {") { + t.Fatalf("dot output missing header") + } + + if !strings.Contains(content, "->") { + t.Fatalf("dot output contains no edges") + } Review Comment: Can it be something along those lines for more comprehensive checks? ```suggestion // Validate the output is parseable as a basic DOT digraph. // Checks: header, footer, and that every non-structural line is a valid edge. lines := strings.Split(strings.TrimSpace(content), "\n") if lines[0] != "digraph G {" { t.Fatalf("missing digraph header, got: %s", lines[0]) } if lines[len(lines)-1] != "}" { t.Fatalf("missing closing brace, got: %s", lines[len(lines)-1]) } for _, line := range lines[1 : len(lines)-1] { line = strings.TrimSpace(line) if line == "" { continue } if !strings.Contains(line, "->") || !strings.HasSuffix(line, ";") { t.Fatalf("invalid DOT edge line: %s", line) } } ``` -- 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]
