MCPcopy Index your code
hub / github.com/coder/coder / assertDOTGraph

Function assertDOTGraph

agent/unit/graph_test.go:63–86  ·  view source on GitHub ↗

assertDOTGraph requires that the graph's DOT representation matches the golden file

(t *testing.T, graph *testGraph, goldenName string)

Source from the content-addressed store, hash-verified

61
62// assertDOTGraph requires that the graph's DOT representation matches the golden file
63func assertDOTGraph(t *testing.T, graph *testGraph, goldenName string) {
64 t.Helper()
65
66 dot, err := graph.ToDOT(goldenName)
67 require.NoError(t, err)
68
69 goldenFile := filepath.Join("testdata", goldenName+".golden")
70 if *UpdateGoldenFiles {
71 t.Logf("update golden file for: %q: %s", goldenName, goldenFile)
72 err := os.MkdirAll(filepath.Dir(goldenFile), 0o755)
73 require.NoError(t, err, "want no error creating golden file directory")
74 err = os.WriteFile(goldenFile, []byte(dot), 0o600)
75 require.NoError(t, err, "update golden file")
76 }
77
78 expected, err := os.ReadFile(goldenFile)
79 require.NoError(t, err, "read golden file, run \"make gen/golden-files\" and commit the changes")
80
81 // Normalize line endings for cross-platform compatibility
82 expected = normalizeLineEndings(expected)
83 normalizedDot := normalizeLineEndings([]byte(dot))
84
85 assert.Empty(t, cmp.Diff(string(expected), string(normalizedDot)), "golden file mismatch (-want +got): %s, run \"make gen/golden-files\", verify and commit the changes", goldenFile)
86}
87
88// normalizeLineEndings ensures that all line endings are normalized to \n.
89// Required for Windows compatibility.

Callers 1

TestGraphFunction · 0.85

Calls 8

ToDOTMethod · 0.80
MkdirAllMethod · 0.80
normalizeLineEndingsFunction · 0.70
HelperMethod · 0.65
LogfMethod · 0.65
WriteFileMethod · 0.65
ReadFileMethod · 0.65
EmptyMethod · 0.45

Tested by

no test coverage detected