mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
f5e46c9bf2
This looks like a massive PR, but it's only a move from cli/tests -> tests, and updates of relative paths for files. This is the first step towards aggregate all of the integration test files under tests/, which will lead to a set of integration tests that can run without the CLI binary being built. While we could leave these tests under `cli`, it would require us to keep a more complex directory structure for the various test runners. In addition, we have a lot of complexity to ignore various test files in the `cli` project itself (cargo publish exclusion rules, autotests = false, etc). And finally, the `tests/` folder will eventually house the `test_ffi`, `test_napi` and other testing code, reducing the size of the root repo directory. For easier review, the extremely large and noisy "move" is in the first commit (with no changes -- just a move), while the remainder of the changes to actual files is in the second commit.
337 lines
8.8 KiB
TypeScript
337 lines
8.8 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
import {
|
|
assertEquals,
|
|
assertRejects,
|
|
assertThrows,
|
|
pathToAbsoluteFileUrl,
|
|
} from "./test_util.ts";
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function futimeSyncSuccess() {
|
|
const testDir = await Deno.makeTempDir();
|
|
const filename = testDir + "/file.txt";
|
|
using file = await Deno.open(filename, {
|
|
create: true,
|
|
write: true,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
await Deno.futime(file.rid, atime, mtime);
|
|
await file.syncData();
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function fsFileUtimeSyncSuccess() {
|
|
const testDir = await Deno.makeTempDir();
|
|
const filename = testDir + "/file.txt";
|
|
using file = await Deno.open(filename, {
|
|
create: true,
|
|
write: true,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
await file.utime(atime, mtime);
|
|
await file.syncData();
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function futimeSyncSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
using file = Deno.openSync(filename, {
|
|
create: true,
|
|
write: true,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
Deno.futimeSync(file.rid, atime, mtime);
|
|
file.syncDataSync();
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function futimeSyncSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
using file = Deno.openSync(filename, {
|
|
create: true,
|
|
write: true,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
file.utimeSync(atime, mtime);
|
|
file.syncDataSync();
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function utimeSyncFileSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
mode: 0o666,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
Deno.utimeSync(filename, atime, mtime);
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function utimeSyncUrlSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
mode: 0o666,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
Deno.utimeSync(pathToAbsoluteFileUrl(filename), atime, mtime);
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function utimeSyncDirectorySuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
Deno.utimeSync(testDir, atime, mtime);
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
|
assertEquals(dirInfo.atime, new Date(atime * 1000));
|
|
assertEquals(dirInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function utimeSyncDateSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const atime = new Date(1000_000);
|
|
const mtime = new Date(50000_000);
|
|
Deno.utimeSync(testDir, atime, mtime);
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
|
assertEquals(dirInfo.atime, atime);
|
|
assertEquals(dirInfo.mtime, mtime);
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function utimeSyncFileDateSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
mode: 0o666,
|
|
});
|
|
const atime = new Date();
|
|
const mtime = new Date();
|
|
Deno.utimeSync(filename, atime, mtime);
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, atime);
|
|
assertEquals(fileInfo.mtime, mtime);
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function utimeSyncLargeNumberSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
// There are Rust side caps (might be fs relate),
|
|
// so JUST make them slightly larger than UINT32_MAX.
|
|
const atime = 0x100000001;
|
|
const mtime = 0x100000002;
|
|
Deno.utimeSync(testDir, atime, mtime);
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
|
assertEquals(dirInfo.atime, new Date(atime * 1000));
|
|
assertEquals(dirInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
function utimeSyncNotFound() {
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
|
|
assertThrows(
|
|
() => {
|
|
Deno.utimeSync("/baddir", atime, mtime);
|
|
},
|
|
Deno.errors.NotFound,
|
|
"utime '/baddir'",
|
|
);
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: false } },
|
|
function utimeSyncPerm() {
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
|
|
assertThrows(() => {
|
|
Deno.utimeSync("/some_dir", atime, mtime);
|
|
}, Deno.errors.PermissionDenied);
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function utimeFileSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
mode: 0o666,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
await Deno.utime(filename, atime, mtime);
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function utimeUrlSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
mode: 0o666,
|
|
});
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
await Deno.utime(pathToAbsoluteFileUrl(filename), atime, mtime);
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function utimeDirectorySuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
await Deno.utime(testDir, atime, mtime);
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
|
assertEquals(dirInfo.atime, new Date(atime * 1000));
|
|
assertEquals(dirInfo.mtime, new Date(mtime * 1000));
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function utimeDateSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const atime = new Date(100_000);
|
|
const mtime = new Date(5000_000);
|
|
await Deno.utime(testDir, atime, mtime);
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
|
assertEquals(dirInfo.atime, atime);
|
|
assertEquals(dirInfo.mtime, mtime);
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function utimeFileDateSuccess() {
|
|
const testDir = Deno.makeTempDirSync();
|
|
const filename = testDir + "/file.txt";
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
mode: 0o666,
|
|
});
|
|
|
|
const atime = new Date();
|
|
const mtime = new Date();
|
|
await Deno.utime(filename, atime, mtime);
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
assertEquals(fileInfo.atime, atime);
|
|
assertEquals(fileInfo.mtime, mtime);
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: true } },
|
|
async function utimeNotFound() {
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
|
|
await assertRejects(
|
|
async () => {
|
|
await Deno.utime("/baddir", atime, mtime);
|
|
},
|
|
Deno.errors.NotFound,
|
|
"utime '/baddir'",
|
|
);
|
|
},
|
|
);
|
|
|
|
Deno.test(
|
|
{ permissions: { read: true, write: false } },
|
|
async function utimeSyncPerm() {
|
|
const atime = 1000;
|
|
const mtime = 50000;
|
|
|
|
await assertRejects(async () => {
|
|
await Deno.utime("/some_dir", atime, mtime);
|
|
}, Deno.errors.PermissionDenied);
|
|
},
|
|
);
|