-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,219 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
rootDir: "src", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {dirname, resolve} from "node:path"; | ||
import {createReadStream} from "node:fs"; | ||
import {FileStorage, MinIO, MinIOBucketPolicy} from "../../src"; | ||
|
||
const fs = new FileStorage(new MinIO("http://minioadmin:minioadmin@localhost:9000")); | ||
|
||
beforeAll(async () => { | ||
const b = fs.getBucket("test"); | ||
await b.save(); | ||
await b.setPolicy(MinIOBucketPolicy.PUBLIC_READONLY); | ||
}); | ||
|
||
describe("MinIO", () => { | ||
test("put URL", async () => { | ||
const bucket = fs.getBucket("test"); | ||
const stat = await bucket.put("url", new URL("https://www.google.com/favicon.ico")); | ||
expect(stat.size).toBeGreaterThan(0); | ||
expect(stat.lastModified).toBeInstanceOf(Date); | ||
expect(stat.metadata["content-type"]).toBe("image/x-icon"); | ||
expect(stat.etag.length).toBeGreaterThan(0); | ||
}); | ||
|
||
test("put string", async () => { | ||
const bucket = fs.getBucket("test"); | ||
const stat = await bucket.put("string", "hello", {"content-type": "text/plain"}); | ||
expect(stat.size).toBe(5); | ||
expect(stat.lastModified).toBeInstanceOf(Date); | ||
expect(stat.metadata["content-type"]).toBe("text/plain"); | ||
expect(stat.etag.length).toBeGreaterThan(0); | ||
}); | ||
|
||
test("put buffer", async () => { | ||
const bucket = fs.getBucket("test"); | ||
const stat = await bucket.put("buffer", Buffer.from("hello"), {"content-type": "text/plain"}); | ||
expect(stat.size).toBe(5); | ||
expect(stat.lastModified).toBeInstanceOf(Date); | ||
expect(stat.metadata["content-type"]).toBe("text/plain"); | ||
expect(stat.etag.length).toBeGreaterThan(0); | ||
}); | ||
|
||
test("put file", async () => { | ||
const bucket = fs.getBucket("test"); | ||
const file = new URL(`file://${resolve(dirname(__filename), "./hello.txt")}`); | ||
const stat = await bucket.put("file", file, {"content-type": "text/plain"}); | ||
expect(stat.size).toBe(6); | ||
expect(stat.lastModified).toBeInstanceOf(Date); | ||
expect(stat.metadata["content-type"]).toBe("text/plain"); | ||
expect(stat.etag.length).toBeGreaterThan(0); | ||
}); | ||
|
||
test("put readable", async () => { | ||
const bucket = fs.getBucket("test"); | ||
const file = createReadStream(resolve(dirname(__filename), "./hello.txt")); | ||
const stat = await bucket.put("readable", file, {"content-type": "text/plain"}); | ||
expect(stat.size).toBe(6); | ||
expect(stat.lastModified).toBeInstanceOf(Date); | ||
expect(stat.metadata["content-type"]).toBe("text/plain"); | ||
expect(stat.etag.length).toBeGreaterThan(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../../tsconfig.test.json", | ||
"include": [ | ||
"src", | ||
"../src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"module": "CommonJS", | ||
"target": "ES2022", | ||
"lib": [ | ||
"ES2022" | ||
|
Oops, something went wrong.