Skip to content
File

Blob: src/workerd/io/worker-fs-test.c++

1.3 KB
1#include "worker-fs.h"
2 
3#include <kj/debug.h>
4#include <kj/test.h>
5 
6namespace workerd {
7namespace {
8 
9kj::Own<FsMap> createTestFsMap() {
10 auto map = kj::heap<FsMap>();
11 map->setBundleRoot("/mything/bundle");
12 map->setTempRoot("/mything/temp");
13 return kj::mv(map);
14}
15 
16KJ_TEST("FsMap") {
17 auto fsMap = createTestFsMap();
18 
19 // Check that the paths are correct.
20 KJ_EXPECT(fsMap->getBundlePath().toString(false) == "mything/bundle");
21 KJ_EXPECT(fsMap->getTempPath().toString(false) == "mything/temp");
22 KJ_EXPECT(fsMap->getBundleRoot().equal("file:///mything/bundle"_url));
23 KJ_EXPECT(fsMap->getTempRoot().equal("file:///mything/temp"_url));
24}
25 
26KJ_TEST("TmpDirStoreScope") {
27 // We can create multiple temp storages on the heap...
28 auto tmpStoreOnHeap = TmpDirStoreScope::create();
29 auto tmpStoreOnHeap2 = TmpDirStoreScope::create();
30 
31 KJ_EXPECT(!TmpDirStoreScope::hasCurrent());
32 
33 {
34 // But we can only have one on the stack at a time per thread.
35 TmpDirStoreScope tmpDirStoreScope;
36 KJ_EXPECT(TmpDirStoreScope::hasCurrent());
37 KJ_ASSERT(&TmpDirStoreScope::current() == &tmpDirStoreScope);
38 KJ_ASSERT(&TmpDirStoreScope::current() != tmpStoreOnHeap.get());
39 KJ_ASSERT(&TmpDirStoreScope::current() != tmpStoreOnHeap2.get());
40 }
41 KJ_EXPECT(!TmpDirStoreScope::hasCurrent());
42}
43 
44} // namespace
45} // namespace workerd