-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: should redirect when nfs adapter support url #522
fix: should redirect when nfs adapter support url #522
Conversation
test/port/controller/package/DownloadPackageVersionTarController.test.ts
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #522 +/- ##
==========================================
- Coverage 97.08% 97.00% -0.08%
==========================================
Files 174 174
Lines 16518 16538 +20
Branches 2160 2162 +2
==========================================
+ Hits 16036 16043 +7
- Misses 482 495 +13
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -222,6 +242,7 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test. | |||
.expect(302) | |||
.expect('location', 'https://registry.npmjs.org/foo/-/foo-1.0.404404.tgz?t=123'); | |||
|
|||
mock(app.config.cnpmcore, 'redirectNotFound', false); | |||
// not redirect when package exists | |||
await app.httpRequest() | |||
.get(`/${name}/-/${name}-1.0.404404.tgz`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码是一个测试用例,主要负责测试当包版本不存在时的行为。建议在代码审查中注重以下几点:
-
确认该测试涵盖了所有可能情况
-
检查是否需要提供更多的上下文或者注释来帮助理解该测试
-
评估该测试的可读性和可维护性,包括变量和方法命名的清晰度以及代码格式的一致性
-
确保在修改代码时更新相应的测试用例,并考虑是否需要新增测试用例
在这个具体的代码片段中,测试增加了针对未发布版本的测试,还模拟了 redirectNotFound 和 url 方法。有两个测试用例被添加到测试套件中,一个测试了包版本不存在时的 404 响应,另一个则确保了当指定源注册表时,CNPM 应该将其重定向到该源。
目前代码看起来没有风险和改进的地方。
@@ -176,6 +177,25 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test. | |||
}); | |||
}); | |||
|
|||
it('should redirect to source registry when package version not exists', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我补了一个单测
[skip ci] ## [3.34.2](v3.34.1...v3.34.2) (2023-06-17) ### Bug Fixes * should redirect when nfs adapter support url ([#522](#522)) ([3d6864c](3d6864c))
@@ -33,15 +33,17 @@ export class DownloadPackageVersionTarController extends AbstractController { | |||
const version = this.getAndCheckVersionFromFilename(ctx, fullname, filenameWithVersion); | |||
const storeKey = `/packages/${fullname}/${version}/${filenameWithVersion}.tgz`; | |||
const downloadUrl = await this.nfsAdapter.getDownloadUrl(storeKey); | |||
// check package version in database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个改动会导致 registry.npmmirror.com 出现大量 db 查询,我先加一个开关
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[skip ci] ## [3.34.4](v3.34.3...v3.34.4) (2023-06-20) ### Bug Fixes * avoid db query on sync mode all ([#527](#527)) ([49855d9](49855d9)), closes [/github.com//pull/522/files#r1234655574](https://github.com/cnpm//github.com/cnpm/cnpmcore/pull/522/files/issues/r1234655574)
@@ -33,15 +33,17 @@ export class DownloadPackageVersionTarController extends AbstractController { | |||
const version = this.getAndCheckVersionFromFilename(ctx, fullname, filenameWithVersion); | |||
const storeKey = `/packages/${fullname}/${version}/${filenameWithVersion}.tgz`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原来这里已经有跳过 db 直接访问 oss 的逻辑,计算 semver 逻辑里一样可以跳过了。
本来还单性可能 oss path 发生变化的情况。
[skip ci] ## [3.34.4](v3.34.3...v3.34.4) (2023-06-20) ### Bug Fixes * avoid db query on sync mode all ([#527](#527)) ([49855d9](49855d9)), closes [/github.com//pull/522/files#r1234655574](https://github.com/cnpm//github.com/cnpm/cnpmcore/pull/522/files/issues/r1234655574)
will check package version on database before redirect to nfs store url
closes #521