Skip to content

Commit

Permalink
add test case for utils getFileInfoType
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 19, 2019
1 parent 9aff721 commit c78607c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion fs/utils_test.ts
Expand Up @@ -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 = [
Expand All @@ -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);
});
});

0 comments on commit c78607c

Please sign in to comment.