github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/systemd/activation_test.go (about) 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 }