summaryrefslogtreecommitdiff
path: root/fs/utils_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'fs/utils_test.ts')
-rw-r--r--fs/utils_test.ts35
1 files changed, 34 insertions, 1 deletions
diff --git a/fs/utils_test.ts b/fs/utils_test.ts
index 9d6959de5..9f8d10cb0 100644
--- a/fs/utils_test.ts
+++ b/fs/utils_test.ts
@@ -2,8 +2,12 @@
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
-import { isSubdir } from "./utils.ts";
+import { isSubdir, getFileInfoType, PathType } from "./utils.ts";
import * as path from "./path/mod.ts";
+import { ensureFileSync } from "./ensure_file.ts";
+import { ensureDirSync } from "./ensure_dir.ts";
+
+const testdataDir = path.resolve("fs", "testdata");
test(function _isSubdir() {
const pairs = [
@@ -29,3 +33,32 @@ test(function _isSubdir() {
);
});
});
+
+test(function _getFileInfoType() {
+ const pairs = [
+ [path.join(testdataDir, "file_type_1"), PathType.file],
+ [path.join(testdataDir, "file_type_dir_1"), PathType.dir]
+ ];
+
+ pairs.forEach(function(p) {
+ const filePath = p[0] as string;
+ const type = p[1] as PathType;
+ switch (type) {
+ case PathType.file:
+ ensureFileSync(filePath);
+ break;
+ case PathType.dir:
+ ensureDirSync(filePath);
+ break;
+ case PathType.symlink:
+ // TODO(axetroy): test symlink
+ break;
+ }
+
+ const stat = Deno.statSync(filePath);
+
+ Deno.removeSync(filePath, { recursive: true });
+
+ assertEquals(getFileInfoType(stat), type);
+ });
+});