-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap_test.go
59 lines (46 loc) · 1.55 KB
/
bootstrap_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
package config
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/getlantern/yaml"
"github.com/getlantern/flashlight/v7/common"
)
func TestBootstrapSettings(t *testing.T) {
file, err := ioutil.TempFile("", ".packaged-lantern.yaml")
defer func() {
err := os.Remove(file.Name())
if err != nil {
log.Errorf("Could not remove file? %v", err)
}
}()
assert.True(t, err == nil, "Should not be an error")
file.Close()
log.Debugf("File at: %v", file.Name())
settings := BootstrapSettings{StartupUrl: "test"}
log.Debugf("Settings: %v", settings)
data, er := yaml.Marshal(&settings)
assert.True(t, er == nil, "Should not be an error")
e := ioutil.WriteFile(file.Name(), data, 0644)
assert.True(t, e == nil, "Should not be an error")
ps, errr := readSettingsFromFile(file.Name())
assert.Equal(t, "test", ps.StartupUrl, "Unexpected startup URL")
assert.NoError(t, errr, "Unable to read settings")
_, path, err := bootstrapPath(name)
assert.True(t, err == nil, "Should not be an error")
var dir string
if common.Platform == "darwin" {
dir, err = filepath.Abs(filepath.Dir(os.Args[0]) + "/../Resources")
} else if common.Platform == "linux" {
dir, err = filepath.Abs(filepath.Dir(os.Args[0]) + "/../")
}
assert.True(t, err == nil, "Should not be an error")
log.Debugf("Running in %v", dir)
if common.Platform == "darwin" {
assert.Equal(t, dir+"/"+name, path, "Unexpected settings dir")
} else if common.Platform == "linux" {
assert.Equal(t, dir+"/"+name, path, "Unexpected settings dir")
}
}