aboutsummaryrefslogtreecommitdiff
path: root/src/tools/chmod-calculator/chmod-calculator.service.test.ts
diff options
context:
space:
mode:
authorGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-11-23 21:57:38 +0100
committerGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-11-23 21:57:38 +0100
commit35b518711938c2bc88f35d104bb35d9956f0c267 (patch)
tree50cccc637a1a03c1074cad4b10edcc633a09617a /src/tools/chmod-calculator/chmod-calculator.service.test.ts
parent94698cea50d46906dbb969036f586567f22b1e45 (diff)
downloadit-tools-35b518711938c2bc88f35d104bb35d9956f0c267.tar.gz
it-tools-35b518711938c2bc88f35d104bb35d9956f0c267.tar.zst
it-tools-35b518711938c2bc88f35d104bb35d9956f0c267.zip
feat(new-tool): chmod calculator
Diffstat (limited to 'src/tools/chmod-calculator/chmod-calculator.service.test.ts')
-rw-r--r--src/tools/chmod-calculator/chmod-calculator.service.test.ts68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/tools/chmod-calculator/chmod-calculator.service.test.ts b/src/tools/chmod-calculator/chmod-calculator.service.test.ts
new file mode 100644
index 0000000..fafb393
--- /dev/null
+++ b/src/tools/chmod-calculator/chmod-calculator.service.test.ts
@@ -0,0 +1,68 @@
+import { expect, describe, it } from 'vitest';
+import { computeChmodOctalRepresentation } from './chmod-calculator.service';
+
+describe('chmod-calculator', () => {
+ describe('computeChmodOctalRepresentation', () => {
+ it('get the octal representation from permissions', () => {
+ expect(
+ computeChmodOctalRepresentation({
+ permissions: {
+ owner: { read: true, write: true, execute: true },
+ group: { read: true, write: true, execute: true },
+ public: { read: true, write: true, execute: true },
+ },
+ }),
+ ).to.eql('777');
+
+ expect(
+ computeChmodOctalRepresentation({
+ permissions: {
+ owner: { read: false, write: false, execute: false },
+ group: { read: false, write: false, execute: false },
+ public: { read: false, write: false, execute: false },
+ },
+ }),
+ ).to.eql('000');
+
+ expect(
+ computeChmodOctalRepresentation({
+ permissions: {
+ owner: { read: false, write: true, execute: false },
+ group: { read: false, write: true, execute: true },
+ public: { read: true, write: false, execute: true },
+ },
+ }),
+ ).to.eql('235');
+
+ expect(
+ computeChmodOctalRepresentation({
+ permissions: {
+ owner: { read: true, write: false, execute: false },
+ group: { read: false, write: true, execute: false },
+ public: { read: false, write: false, execute: true },
+ },
+ }),
+ ).to.eql('421');
+
+ expect(
+ computeChmodOctalRepresentation({
+ permissions: {
+ owner: { read: false, write: false, execute: true },
+ group: { read: false, write: true, execute: false },
+ public: { read: true, write: false, execute: false },
+ },
+ }),
+ ).to.eql('124');
+
+ expect(
+ computeChmodOctalRepresentation({
+ permissions: {
+ owner: { read: false, write: true, execute: false },
+ group: { read: false, write: true, execute: false },
+ public: { read: false, write: true, execute: false },
+ },
+ }),
+ ).to.eql('222');
+ });
+ });
+});