Skip to content

Commit 9764dad

Browse files
authored
feat: add service discovery config (#2081)
1 parent bcdd3b6 commit 9764dad

File tree

17 files changed

+646
-70
lines changed

17 files changed

+646
-70
lines changed

api/internal/core/entity/entity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ type UpstreamDef struct {
171171
Key string `json:"key,omitempty"`
172172
Scheme string `json:"scheme,omitempty"`
173173
DiscoveryType string `json:"discovery_type,omitempty"`
174+
DiscoveryArgs map[string]string `json:"discovery_args,omitempty"`
174175
PassHost string `json:"pass_host,omitempty"`
175176
UpstreamHost string `json:"upstream_host,omitempty"`
176177
Name string `json:"name,omitempty"`
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
/* eslint-disable no-undef */
18+
19+
context('Create Route with Service Discovery Upstream', () => {
20+
const selector = {
21+
name: '#name',
22+
description: '#desc',
23+
discovery_type: '#discovery_type',
24+
service_name: '#service_name',
25+
upstreamSelector: '[data-cy=upstream_selector]',
26+
nameSelector: '[title=Name]',
27+
selectItem: '.ant-select-item-option-content',
28+
drawer: '.ant-drawer-content',
29+
monacoScroll: '.monaco-scrollable-element',
30+
input: ':input',
31+
deleteAlert: '.ant-modal-body',
32+
notification: '.ant-notification-notice-message',
33+
};
34+
35+
const data = {
36+
deleteRouteSuccess: 'Delete Route Successfully',
37+
submitSuccess: 'Submit Successfully',
38+
deleteUpstreamSuccess: 'Delete Upstream Successfully',
39+
weight: 1,
40+
description: 'desc_by_autotest',
41+
upstreamName: 'test_upstream',
42+
routeName: 'test_route',
43+
serviceName: 'test.cluster.local',
44+
};
45+
46+
beforeEach(() => {
47+
cy.login();
48+
});
49+
50+
it('should create route with DNS service discovery upstream', function () {
51+
cy.visit('/');
52+
cy.get('[role=menu]')
53+
.should('be.visible')
54+
.within(() => {
55+
cy.contains('Route').click();
56+
});
57+
cy.contains('Create').click();
58+
59+
cy.contains('Next').click().click();
60+
cy.get(selector.name).type(data.routeName);
61+
cy.contains('Next').click();
62+
63+
// should enable Upstream input boxes after selecting Custom mode
64+
cy.get(selector.upstreamSelector).click();
65+
cy.contains('.ant-select-item-option-content', 'Custom').click();
66+
67+
// set service discovery
68+
cy.get('[title="Node"]').click();
69+
cy.get(selector.selectItem).within(() => {
70+
cy.contains('Service Discovery').click();
71+
});
72+
73+
cy.get(selector.discovery_type).click();
74+
cy.get(selector.selectItem).within(() => {
75+
cy.contains('DNS').click();
76+
});
77+
cy.get(selector.service_name).type(data.serviceName);
78+
79+
cy.contains('Next').click();
80+
cy.contains('Next').click();
81+
cy.contains('Submit').click();
82+
cy.contains(data.submitSuccess).should('be.visible');
83+
cy.contains('Goto List').click();
84+
cy.url().should('contains', 'routes/list');
85+
86+
// check if the service discovery have been saved
87+
cy.get(selector.nameSelector).type(data.routeName);
88+
cy.contains('Search').click();
89+
90+
cy.contains(data.routeName).siblings().contains('Configure').click();
91+
// ensure it has already changed to edit page
92+
cy.get(selector.name).should('value', data.routeName);
93+
cy.contains('Next').click({
94+
force: true,
95+
});
96+
cy.get(selector.service_name).should('value', data.serviceName);
97+
});
98+
99+
it('should edit this route with Nacos Service Discovery upstream', function () {
100+
cy.visit('/');
101+
cy.contains('Route').click();
102+
cy.get(selector.nameSelector).type(data.routeName);
103+
104+
cy.contains('Search').click();
105+
cy.contains(data.routeName).siblings().contains('Configure').click();
106+
107+
cy.get(selector.name).should('value', data.routeName);
108+
cy.contains('Next').click({
109+
force: true,
110+
});
111+
112+
cy.contains('DNS').should('exist');
113+
114+
// set another service discovery
115+
cy.get(selector.discovery_type).click({ force: true });
116+
cy.get(selector.selectItem).within(() => {
117+
cy.contains('Nacos').click();
118+
});
119+
cy.get(selector.service_name).clear().type(`another.${data.serviceName}`);
120+
121+
cy.contains('Next').click();
122+
cy.contains('Next').click();
123+
cy.contains('Submit').click();
124+
cy.contains(data.submitSuccess).should('be.visible');
125+
cy.contains('Goto List').click();
126+
cy.url().should('contains', 'routes/list');
127+
128+
// check if the changes have been saved
129+
cy.get(selector.nameSelector).type(data.routeName);
130+
cy.contains('Search').click();
131+
132+
cy.contains(data.routeName).siblings().contains('Configure').click();
133+
// ensure it has already changed to edit page
134+
cy.get(selector.name).should('value', data.routeName);
135+
cy.contains('Next').click({
136+
force: true,
137+
});
138+
cy.get(selector.service_name).should('value', `another.${data.serviceName}`);
139+
});
140+
141+
it('should view the test route', function () {
142+
cy.visit('/');
143+
cy.contains('Route').click();
144+
145+
cy.get(selector.nameSelector).type(data.routeName);
146+
cy.contains('Search').click();
147+
cy.contains(data.routeName).siblings().contains('More').click();
148+
cy.contains('View').click();
149+
cy.get(selector.drawer).should('be.visible');
150+
151+
cy.get(selector.monacoScroll).within(() => {
152+
cy.contains('service_name').should('exist');
153+
cy.contains('discovery').should('exist');
154+
});
155+
});
156+
157+
it('should delete this test route and upstream', function () {
158+
cy.visit('/routes/list');
159+
cy.get(selector.nameSelector).type(data.routeName);
160+
cy.contains('Search').click();
161+
cy.contains(data.routeName).siblings().contains('More').click();
162+
cy.contains('Delete').click();
163+
cy.get(selector.deleteAlert)
164+
.should('be.visible')
165+
.within(() => {
166+
cy.contains('OK').click();
167+
});
168+
cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
169+
});
170+
});
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
/* eslint-disable no-undef */
18+
19+
context('Create and Edit Service with Custom CHash Key Upstream', () => {
20+
const selector = {
21+
name: '#name',
22+
description: '#desc',
23+
roundRobinSelect: '[title="Round Robin"]',
24+
upstreamTypeSelect: '[title="Node"]',
25+
discovery_type: '#discovery_type',
26+
service_name: '#service_name',
27+
upstreamType: '.ant-select-item-option-content',
28+
hashPosition: '.ant-select-item-option-content',
29+
discoveryTypeSelect: '.ant-select-item-option-content',
30+
chash_key: '#key',
31+
notification: '.ant-notification-notice-message',
32+
nameSearch: '[title=Name]',
33+
notificationCloseIcon: '.ant-notification-close-icon',
34+
drawer: '.ant-drawer-content',
35+
monacoScroll: '.monaco-scrollable-element',
36+
};
37+
38+
const data = {
39+
createServiceSuccess: 'Create Service Successfully',
40+
deleteServiceSuccess: 'Delete Service Successfully',
41+
editServiceSuccess: 'Configure Service Successfully',
42+
port: '80',
43+
weight: 1,
44+
description: 'desc_by_autotest',
45+
ip1: '127.0.0.1',
46+
port0: '7000',
47+
weight0: '1',
48+
custom_key: 'custom_key',
49+
new_key: 'new_key',
50+
serviceName: 'test.cluster.local',
51+
anotherServiceName: `another.test.cluster.local`,
52+
};
53+
54+
beforeEach(() => {
55+
cy.login();
56+
});
57+
58+
it('should create a service with service discovery Upstream', function () {
59+
cy.visit('/');
60+
cy.contains('Service').click();
61+
cy.contains('Create').click();
62+
cy.get(selector.name).type(data.serviceName);
63+
cy.get(selector.description).type(data.description);
64+
cy.get(selector.upstreamTypeSelect).click();
65+
cy.get(selector.upstreamType).within(() => {
66+
cy.contains('Service Discovery').click();
67+
});
68+
cy.get(selector.discovery_type).click();
69+
cy.get(selector.discoveryTypeSelect).within(() => {
70+
cy.contains('DNS').click();
71+
});
72+
cy.get(selector.service_name).type(data.serviceName);
73+
cy.contains('Next').click();
74+
cy.contains('Next').click();
75+
cy.contains('Submit').click();
76+
cy.get(selector.notification).should('contain', data.createServiceSuccess);
77+
});
78+
79+
it('should edit the service', function () {
80+
cy.visit('/service/list');
81+
82+
cy.get(selector.nameSearch).type(data.serviceName);
83+
cy.contains('Search').click();
84+
cy.contains(data.serviceName).siblings().contains('Configure').click();
85+
86+
cy.wait(1000);
87+
88+
cy.get(selector.name).clear().type(data.anotherServiceName);
89+
90+
// set another service discovery
91+
cy.get(selector.discovery_type).click({ force: true });
92+
cy.get(selector.discoveryTypeSelect).within(() => {
93+
cy.contains('Nacos').click();
94+
});
95+
cy.get(selector.service_name).clear().type(data.anotherServiceName);
96+
97+
cy.contains('Next').click();
98+
cy.contains('Next').click();
99+
cy.contains('Submit').click();
100+
cy.get(selector.notification).should('contain', data.editServiceSuccess);
101+
});
102+
103+
it('should view the test service', function () {
104+
cy.visit('/service/list');
105+
106+
cy.get(selector.nameSearch).type(data.anotherServiceName);
107+
cy.contains('Search').click();
108+
cy.contains(data.anotherServiceName).siblings().contains('View').click();
109+
cy.get(selector.drawer).should('be.visible');
110+
111+
cy.get(selector.monacoScroll).within(() => {
112+
cy.contains('service_name').should('exist');
113+
cy.contains('discovery').should('exist');
114+
});
115+
});
116+
117+
it('should delete this service', function () {
118+
cy.visit('/service/list');
119+
cy.get(selector.nameSearch).type(data.anotherServiceName);
120+
cy.contains('Search').click();
121+
cy.contains(data.anotherServiceName).siblings().contains('Delete').click();
122+
cy.contains('button', 'Confirm').click();
123+
cy.get(selector.notification).should('contain', data.deleteServiceSuccess);
124+
cy.get(selector.notificationCloseIcon).click();
125+
});
126+
});

0 commit comments

Comments
 (0)