AlinsRan commented on code in PR #12718:
URL: https://github.com/apache/apisix/pull/12718#discussion_r2554719605


##########
t/admin/standalone.spec.ts:
##########
@@ -194,6 +194,86 @@ describe('Admin - Standalone', () => {
   });
 
   describe('Normal', () => {
+    it('validate config (success case with json)', async () => {
+      const resp = await client.post(`${ENDPOINT}/validate`, config1);
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',
+        valid: true,
+      });
+    });
+
+    it('validate config (success case with yaml)', async () => {
+      const resp = await client.post(`${ENDPOINT}/validate`, 
YAML.stringify(config1), {
+        headers: { 'Content-Type': 'application/yaml' },
+      });
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',
+        valid: true,
+      });
+    });
+
+    it('validate config (success case with multiple resources)', async () => {
+      const multiResourceConfig = {
+        routes: [
+          {
+            id: 'r1',
+            uri: '/r1',
+            upstream: {
+              nodes: { '127.0.0.1:1980': 1 },
+              type: 'roundrobin',
+            },
+          },
+          {
+            id: 'r2',
+            uri: '/r2',
+            upstream: {
+              nodes: { '127.0.0.1:1980': 1 },
+              type: 'roundrobin',
+            },
+          },
+        ],
+        services: [
+          {
+            id: 's1',
+            upstream: {
+              nodes: { '127.0.0.1:1980': 1 },
+              type: 'roundrobin',
+            },
+          },
+        ],
+        routes_conf_version: 1,
+        services_conf_version: 1,
+      };
+
+      const resp = await client.post(`${ENDPOINT}/validate`, 
multiResourceConfig);
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',
+        valid: true,
+      });
+    });
+
+    it('validate config with consumer credentials', async () => {
+      const resp = await client.post(`${ENDPOINT}/validate`, credential1);
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',

Review Comment:
   fixed.



##########
t/admin/standalone.spec.ts:
##########
@@ -194,6 +194,86 @@ describe('Admin - Standalone', () => {
   });
 
   describe('Normal', () => {
+    it('validate config (success case with json)', async () => {
+      const resp = await client.post(`${ENDPOINT}/validate`, config1);
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',
+        valid: true,
+      });
+    });
+
+    it('validate config (success case with yaml)', async () => {
+      const resp = await client.post(`${ENDPOINT}/validate`, 
YAML.stringify(config1), {
+        headers: { 'Content-Type': 'application/yaml' },
+      });
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',
+        valid: true,
+      });
+    });
+
+    it('validate config (success case with multiple resources)', async () => {
+      const multiResourceConfig = {
+        routes: [
+          {
+            id: 'r1',
+            uri: '/r1',
+            upstream: {
+              nodes: { '127.0.0.1:1980': 1 },
+              type: 'roundrobin',
+            },
+          },
+          {
+            id: 'r2',
+            uri: '/r2',
+            upstream: {
+              nodes: { '127.0.0.1:1980': 1 },
+              type: 'roundrobin',
+            },
+          },
+        ],
+        services: [
+          {
+            id: 's1',
+            upstream: {
+              nodes: { '127.0.0.1:1980': 1 },
+              type: 'roundrobin',
+            },
+          },
+        ],
+        routes_conf_version: 1,
+        services_conf_version: 1,
+      };
+
+      const resp = await client.post(`${ENDPOINT}/validate`, 
multiResourceConfig);
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',
+        valid: true,
+      });
+    });
+
+    it('validate config with consumer credentials', async () => {
+      const resp = await client.post(`${ENDPOINT}/validate`, credential1);
+      expect(resp.status).toEqual(200);
+      expect(resp.data).toEqual({
+        message: 'Configuration is valid',
+        valid: true,
+      });
+    });
+
+    it('validate config does not persist changes', async () => {
+      // First validate a configuration
+      const validateResp = await client.post(`${ENDPOINT}/validate`, config1);
+      expect(validateResp.status).toEqual(200);
+
+      // Then check that the configuration was not persisted
+      const getResp = await client.get(ENDPOINT);
+      expect(getResp.data.routes).toBeUndefined();
+    });

Review Comment:
   fixed.



-- 
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]

Reply via email to