aboutsummaryrefslogtreecommitdiff
path: root/pkg/systemd/activation_test.go
blob: d2553777bd6db696182fb43c86e664c5530208aa (plain)
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
package systemd

import (
	"fmt"
	"os"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSocketActivated(t *testing.T) {
	assert := assert.New(t)

	assert.False(SocketActivated())

	// different pid
	assert.NoError(os.Setenv("LISTEN_PID", "1"))
	assert.False(SocketActivated())

	// same pid no fds
	assert.NoError(os.Setenv("LISTEN_PID", fmt.Sprintf("%d", os.Getpid())))
	assert.NoError(os.Setenv("LISTEN_FDS", "0"))
	assert.False(SocketActivated())

	// same pid some fds
	assert.NoError(os.Setenv("LISTEN_FDS", "1"))
	assert.True(SocketActivated())

	// FDNAME is ok too (but not required)
	assert.NoError(os.Setenv("LISTEN_FDNAMES", "/meshuggah/rocks"))
	assert.True(SocketActivated())
}