2020-12-28 15:58:58 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-12-29 09:26:08 -05:00
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertThrows,
|
|
|
|
assertThrowsAsync,
|
|
|
|
} from "../../testing/asserts.ts";
|
2020-12-28 15:58:58 -05:00
|
|
|
import { mkdtemp, mkdtempSync } from "./_fs_mkdtemp.ts";
|
|
|
|
import { existsSync } from "./_fs_exists.ts";
|
|
|
|
import { env } from "../process.ts";
|
|
|
|
import { isWindows } from "../../_util/os.ts";
|
|
|
|
import { promisify } from "../_util/_util_promisify.ts";
|
|
|
|
|
|
|
|
const prefix = isWindows ? env.TEMP + "\\" : (env.TMPDIR || "/tmp") + "/";
|
|
|
|
const doesNotExists = "/does/not/exists/";
|
|
|
|
const options = { encoding: "ascii" };
|
|
|
|
const badOptions = { encoding: "bogus" };
|
|
|
|
|
|
|
|
const mkdtempP = promisify(mkdtemp);
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtemp",
|
|
|
|
fn: async () => {
|
2020-12-29 09:26:08 -05:00
|
|
|
const directory = await mkdtempP(prefix);
|
|
|
|
assert(existsSync(directory));
|
|
|
|
Deno.removeSync(directory);
|
2020-12-28 15:58:58 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtemp (does not exists)",
|
|
|
|
fn: async () => {
|
2020-12-29 09:26:08 -05:00
|
|
|
await assertThrowsAsync(() => mkdtempP(doesNotExists));
|
2020-12-28 15:58:58 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtemp (with options)",
|
|
|
|
fn: async () => {
|
2020-12-29 09:26:08 -05:00
|
|
|
const directory = await mkdtempP(prefix, options);
|
|
|
|
assert(existsSync(directory));
|
|
|
|
Deno.removeSync(directory);
|
2020-12-28 15:58:58 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtemp (with bad options)",
|
|
|
|
fn: async () => {
|
2020-12-29 09:26:08 -05:00
|
|
|
await assertThrowsAsync(() => mkdtempP(prefix, badOptions));
|
2020-12-28 15:58:58 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtempSync",
|
|
|
|
fn: () => {
|
|
|
|
const directory = mkdtempSync(prefix);
|
|
|
|
const dirExists = existsSync(directory);
|
|
|
|
Deno.removeSync(directory);
|
|
|
|
assert(dirExists);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtempSync (does not exists)",
|
|
|
|
fn: () => {
|
2020-12-29 09:26:08 -05:00
|
|
|
assertThrows(() => mkdtempSync(doesNotExists));
|
2020-12-28 15:58:58 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtempSync (with options)",
|
|
|
|
fn: () => {
|
|
|
|
const directory = mkdtempSync(prefix, options);
|
|
|
|
const dirExists = existsSync(directory);
|
|
|
|
Deno.removeSync(directory);
|
|
|
|
assert(dirExists);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "[node/fs] mkdtempSync (with bad options)",
|
|
|
|
fn: () => {
|
2020-12-29 09:26:08 -05:00
|
|
|
assertThrows(() => mkdtempSync(prefix, badOptions));
|
2020-12-28 15:58:58 -05:00
|
|
|
},
|
|
|
|
});
|