smengcl commented on code in PR #11513: URL: https://github.com/apache/ozone/pull/11513#discussion_r4265778799
########## hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/mocks/namespaceUsageMocks/namespaceUsageServer.ts: ########## @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { setupServer } from 'msw/node'; +import { http, HttpResponse } from 'msw'; + +import * as mockResponses from './namespaceUsageResponseMocks'; + +/** Paths from `path` query param on each intercepted usage request (for tests). */ +export const usagePathsRequested: string[] = []; + +export function resetNamespaceUsageRequestTracking(): void { + usagePathsRequested.length = 0; +} + +const usageHandler = http.get('/api/v1/namespace/usage', ({ request }) => { + const url = new URL(request.url); + const path = url.searchParams.get('path') ?? '/'; + usagePathsRequested.push(path); + + if (path === '/missing') { + return HttpResponse.json(mockResponses.PathNotFoundUsage); + } + if (path === '/vol1/bucket1/key1') { + return HttpResponse.json(mockResponses.Key1NamespaceUsage); + } + if (path === '/vol1/bucket1') { + return HttpResponse.json(mockResponses.Bucket1NamespaceUsage); + } + if (path === '/vol1') { + return HttpResponse.json(mockResponses.Vol1NamespaceUsage); + } + return HttpResponse.json(mockResponses.RootNamespaceUsage); +}); + +const summaryHandler = http.get('/api/v1/namespace/summary', ({ request }) => { + const url = new URL(request.url); + const path = url.searchParams.get('path') ?? '/'; + if (path === '/vol1/bucket1/key1') { + return HttpResponse.json(mockResponses.Key1SummaryResponse); + } + if (path === '/vol1/bucket1') { + return HttpResponse.json(mockResponses.Bucket1SummaryResponse); + } + if (path === '/vol1') { + return HttpResponse.json(mockResponses.Vol1SummaryResponse); + } + return HttpResponse.json(mockResponses.RootSummaryResponse); Review Comment: Please model `/missing` on all three namespace endpoints. `UnknownEntityHandler` returns `PATH_NOT_FOUND` for summary and quota too, but these handlers fall back to root responses. The test therefore checks only the usage toast while `NUMetadata` can render root metadata; add missing-path responses and assert that the metadata is cleared. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
