-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathdbrecovery_test.go
More file actions
47 lines (36 loc) · 979 Bytes
/
Copy pathdbrecovery_test.go
File metadata and controls
47 lines (36 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:build !windows
package main
import (
"os"
"path/filepath"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCleanStalePIDFile(t *testing.T) {
t.Parallel()
t.Run("NoPIDFile", func(t *testing.T) {
t.Parallel()
cleanStalePIDFile(t.TempDir())
})
t.Run("StalePID", func(t *testing.T) {
t.Parallel()
dir := t.TempDir()
pidFile := filepath.Join(dir, "postmaster.pid")
require.NoError(t, os.WriteFile(pidFile, []byte("999999999\n"), 0o600))
cleanStalePIDFile(dir)
_, err := os.Stat(pidFile)
assert.True(t, os.IsNotExist(err))
})
t.Run("RunningPID", func(t *testing.T) {
t.Parallel()
dir := t.TempDir()
pidFile := filepath.Join(dir, "postmaster.pid")
require.NoError(t, os.WriteFile(pidFile,
[]byte(strconv.Itoa(os.Getpid())+"\n"), 0o600))
cleanStalePIDFile(dir)
_, err := os.Stat(pidFile)
assert.NoError(t, err, "should not remove PID file for running process")
})
}