Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
Author: zxcv <ttgml@outlook.com>
Date:   Wed May 17 13:35:34 2023 +0800

    fix: Added a test case for using host to search for routes
    fix apache#2806 (comment)
  • Loading branch information
YXZhdHI committed Aug 16, 2023
1 parent 9633de4 commit b95a0f8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/internal/handler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
}

if input.Host != "" && !strings.Contains(obj.(*entity.Route).Host, input.Host) {
if strings.Contains(strings.Join(obj.(*entity.Route).Hosts, ""), input.Host) {
return true
}
return false
}

Expand Down
33 changes: 33 additions & 0 deletions web/cypress/integration/route/search-route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ context('Create and Search Route', () => {
name: '#name',
description: '#desc',
hosts_0: '#hosts_0',
hosts_1: '#hosts_1',
add_host: 'button[data-cy="addHost"]',
uris_0: '#uris_0',
labels_0_labelKey: '#labels_0_labelKey',
labels_0_labelValue: '#labels_0_labelValue',
nodes_0_host: '#submitNodes_0_host',
nodes_0_port: '#submitNodes_0_port',
nodes_0_weight: '#submitNodes_0_weight',
nameSearchInput: '#name',
hostSearchInput: '#host',
pathSearchInput: '#uri',
labelSelect_0: '.ant-select-selection-overflow',
dropdown: '.rc-virtual-list',
Expand All @@ -45,6 +48,7 @@ context('Create and Search Route', () => {
const data = {
host1: '11.11.11.11',
host2: '12.12.12.12',
hostx: 'aa.com',
port: '80',
weight: 1,
uris: '/get',
Expand Down Expand Up @@ -79,6 +83,11 @@ context('Create and Search Route', () => {
cy.get(selector.name).type(`test${i}`);
cy.get(selector.description).type(`desc${i}`);
cy.get(selector.hosts_0).type(data.host1);
if (i == 2) {
cy.get(selector.add_host).click();
cy.get(selector.hosts_1).type(data.hostx);
}

cy.get(selector.uris_0).clear().type(`/get${i}`);

// config label
Expand Down Expand Up @@ -134,6 +143,30 @@ context('Create and Search Route', () => {
cy.contains(data.test2).should('not.exist');
});

it('should search the route with host', function () {
cy.visit('/');
cy.contains('Route').click();
cy.wait(timeout);
// only one host
cy.get(selector.hostSearchInput).type(data.hostx);
cy.contains('Search').click();
cy.contains(data.test2).siblings().should('contain', data.hostx);
cy.contains(data.test0).should('not.exist');
cy.contains(data.test1).should('not.exist');
// search hosts
cy.get(selector.hostSearchInput).clear().type(data.host1);
cy.contains('Search').click();
cy.contains(data.test0).siblings().should('contain', data.desc0);
cy.contains(data.test1).siblings().should('contain', data.desc1);
cy.contains(data.test2).siblings().should('contain', data.desc2);
// no match host
cy.get(selector.hostSearchInput).clear().type(data.host2);
cy.contains('Search').click();
cy.contains(data.test0).should('not.exist');
cy.contains(data.test1).should('not.exist');
cy.contains(data.test2).should('not.exist');
});

it('should search the route with path', function () {
cy.visit('/');
cy.contains('Route').click();
Expand Down

0 comments on commit b95a0f8

Please sign in to comment.