cloudcmd 17.1.5 → 17.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,29 +10,29 @@ const isString = (a) => typeof a === 'string';
10
10
  module.exports.root = (dir, config, {exit = _exit, statSync = _statSync} = {}) => {
11
11
  if (!isString(dir))
12
12
  throw Error('dir should be a string');
13
-
13
+
14
14
  if (dir === '/')
15
15
  return;
16
-
16
+
17
17
  if (config('dropbox'))
18
18
  return;
19
-
19
+
20
20
  const [error] = tryCatch(statSync, dir);
21
-
21
+
22
22
  if (error)
23
23
  return exit('cloudcmd --root: %s', error.message);
24
24
  };
25
25
 
26
26
  module.exports.editor = (name, {exit = _exit} = {}) => {
27
27
  const reg = /^(dword|edward|deepword)$/;
28
-
28
+
29
29
  if (!reg.test(name))
30
30
  exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
31
31
  };
32
32
 
33
33
  module.exports.packer = (name, {exit = _exit} = {}) => {
34
34
  const reg = /^(tar|zip)$/;
35
-
35
+
36
36
  if (!reg.test(name))
37
37
  exit('cloudcmd --packer: could be "tar" or "zip" only');
38
38
  };
@@ -42,12 +42,12 @@ module.exports.columns = (type, {exit = _exit, getColumns = _getColumns} = {}) =
42
42
  const all = Object
43
43
  .keys(getColumns())
44
44
  .concat('');
45
-
45
+
46
46
  const names = all
47
47
  .filter(Boolean)
48
48
  .map(addQuotes)
49
49
  .join(', ');
50
-
50
+
51
51
  if (!all.includes(type))
52
52
  exit(`cloudcmd --columns: can be only one of: ${names}`);
53
53
  };
@@ -0,0 +1,104 @@
1
+ import {test, stub} from 'supertape';
2
+ import tryCatch from 'try-catch';
3
+ import validate from './validate.js';
4
+ import cloudcmd from './cloudcmd.mjs';
5
+
6
+ test('validate: root: bad', (t) => {
7
+ const config = {
8
+ root: Math.random(),
9
+ };
10
+
11
+ const [e] = tryCatch(cloudcmd, {
12
+ config,
13
+ });
14
+
15
+ t.equal(e.message, 'dir should be a string', 'should throw');
16
+ t.end();
17
+ });
18
+
19
+ test('validate: root: config', (t) => {
20
+ const config = stub().returns(true);
21
+
22
+ validate.root('/hello', config);
23
+
24
+ t.calledWith(config, ['dropbox'], 'should call config');
25
+ t.end();
26
+ });
27
+
28
+ test('validate: root: /', (t) => {
29
+ const fn = stub();
30
+ validate.root('/', fn);
31
+
32
+ t.notCalled(fn, 'should not call fn');
33
+ t.end();
34
+ });
35
+
36
+ test('validate: root: stat', (t) => {
37
+ const config = stub();
38
+ const error = 'ENOENT';
39
+ const statSync = stub().throws(Error(error));
40
+ const exit = stub();
41
+
42
+ validate.root('hello', config, {
43
+ statSync,
44
+ exit,
45
+ });
46
+
47
+ const msg = 'cloudcmd --root: %s';
48
+
49
+ t.calledWith(exit, [msg, error], 'should call fn');
50
+ t.end();
51
+ });
52
+
53
+ test('validate: packer: not valid', (t) => {
54
+ const exit = stub();
55
+ const msg = 'cloudcmd --packer: could be "tar" or "zip" only';
56
+
57
+ validate.packer('hello', {
58
+ exit,
59
+ });
60
+
61
+ t.calledWith(exit, [msg], 'should call fn');
62
+ t.end();
63
+ });
64
+
65
+ test('validate: editor: not valid', (t) => {
66
+ const exit = stub();
67
+ const msg = 'cloudcmd --editor: could be "dword", "edward" or "deepword" only';
68
+
69
+ validate.editor('hello', {
70
+ exit,
71
+ });
72
+
73
+ t.calledWith(exit, [msg], 'should call fn');
74
+ t.end();
75
+ });
76
+
77
+ test('validate: columns', (t) => {
78
+ const exit = stub();
79
+
80
+ validate.columns('name-size-date', {
81
+ exit,
82
+ });
83
+
84
+ t.notCalled(exit, 'should not call exit');
85
+ t.end();
86
+ });
87
+
88
+ test('validate: columns: wrong', (t) => {
89
+ const getColumns = stub().returns({
90
+ 'name-size-date': '',
91
+ 'name-size': '',
92
+ });
93
+
94
+ const exit = stub();
95
+ const msg = 'cloudcmd --columns: can be only one of: "name-size-date", "name-size"';
96
+
97
+ validate.columns('hello', {
98
+ exit,
99
+ getColumns,
100
+ });
101
+
102
+ t.calledWith(exit, [msg], 'should call exit');
103
+ t.end();
104
+ });