-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
notebooks-export.bats
214 lines (166 loc) · 5.26 KB
/
notebooks-export.bats
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env bats
load test_helper
_setup_notebooks() {
"${_NB}" init
mkdir -p "${NB_DIR}/one"
cd "${NB_DIR}/one" || return 1
git init
git remote add origin "${_GIT_REMOTE_URL}"
touch "${NB_DIR}/one/.index"
mkdir -p "${NB_DIR}/two"
cd "${NB_DIR}" || return 1
}
# <name> validation ###########################################################
@test "'notebooks export <reserved>' exits with 1 and prints error message." {
{
"${_NB}" init
cd "${_TMP_DIR}"
_names=(
".cache"
".current"
".plugins"
".readme"
"readme"
"readme.md"
)
}
for __name in "${_names[@]}"
do
run "${_NB}" notebooks export "${__name}" "${_TMP_DIR}/example"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]]
[[ "${lines[0]}" =~ Name\ reserved ]]
[[ "${lines[0]}" =~ ${__name} ]]
done
}
# `notebooks export` ##########################################################
@test "'notebooks export' with no arguments exits with status 1 and prints help." {
{
"${_NB}" init
}
run "${_NB}" notebooks export
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]]
[[ "${lines[0]}" =~ Usage.*\: ]]
}
@test "'notebooks export' with valid <name> exports to current directory." {
{
"${_NB}" init
}
run "${_NB}" notebooks add "example"
[[ -d "${NB_DIR}/example" ]]
[[ ! -d "${_TMP_DIR}/example" ]]
cd "${_TMP_DIR}"
run "${_NB}" notebooks export "example"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
ls "${_TMP_DIR}"
[[ ${status} -eq 0 ]]
[[ -d "${_TMP_DIR}/example" ]]
[[ -d "${_TMP_DIR}/example/.git" ]]
[[ "${lines[0]}" =~ "Exported" ]]
}
@test "'notebooks export' with valid <name> exports to current directory uniquely." {
{
"${_NB}" init
"${_NB}" notebooks add "example"
[[ -d "${NB_DIR}/example" ]]
mkdir -p "${_TMP_DIR}/example"
[[ -d "${_TMP_DIR}/example" ]]
cd "${_TMP_DIR}"
}
run "${_NB}" notebooks export "example"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
ls "${_TMP_DIR}"
[[ ${status} -eq 0 ]]
[[ -d "${_TMP_DIR}/example-1" ]]
[[ -d "${_TMP_DIR}/example-1/.git" ]]
[[ "${lines[0]}" =~ "Exported" ]]
}
@test "'notebooks export' with invalid <name> exits with 1." {
{
"${_NB}" init
"${_NB}" notebooks add "example"
[[ -d "${NB_DIR}/example" ]]
cd "${_TMP_DIR}"
}
run "${_NB}" notebooks export "not valid"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
ls "${_TMP_DIR}"
[[ ${status} -eq 1 ]]
[[ ! -d "${_TMP_DIR}/example" ]]
[[ ! -d "${_TMP_DIR}/example/.git" ]]
[[ "${lines[0]}" =~ "not found" ]]
}
@test "'notebooks export' with valid <name> and <path> exports." {
{
"${_NB}" init
"${_NB}" notebooks add "example"
[[ -d "${NB_DIR}/example" ]]
[[ ! -d "${_TMP_DIR}/example" ]]
}
run "${_NB}" notebooks export "example" "${_TMP_DIR}/example"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
ls "${_TMP_DIR}"
[[ ${status} -eq 0 ]]
[[ -d "${_TMP_DIR}/example" ]]
[[ -d "${_TMP_DIR}/example/.git" ]]
[[ "${lines[0]}" =~ "Exported" ]]
}
@test "'notebooks export' with valid <name> and <path> exports uniquely." {
{
"${_NB}" init
"${_NB}" notebooks add "example"
[[ -d "${NB_DIR}/example" ]]
mkdir -p "${_TMP_DIR}/example"
[[ -d "${_TMP_DIR}/example" ]]
}
run "${_NB}" notebooks export "example" "${_TMP_DIR}/example"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
ls "${_TMP_DIR}"
[[ ${status} -eq 0 ]]
[[ -d "${_TMP_DIR}/example-1" ]]
[[ -d "${_TMP_DIR}/example-1/.git" ]]
[[ "${lines[0]}" =~ "Exported" ]]
}
@test "'notebooks export' with valid <name> and <path> ending in existing name exports." {
{
"${_NB}" init
"${_NB}" notebooks add "example"
[[ -d "${NB_DIR}/example" ]]
mkdir -p "${_TMP_DIR}/example"
[[ -d "${_TMP_DIR}/example" ]]
}
run "${_NB}" notebooks export "example" "${_TMP_DIR}/sample-example"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
ls "${_TMP_DIR}"
[[ ${status} -eq 0 ]]
[[ -d "${_TMP_DIR}/sample-example" ]]
[[ -d "${_TMP_DIR}/sample-example/.git" ]]
[[ "${lines[0]}" =~ "Exported" ]]
}
@test "'notebooks export' with valid <name> and relative <path> exports." {
{
"${_NB}" init
"${_NB}" notebooks add "example"
[[ -d "${NB_DIR}/example" ]]
mkdir -p "${_TMP_DIR}/subfolder"
[[ -d "${_TMP_DIR}/subfolder" ]]
cd "${_TMP_DIR}"
}
run "${_NB}" notebooks export "example" "subfolder/local-notebook"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
ls "${_TMP_DIR}"
[[ ${status} -eq 0 ]]
[[ -d "${_TMP_DIR}/subfolder/local-notebook" ]]
[[ -d "${_TMP_DIR}/subfolder/local-notebook/.git" ]]
[[ "${lines[0]}" =~ "Exported" ]]
}