File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -25,11 +25,5 @@ func SocketActivated() bool {
2525 if err != nil || nfds == 0 {
2626 return false
2727 }
28-
29- // "github.com/coreos/go-systemd/v22/activation" will use and validate this variable's
30- // value. We're just providing a fast fail
31- if _ , found = os .LookupEnv ("LISTEN_FDNAMES" ); ! found {
32- return false
33- }
3428 return true
3529}
Original file line number Diff line number Diff line change 1+ package systemd
2+
3+ import (
4+ "fmt"
5+ "os"
6+ "testing"
7+
8+ "github.com/stretchr/testify/assert"
9+ )
10+
11+ func TestSocketActivated (t * testing.T ) {
12+ assert := assert .New (t )
13+
14+ assert .False (SocketActivated ())
15+
16+ // different pid
17+ assert .NoError (os .Setenv ("LISTEN_PID" , "1" ))
18+ assert .False (SocketActivated ())
19+
20+ // same pid no fds
21+ assert .NoError (os .Setenv ("LISTEN_PID" , fmt .Sprintf ("%d" , os .Getpid ())))
22+ assert .NoError (os .Setenv ("LISTEN_FDS" , "0" ))
23+ assert .False (SocketActivated ())
24+
25+ // same pid some fds
26+ assert .NoError (os .Setenv ("LISTEN_FDS" , "1" ))
27+ assert .True (SocketActivated ())
28+
29+ // FDNAME is ok too (but not required)
30+ assert .NoError (os .Setenv ("LISTEN_FDNAMES" , "/meshuggah/rocks" ))
31+ assert .True (SocketActivated ())
32+ }
You can’t perform that action at this time.
0 commit comments