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

Function TestDebugTemplate

tailnet/coordinator_internal_test.go:21–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19var UpdateGoldenFiles = flag.Bool("update", false, "update .golden files")
20
21func TestDebugTemplate(t *testing.T) {
22 t.Parallel()
23 if runtime.GOOS == "windows" {
24 t.Skip("newlines screw up golden files on windows")
25 }
26 p1 := uuid.MustParse("01000000-2222-2222-2222-222222222222")
27 p2 := uuid.MustParse("02000000-2222-2222-2222-222222222222")
28 in := HTMLDebug{
29 Peers: []HTMLPeer{
30 {
31 Name: "Peer 1",
32 ID: p1,
33 LastWriteAge: 5 * time.Second,
34 Node: `id:1 preferred_derp:999 endpoints:"192.168.0.49:4449"`,
35 CreatedAge: 87 * time.Second,
36 Overwrites: 0,
37 },
38 {
39 Name: "Peer 2",
40 ID: p2,
41 LastWriteAge: 7 * time.Second,
42 Node: `id:2 preferred_derp:999 endpoints:"192.168.0.33:4449"`,
43 CreatedAge: time.Hour,
44 Overwrites: 2,
45 },
46 },
47 Tunnels: []HTMLTunnel{
48 {
49 Src: p1,
50 Dst: p2,
51 },
52 },
53 }
54 buf := new(bytes.Buffer)
55 err := debugTempl.Execute(buf, in)
56 require.NoError(t, err)
57 actual := buf.Bytes()
58
59 goldenPath := filepath.Join("testdata", "debug.golden.html")
60 if *UpdateGoldenFiles {
61 t.Logf("update golden file %s", goldenPath)
62 err := os.WriteFile(goldenPath, actual, 0o600)
63 require.NoError(t, err, "update golden file")
64 }
65
66 expected, err := os.ReadFile(goldenPath)
67 require.NoError(t, err, "read golden file, run \"make gen/golden-files\" and commit the changes")
68
69 require.Equal(
70 t, string(expected), string(actual),
71 "golden file mismatch: %s, run \"make gen/golden-files\", verify and commit the changes",
72 goldenPath,
73 )
74}

Callers

nothing calls this directly

Calls 7

SkipMethod · 0.80
ExecuteMethod · 0.65
LogfMethod · 0.65
WriteFileMethod · 0.65
ReadFileMethod · 0.65
BytesMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected