diff options
| author | Axetroy <troy450409405@gmail.com> | 2019-04-07 09:01:23 +0800 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-04-07 04:01:23 +0300 |
| commit | d6f808958f414315a09b3429cf0c4b5c258f1012 (patch) | |
| tree | d2d60398319ba1bcd3f11216b258d835941ef45f /fs/utils_test.ts | |
| parent | 9d1e24b67baf59d1d8b9bd1eb2a6c4135c6e7ca4 (diff) | |
fix: ensure exists file/dir must be the same type or it will throw error (denoland/deno_std#294)
Original: https://github.com/denoland/deno_std/commit/24f41f67bdbc9f426e3f9f03598a1010748d8200
Diffstat (limited to 'fs/utils_test.ts')
| -rw-r--r-- | fs/utils_test.ts | 35 |
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); + }); +}); |
