-
Notifications
You must be signed in to change notification settings - Fork 13
/
installer_test.go
55 lines (44 loc) · 1.39 KB
/
installer_test.go
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
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"os"
"path/filepath"
"testing"
)
func getTestInstaller() *systemdInstaller {
targetDirectory := os.TempDir()
commandExecutor := newExecutor(os.Stdin, os.Stdout, os.Stderr, "", false)
return &systemdInstaller{targetDirectory, commandExecutor, false}
}
func Test_createSystemdService_NoErrorIsReturned(t *testing.T) {
installer := getTestInstaller()
serviceViewModel := serviceDefinition{
ProjectName: "exampleproject",
ProjectDirectory: "/var/www/example-project",
DockerComposeFile: "docker-compose.yml",
}
result := installer.createSystemdService(serviceViewModel)
if result != nil {
t.Fail()
t.Logf("createSystemdService returned %s", result)
}
}
func Test_createSystemdService_ServiceFileIsWritten(t *testing.T) {
installer := getTestInstaller()
serviceViewModel := serviceDefinition{
ProjectName: "exampleproject",
ProjectDirectory: "/var/www/example-project",
DockerComposeFile: "docker-compose.yml",
}
result := installer.createSystemdService(serviceViewModel)
if result != nil {
t.Fail()
t.Logf("createSystemdService returned %s", result)
}
targetFilePath := filepath.Join(installer.systemdDirectory, fmt.Sprintf("%s.service", serviceViewModel.ProjectName))
_, err := os.Stat(targetFilePath)
if err != nil {
t.Fail()
t.Logf("createSystemdService failed to create the service file %s: %s", targetFilePath, err)
}
}