forked from asticode/go-astilectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provisioner_test.go
121 lines (110 loc) · 4.96 KB
/
provisioner_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package astilectron
import (
"context"
"io/ioutil"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func testProvisionerSuccessful(t *testing.T, p Paths, osName, arch string) {
_, err := os.Stat(p.AstilectronApplication())
assert.NoError(t, err)
_, err = os.Stat(p.AppExecutable())
assert.NoError(t, err)
b, err := ioutil.ReadFile(p.ProvisionStatus())
assert.NoError(t, err)
assert.Equal(t, "{\"astilectron\":{\"version\":\""+VersionAstilectron+"\"},\"electron\":{\""+provisionStatusElectronKey(osName, arch)+"\":{\"version\":\""+VersionElectron+"\"}}}\n", string(b))
}
func TestDefaultProvisioner(t *testing.T) {
// Init
var o = Options{BaseDirectoryPath: mockedTempPath()}
defer os.RemoveAll(o.BaseDirectoryPath)
var mh = &mockedHandler{}
var s = httptest.NewServer(mh)
// Test linux
p, err := newPaths("linux", "amd64", o)
assert.NoError(t, err)
p.astilectronUnzipSrc = filepath.Join(p.astilectronDownloadDst, "astilectron")
p.astilectronDownloadSrc = s.URL + "/provisioner/astilectron"
p.electronDownloadSrc = s.URL + "/provisioner/electron/linux"
err = DefaultProvisioner.Provision(context.Background(), "", "linux", "amd64", *p)
assert.NoError(t, err)
testProvisionerSuccessful(t, *p, "linux", "amd64")
// Test nothing happens if provision status is up to date
mh.e = true
os.Remove(p.AstilectronDownloadDst())
os.Remove(p.ElectronDownloadDst())
err = DefaultProvisioner.Provision(context.Background(), "", "linux", "amd64", *p)
assert.NoError(t, err)
testProvisionerSuccessful(t, *p, "linux", "amd64")
// Test windows
mh.e = false
os.RemoveAll(o.BaseDirectoryPath)
p, err = newPaths("windows", "amd64", o)
assert.NoError(t, err)
p.astilectronUnzipSrc = filepath.Join(p.astilectronDownloadDst, "astilectron")
p.astilectronDownloadSrc = s.URL + "/provisioner/astilectron"
p.electronDownloadSrc = s.URL + "/provisioner/electron/windows"
err = DefaultProvisioner.Provision(context.Background(), "", "windows", "amd64", *p)
assert.NoError(t, err)
testProvisionerSuccessful(t, *p, "windows", "amd64")
// Test darwin without custom app name + icon
os.RemoveAll(o.BaseDirectoryPath)
p, err = newPaths("darwin", "amd64", o)
assert.NoError(t, err)
p.astilectronUnzipSrc = filepath.Join(p.astilectronDownloadDst, "astilectron")
p.astilectronDownloadSrc = s.URL + "/provisioner/astilectron"
p.electronDownloadSrc = s.URL + "/provisioner/electron/darwin"
err = DefaultProvisioner.Provision(context.Background(), "", "darwin", "amd64", *p)
assert.NoError(t, err)
testProvisionerSuccessful(t, *p, "darwin", "amd64")
// Test darwin with custom app name + icon
os.RemoveAll(o.BaseDirectoryPath)
o.AppName = "Test app"
wd, err := os.Getwd()
assert.NoError(t, err)
o.AppIconDarwinPath = filepath.Join(wd, "testdata", "provisioner", "icon.icns")
p, err = newPaths("darwin", "amd64", o)
assert.NoError(t, err)
p.astilectronUnzipSrc = filepath.Join(p.astilectronDownloadDst, "astilectron")
p.astilectronDownloadSrc = s.URL + "/provisioner/astilectron"
p.electronDownloadSrc = s.URL + "/provisioner/electron/darwin"
err = DefaultProvisioner.Provision(context.Background(), o.AppName, "darwin", "amd64", *p)
assert.NoError(t, err)
testProvisionerSuccessful(t, *p, "darwin", "amd64")
// Rename
_, err = os.Stat(filepath.Join(p.ElectronDirectory(), o.AppName+".app"))
assert.NoError(t, err)
_, err = os.Stat(filepath.Join(p.ElectronDirectory(), o.AppName+".app", "Contents", "MacOS", o.AppName))
assert.NoError(t, err)
_, err = os.Stat(filepath.Join(p.ElectronDirectory(), o.AppName+".app", "Contents", "Frameworks", o.AppName+" Helper.app"))
assert.NoError(t, err)
_, err = os.Stat(filepath.Join(p.ElectronDirectory(), o.AppName+".app", "Contents", "Frameworks", o.AppName+" Helper.app", "Contents", "MacOS", o.AppName+" Helper"))
assert.NoError(t, err)
// Icon
b, err := ioutil.ReadFile(filepath.Join(p.ElectronDirectory(), o.AppName+".app", "Contents", "Resources", "electron.icns"))
assert.NoError(t, err)
assert.Equal(t, "body", string(b))
// Replace
b, err = ioutil.ReadFile(filepath.Join(p.ElectronDirectory(), o.AppName+".app", "Contents", "Info.plist"))
assert.NoError(t, err)
assert.Equal(t, "<string>"+o.AppName+" Test</string>", string(b))
b, err = ioutil.ReadFile(filepath.Join(p.ElectronDirectory(), o.AppName+".app", "Contents", "Frameworks", o.AppName+" Helper.app", "Contents", "Info.plist"))
assert.NoError(t, err)
assert.Equal(t, "<string>"+o.AppName+" Test</string>", string(b))
}
func TestNewDisembedderProvisioner(t *testing.T) {
// Init
var o = Options{BaseDirectoryPath: mockedTempPath()}
defer os.RemoveAll(o.BaseDirectoryPath)
p, err := newPaths("linux", "amd64", o)
assert.NoError(t, err)
p.astilectronUnzipSrc = filepath.Join(p.astilectronDownloadDst, "astilectron")
pvb := NewDisembedderProvisioner(mockedDisembedder, "astilectron", "electron/linux")
// Test provision
err = pvb.Provision(context.Background(), "", "linux", "amd64", *p)
assert.NoError(t, err)
testProvisionerSuccessful(t, *p, "linux", "amd64")
}