liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
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
'use strict';
 
var grunt = require('grunt');
var helpers = require('./helpers');
 
exports.chmod = {
  setUp: function(done) {
    // setup here if necessary
    done();
  },
  
  default_options: function(test) {
    test.expect(1);
 
    var actual = grunt.file.readJSON('tmp/default_options.json');
    var expected = grunt.file.readJSON('test/expected/default_options.json');
    test.deepEqual(actual, expected, 'Task should fail when relying on the default options.');
 
    test.done();
  },
  
  custom_options_without_string_mode: function(test) {
    test.expect(1);
 
    var actual = grunt.file.readJSON('tmp/custom_options_without_string_mode.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_without_string_mode.json');
    test.deepEqual(actual, expected, 'Task should fail when setting a non-string `mode` on the custom options.');
 
    test.done();
  },
  
  custom_options_with_empty_mode: function(test) {
    test.expect(1);
 
    var actual = grunt.file.readJSON('tmp/custom_options_with_empty_mode.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_with_empty_mode.json');
    test.deepEqual(actual, expected, 'Task should fail when setting an empty string `mode` on the custom options.');
 
    test.done();
  },
  
  custom_options_with_invalid_mode: function(test) {
    test.expect(1);
 
    var actual = grunt.file.readJSON('tmp/custom_options_with_invalid_mode.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_with_invalid_mode.json');
    test.deepEqual(actual, expected, 'Task should fail when setting an invalid string `mode` on the custom options.');
 
    test.done();
  },
  
  custom_options_nonexistent_file: function(test) {
    test.expect(1);
 
    var actual = grunt.file.readJSON('tmp/custom_options_nonexistent_file.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_nonexistent_file.json');
    test.deepEqual(actual, expected, 'Task should pass but not modify any file permissions when there are no files that match.');
 
    test.done();
  },
  
  custom_options_file: function(test) {
    test.expect(2);
 
    var actual = grunt.file.readJSON('tmp/custom_options_file.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_file.json');
    test.deepEqual(actual, expected, 'Task should pass and modify the file permissions of all files that match.');
    
    var rawMode = require('fs').statSync('tmp/custom_options_file.js').mode;
    var numericMode = helpers.permsFromMode(rawMode);
    
    var actualPerms = '' + numericMode;
    var expectedPerms = '444';
    test.strictEqual(actualPerms, expectedPerms, 'Permissions should match.');
 
    test.done();
  },
  
  custom_options_dir: function(test) {
    test.expect(2);
 
    var actual = grunt.file.readJSON('tmp/custom_options_dir.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_dir.json');
    test.deepEqual(actual, expected, 'Task should pass and modify the directory permissions of all directories that match.');
    
    var rawMode = require('fs').statSync('tmp/custom_options_dir/').mode;
    var numericMode = helpers.permsFromMode(rawMode);
    
    var actualPerms = '' + numericMode;
    var expectedPerms = '444';
    test.strictEqual(actualPerms, expectedPerms, 'Permissions should match.');
 
    test.done();
  },
 
  custom_options_file_symbolic_1: function(test) {
    test.expect(2);
 
    var actual = grunt.file.readJSON('tmp/custom_options_file_symbolic_1.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_file_symbolic_1.json');
    test.deepEqual(actual, expected, 'Task should pass and modify the file permissions of all files that match.');
    
    var rawMode = require('fs').statSync('tmp/custom_options_file_symbolic_1.js').mode;
    var numericMode = helpers.permsFromMode(rawMode);
    
    var actualPerms = '' + numericMode;
    var expectedPerms = '400';
    test.strictEqual(actualPerms, expectedPerms, 'Permissions should match.');
 
    test.done();
  },
 
  custom_options_file_symbolic_2: function(test) {
    test.expect(2);
 
    var actual = grunt.file.readJSON('tmp/custom_options_file_symbolic_2.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_file_symbolic_2.json');
    test.deepEqual(actual, expected, 'Task should pass and modify the file permissions of all files that match.');
    
    var rawMode = require('fs').statSync('tmp/custom_options_file_symbolic_2.js').mode;
    var numericMode = helpers.permsFromMode(rawMode);
    
    var actualPerms = '' + numericMode;
    var expectedPerms = '600';
    test.strictEqual(actualPerms, expectedPerms, 'Permissions should match.');
 
    test.done();
  },
 
  custom_options_file_symbolic_3: function(test) {
    test.expect(2);
 
    var actual = grunt.file.readJSON('tmp/custom_options_file_symbolic_3.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_file_symbolic_3.json');
    test.deepEqual(actual, expected, 'Task should pass and modify the file permissions of all files that match.');
    
    var rawMode = require('fs').statSync('tmp/custom_options_file_symbolic_3.js').mode;
    var numericMode = helpers.permsFromMode(rawMode);
    
    var actualPerms = '' + numericMode;
    var expectedPerms = '700';
    test.strictEqual(actualPerms, expectedPerms, 'Permissions should match.');
 
    test.done();
  },
 
  custom_options_file_symbolic_4: function(test) {
    test.expect(2);
 
    var actual = grunt.file.readJSON('tmp/custom_options_file_symbolic_4.json');
    var expected = grunt.file.readJSON('test/expected/custom_options_file_symbolic_4.json');
    test.deepEqual(actual, expected, 'Task should pass and modify the file permissions of all files that match.');
    
    var rawMode = require('fs').statSync('tmp/custom_options_file_symbolic_4.js').mode;
    var numericMode = helpers.permsFromMode(rawMode);
    
    var actualPerms = '' + numericMode;
    var expectedPerms = '404';
    test.strictEqual(actualPerms, expectedPerms, 'Permissions should match.');
 
    test.done();
  }  
};