Skip to content

Commit

Permalink
feat: improve cpu profile test
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Oct 21, 2024
1 parent 7a717ec commit 500c356
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,31 @@ func TestCpuProfile(t *testing.T) {
as.NoError(os.Chdir(cwd))
})

_, _, err = treefmt(t, "-C", tempDir, "--allow-missing-formatter", "--cpu-profile", "cpu.pprof")
as.NoError(err)
as.FileExists(filepath.Join(tempDir, "cpu.pprof"))
_, err = os.Stat(filepath.Join(tempDir, "cpu.pprof"))
as.NoError(err)
// change to temp dir
as.NoError(os.Chdir(tempDir), "failed to change to temp dir")
// allow missing formatter
t.Setenv("TREEFMT_ALLOW_MISSING_FORMATTER", "true")

treefmt2(
t, args("--cpu-profile", "cpu.pprof"),
func(_ []byte, _ *stats.Stats, err error) {
// check the profile exists
as.NoError(err)
as.FileExists(filepath.Join(tempDir, "cpu.pprof"))
},
)

// test with env
t.Setenv("TREEFMT_CPU_PROFILE", "env.pprof")
_, _, err = treefmt(t, "-C", tempDir, "--allow-missing-formatter")
as.NoError(err)
as.FileExists(filepath.Join(tempDir, "env.pprof"))
_, err = os.Stat(filepath.Join(tempDir, "env.pprof"))
as.NoError(err)

treefmt2(
t, args(),
func(_ []byte, _ *stats.Stats, err error) {
// check the profile exists
as.NoError(err)
as.FileExists(filepath.Join(tempDir, "env.pprof"))
},
)
}

func TestAllowMissingFormatter(t *testing.T) {
Expand Down

0 comments on commit 500c356

Please sign in to comment.