-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprofile_test.go
More file actions
136 lines (95 loc) · 3.25 KB
/
Copy pathprofile_test.go
File metadata and controls
136 lines (95 loc) · 3.25 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewProfile_FromJSON(t *testing.T) {
t.Parallel()
p, err := NewProfile("testdata/profile_valid.json")
require.NoError(t, err)
assert.Equal(t, "/dotfiles/root", p.DotfilesDir())
}
func TestNewProfile_FromTOML(t *testing.T) {
t.Parallel()
p, err := NewProfile("testdata/profile_valid.toml")
require.NoError(t, err)
assert.Equal(t, "/dotfiles/root", p.DotfilesDir())
}
func TestNewProfile_InvalidJSON(t *testing.T) {
t.Parallel()
_, err := NewProfile("testdata/profile_invalid.json")
assert.Error(t, err)
}
func TestNewProfile_InvalidTOML(t *testing.T) {
t.Parallel()
_, err := NewProfile("testdata/profile_invalid.toml")
assert.Error(t, err)
}
func TestNewProfile_UnknownExtension(t *testing.T) {
t.Parallel()
_, err := NewProfile("testdata/somefile.badext")
assert.Error(t, err)
}
func TestNewProfile_BadDotfilesDirectory(t *testing.T) {
t.Parallel()
_, err := NewProfile("testdata/profile_bad_dotfiles.json")
assert.Error(t, err)
assert.Contains(t, err.Error(), "must be an absolute path")
}
func TestNewProfile_BadSourcesDirectory(t *testing.T) {
t.Parallel()
_, err := NewProfile("testdata/profile_bad_sources.json")
assert.Error(t, err)
assert.Contains(t, err.Error(), "must be a relative path")
}
func TestNewProfile_BadDestinationDirectory(t *testing.T) {
t.Parallel()
_, err := NewProfile("testdata/profile_bad_destination.json")
assert.Error(t, err)
assert.Contains(t, err.Error(), "must be an absolute path")
}
func TestNewProfile_BadBackupDirectory(t *testing.T) {
t.Parallel()
_, err := NewProfile("testdata/profile_bad_backup.json")
assert.Error(t, err)
assert.Contains(t, err.Error(), "must be an absolute path")
}
func TestNewProfile_ExpandEnv(t *testing.T) {
t.Setenv("TEST_DOTFILES_DIR", "/my/dotfiles")
t.Setenv("TEST_DESTINATION_DIR", "/my/destination")
t.Setenv("TEST_BACKUP_DIR", "/my/backup")
p, err := NewProfile("testdata/profile_env_vars.json")
require.NoError(t, err)
assert.Equal(t, "/my/dotfiles", p.DotfilesDir())
assert.Equal(t, "/my/destination", p.DestinationDir())
assert.Equal(t, "/my/backup", p.BackupDir())
}
func TestNewProfile_Mapping_TOML(t *testing.T) {
t.Parallel()
p, err := NewProfile("testdata/profile_mapping.toml")
require.NoError(t, err)
assert.Equal(t, Destinations{"dst/single"}, p.Data().Mapping["src/single"])
assert.Equal(t, Destinations{"dst/one", "dst/two"}, p.Data().Mapping["src/multi"])
}
func TestNewProfile_Mapping_JSON(t *testing.T) {
t.Parallel()
p, err := NewProfile("testdata/profile_mapping.json")
require.NoError(t, err)
assert.Equal(t, Destinations{"dst/single"}, p.Data().Mapping["src/single"])
assert.Equal(t, Destinations{"dst/one", "dst/two"}, p.Data().Mapping["src/multi"])
}
func TestNewProfile_DefaultValues(t *testing.T) {
home := os.Getenv("HOME")
profilePath, err := filepath.Abs("testdata/profile_defaults.json")
require.NoError(t, err)
profileDir := filepath.Dir(profilePath)
p, err := NewProfile(profilePath)
require.NoError(t, err)
assert.Equal(t, profileDir, p.DotfilesDir())
assert.Equal(t, "", p.SourcesDir())
assert.Equal(t, home, p.DestinationDir())
assert.Equal(t, home+"/.dotfiles~", p.BackupDir())
}