-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor download command use golang error style insted of try catch (#…
…31) * refactored download command to use golang error style insted of try catch * Improved PR
- Loading branch information
Showing
5 changed files
with
166 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { it, expect, describe } from "bun:test" | ||
import { getTestServer } from "tests/fixtures/get-test-server" | ||
import { temporaryDirectory } from "tempy" | ||
import { downloadDatasetToDirectory } from "@/cli/download/download-dataset" | ||
import { join } from "path" | ||
|
||
describe("downloadDatasetToDirectory error cases", () => { | ||
it("should return error for non-existent dataset", async () => { | ||
const { ky } = await getTestServer() | ||
const tempDir = temporaryDirectory() | ||
|
||
await expect( | ||
downloadDatasetToDirectory({ | ||
datasetNameWithOwner: "nonexistent/dataset", | ||
outputDirectory: tempDir, | ||
ky, | ||
}), | ||
).rejects.toThrow( | ||
/Failed to fetch dataset "nonexistent\/dataset".*Please check if the dataset exists and you have access to it.*Original error/, | ||
) | ||
}) | ||
|
||
it("should return error for invalid output directory", async () => { | ||
const { ky } = await getTestServer() | ||
|
||
const invalidDir = join( | ||
"/", | ||
"nonexistent", | ||
"path", | ||
"that", | ||
"should", | ||
"fail", | ||
) | ||
|
||
await expect( | ||
downloadDatasetToDirectory({ | ||
datasetNameWithOwner: "testuser/custom-keyboards", | ||
outputDirectory: invalidDir, | ||
ky, | ||
}), | ||
).rejects.toThrow(/Failed to create dataset directory.*Original error/) | ||
}) | ||
|
||
it("should return error for failed file download", async () => { | ||
const tempDir = temporaryDirectory() | ||
|
||
await expect( | ||
downloadDatasetToDirectory({ | ||
datasetNameWithOwner: "testuser/custom-keyboards", | ||
outputDirectory: tempDir, | ||
}), | ||
).rejects.toThrow( | ||
/Failed to fetch dataset "testuser\/custom-keyboards".*Please check if the dataset exists and you have access to it.*Original error/, | ||
) | ||
}) | ||
}) |
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