mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 09:40:12 +00:00
31 lines
653 B
Go
31 lines
653 B
Go
//go:build linux
|
|
|
|
package process
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestProcessHasOpenPathTogglesWithDescriptorLifecycle(t *testing.T) {
|
|
// Given
|
|
path := filepath.Join(t.TempDir(), "dashboard.sqlite-journal")
|
|
require.NoError(t, os.WriteFile(path, []byte("journal"), 0o600))
|
|
file, err := os.Open(path)
|
|
require.NoError(t, err)
|
|
|
|
// When
|
|
held, err := ProcessHasOpenPath(os.Getpid(), path)
|
|
require.NoError(t, err)
|
|
require.NoError(t, file.Close())
|
|
released, err := ProcessHasOpenPath(os.Getpid(), path)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
require.True(t, held)
|
|
require.False(t, released)
|
|
}
|