diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 15:54:13 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 15:54:13 +0200 |
| commit | a9f4fbbc3a18585c127d1640cdb627ff56328294 (patch) | |
| tree | 508aa8f389ca659b8571cbd5b802212e086bb7c2 /internal/flamegraph/iordata_test.go | |
| parent | 58825fb53b900aedd3b161ff0e3b769a2cf188ab (diff) | |
fix: return serialize errors instead of panicking (task 383)
Diffstat (limited to 'internal/flamegraph/iordata_test.go')
| -rw-r--r-- | internal/flamegraph/iordata_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/flamegraph/iordata_test.go b/internal/flamegraph/iordata_test.go index 5e95976..f4855b0 100644 --- a/internal/flamegraph/iordata_test.go +++ b/internal/flamegraph/iordata_test.go @@ -2,6 +2,8 @@ package flamegraph import ( "bytes" + "errors" + "strings" "syscall" "testing" @@ -288,6 +290,24 @@ func TestDeserializeInvalidData(t *testing.T) { } } +func TestSerializeToFileHostnameErrorReturnsError(t *testing.T) { + origHostnameFn := hostnameFn + t.Cleanup(func() { hostnameFn = origHostnameFn }) + + hostnameFn = func() (string, error) { + return "", errors.New("hostname unavailable") + } + + iod := newIorData() + err := iod.serializeToFile("test") + if err == nil { + t.Fatal("Expected error when hostname lookup fails, got nil") + } + if !strings.Contains(err.Error(), "get hostname") { + t.Fatalf("Expected get hostname context, got %v", err) + } +} + func bothArraysHaveSameElements(a, b []string) bool { if len(a) != len(b) { return false |
