예제 #1
0
func TestInstall(t *testing.T) {
	env := test_env.New()
	sys := newExporter(env, systemdConfig)

	sys.Install("some-app", procfile.App{Services: []procfile.Service{defaultService}})

	assert.True(t, env.FileExists(appUnitFilePath), "no app unit file")

	assert.True(t, env.FileExists(helperFilePath), "no helper file")
	helperFileData := env.ReadFile(helperFilePath)
	assert.Contains(t, helperFileData, "run-some-service")

	assert.True(t, env.FileExists(serviceUnitFilePath), "no service unit file")
	unitFileData := env.ReadFile(serviceUnitFilePath)
	assert.Contains(t, unitFileData, "PartOf=some-app.service")
	assert.Contains(t, unitFileData, "TimeoutStopSec=12345")
	assert.Contains(t, unitFileData, "StartLimitInterval=10")
	assert.Contains(t, unitFileData, "StartLimitBurst=100")
	assert.Contains(t, unitFileData, "WorkingDirectory=/projects/some-service")
	assert.Contains(t, unitFileData, "User=run_user")
	assert.Contains(t, unitFileData, "Group=run_group")
	assert.Contains(t, unitFileData, "env_var=env_val")
	assert.Contains(t, unitFileData, "env_var2=env_val2")
	assert.Contains(t, unitFileData, ">> /var/log/some-app/some-service.log")

	assert.Contains(t, env.ExecutedCommands, "systemctl enable some-app.service")
}
예제 #2
0
func TestInstallMultiCount(t *testing.T) {
	env := test_env.New()
	sys := newExporter(env, systemdConfig)

	multiService := defaultService
	multiService.Options.Count = 2

	sys.Install("some-app", procfile.App{Services: []procfile.Service{multiService}})

	assert.True(t, env.FileExists("/units/some-app_some-service1.service"), "no service unit file")
	assert.True(t, env.FileExists("/units/some-app_some-service2.service"), "no service unit file")
}
예제 #3
0
func TestUnInstall(t *testing.T) {
	env := test_env.New()
	sys := newExporter(env, systemdConfig)

	sys.Install("some-app", procfile.App{Services: []procfile.Service{defaultService}})

	env.WriteFile("/helpers/file_to_keep.sh", "data")
	env.WriteFile("/units/file_to_keep.service", "data")

	sys.Uninstall("some-app")

	assert.False(t, env.FileExists(appUnitFilePath), "app unit file exists")
	assert.False(t, env.FileExists(helperFilePath), "helper file exists")
	assert.False(t, env.FileExists(serviceUnitFilePath), "service unit file exists")

	assert.True(t, env.FileExists("/helpers/file_to_keep.sh"), "wrong file deleted")
	assert.True(t, env.FileExists("/units/file_to_keep.service"), "wrong file deleted")

	assert.Contains(t, env.ExecutedCommands, "systemctl disable some-app.service")
}
예제 #4
0
func TestInstall(t *testing.T) {
	env := test_env.New()
	sys := newExporter(env, systemdConfig)

	sys.Install("some-app", procfile.App{Services: []procfile.Service{defaultService}})

	assert.True(t, env.FileExists(appUnitFilePath), "no app unit file")

	assert.True(t, env.FileExists(helperFilePath), "no helper file")
	helperFileData := env.ReadFile(helperFilePath)
	assert.Contains(t, helperFileData, "run-some-service")
	assert.Contains(t, helperFileData, "cd /projects/some-service")
	assert.Contains(t, helperFileData, "env_var=env_val")
	assert.Contains(t, helperFileData, "env_var2=env_val2")

	assert.True(t, env.FileExists(serviceUnitFilePath), "no service unit file")
	unitFileData := env.ReadFile(serviceUnitFilePath)

	assert.Contains(t, unitFileData, "kill timeout 12345")
	assert.Contains(t, unitFileData, "respawn limit 100 10")
	assert.Contains(t, unitFileData, "sudo -u run_user")
	assert.Contains(t, unitFileData, ">> /var/log/some-app/some-service.log")
}