Copilot commented on code in PR #3277:
URL: https://github.com/apache/apisix-dashboard/pull/3277#discussion_r2895150984
##########
e2e/server/apisix_conf.yml:
##########
@@ -40,3 +40,8 @@ deployment:
- "http://etcd:2379" # multiple etcd address
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 30 seconds
+
+discovery:
+ nacos:
+ host:
+ - "http://127.0.0.1:8848"
Review Comment:
`discovery.nacos.host` is set to `http://127.0.0.1:8848`, but the e2e
docker-compose only starts `apisix` and `etcd` (no Nacos service). Inside the
APISIX container, `127.0.0.1` points to the container itself, so service
discovery calls will fail if exercised. Consider adding a `nacos` service to
`e2e/server/docker-compose.yml` and referencing it by service name (e.g.,
`http://nacos:8848`), or switch the regression test to a discovery provider
that doesn’t require an external dependency.
```suggestion
- "http://nacos:8848"
```
##########
e2e/tests/upstreams.empty-discovery-args.spec.ts:
##########
@@ -0,0 +1,117 @@
+/**
+ * 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 { upstreamsPom } from '@e2e/pom/upstreams';
+import { e2eReq } from '@e2e/utils/req';
+import { test } from '@e2e/utils/test';
+import { uiHasToastMsg } from '@e2e/utils/ui';
+import { expect } from '@playwright/test';
+
+import { deleteAllUpstreams, putUpstreamReq } from '@/apis/upstreams';
+import { API_UPSTREAMS } from '@/config/constant';
+import type { APISIXType } from '@/types/schema/apisix';
+
+/**
+ * Test that editing an upstream with service discovery and empty
discovery_args
+ * does not cause the discovery_args field to be dropped.
+ * Regression test for: https://github.com/apache/apisix-dashboard/issues/3270
+ */
+const upstream: APISIXType['Upstream'] = {
+ id: 'upstream_discovery_test',
+ name: 'upstream_discovery_test',
+ desc: 'Upstream with service discovery',
+ discovery_type: 'nacos',
+ service_name: 'test-service',
+ discovery_args: {},
+};
+
+test.beforeAll(async () => {
+ await deleteAllUpstreams(e2eReq);
+ await putUpstreamReq(e2eReq, upstream);
+});
+
+test.afterAll(async () => {
+ await deleteAllUpstreams(e2eReq);
+});
+
+test('should preserve empty discovery_args after editing upstream', async ({
+ page,
+}) => {
+ await test.step('verify upstream exists and has discovery fields', async ()
=> {
+ // Verify upstream was created with discovery_args via API
+ const resp = await e2eReq.get(`${API_UPSTREAMS}/${upstream.id}`);
+ const data = resp.data;
+ expect(data.value.discovery_type).toBe('nacos');
+ expect(data.value.service_name).toBe('test-service');
+ expect(data.value.discovery_args).toEqual({});
+ });
+
+ await test.step('navigate to upstream detail page', async () => {
+ await upstreamsPom.toIndex(page);
+ await upstreamsPom.isIndexPage(page);
+
+ // Click on the upstream to view details
+ const row = page.locator('tr').filter({ hasText: upstream.name });
+ await expect(row).toBeVisible();
+ await row.getByRole('button', { name: 'View' }).click();
+ await upstreamsPom.isDetailPage(page);
+ });
+
+ await test.step('edit upstream description and save', async () => {
+ // Click Edit button
+ await page.getByRole('button', { name: 'Edit' }).click();
+
+ // Verify we're in edit mode
+ const nameField = page.getByLabel('Name', { exact: true }).first();
+ await expect(nameField).toBeEnabled();
+
+ // Verify discovery fields are visible
+ const discoverySection = page.getByRole('group', {
+ name: 'Service Discovery',
+ });
+ await expect(discoverySection).toBeVisible();
+
+ // Update the description to trigger a change
+ const descriptionField = page.getByLabel('Description').first();
+ await descriptionField.fill(
+ 'Updated description to verify discovery_args persists'
+ );
+
+ // Save the changes
+ const saveBtn = page.getByRole('button', { name: 'Save' });
+ await saveBtn.click();
+
+ // Verify the update was successful
+ await uiHasToastMsg(page, {
+ hasText: 'success',
+ });
+
+ // Verify we're back in detail view mode
+ await upstreamsPom.isDetailPage(page);
+ });
+
+ await test.step('verify discovery_args is preserved after edit', async ()
=> {
+ // Verify via API that discovery_args was not dropped
+ const resp = await e2eReq.get(`${API_UPSTREAMS}/${upstream.id}`);
+ const data = resp.data;
+ expect(data.value.discovery_type).toBe('nacos');
+ expect(data.value.service_name).toBe('test-service');
+ expect(data.value.discovery_args).toEqual({});
+ expect(data.value.desc).toBe(
+ 'Updated description to verify discovery_args persists'
+ );
+ });
Review Comment:
This new e2e spec has inconsistent indentation (extra 2 levels) for several
`test.step` blocks, which doesn’t match the 2-space formatting used across the
other e2e tests and is likely to cause formatter/lint noise. Please run the
formatter (or align indentation) so the `await test.step(...)` calls are at the
same nesting level within the test.
```suggestion
await test.step('navigate to upstream detail page', async () => {
await upstreamsPom.toIndex(page);
await upstreamsPom.isIndexPage(page);
// Click on the upstream to view details
const row = page.locator('tr').filter({ hasText: upstream.name });
await expect(row).toBeVisible();
await row.getByRole('button', { name: 'View' }).click();
await upstreamsPom.isDetailPage(page);
});
await test.step('edit upstream description and save', async () => {
// Click Edit button
await page.getByRole('button', { name: 'Edit' }).click();
// Verify we're in edit mode
const nameField = page.getByLabel('Name', { exact: true }).first();
await expect(nameField).toBeEnabled();
// Verify discovery fields are visible
const discoverySection = page.getByRole('group', {
name: 'Service Discovery',
});
await expect(discoverySection).toBeVisible();
// Update the description to trigger a change
const descriptionField = page.getByLabel('Description').first();
await descriptionField.fill(
'Updated description to verify discovery_args persists'
);
// Save the changes
const saveBtn = page.getByRole('button', { name: 'Save' });
await saveBtn.click();
// Verify the update was successful
await uiHasToastMsg(page, {
hasText: 'success',
});
// Verify we're back in detail view mode
await upstreamsPom.isDetailPage(page);
});
await test.step('verify discovery_args is preserved after edit', async ()
=> {
// Verify via API that discovery_args was not dropped
const resp = await e2eReq.get(`${API_UPSTREAMS}/${upstream.id}`);
const data = resp.data;
expect(data.value.discovery_type).toBe('nacos');
expect(data.value.service_name).toBe('test-service');
expect(data.value.discovery_args).toEqual({});
expect(data.value.desc).toBe(
'Updated description to verify discovery_args persists'
);
});
```
--
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]