Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Support duplicate one existing Route #1558

Merged
merged 6 commits into from
Apr 2, 2021

Conversation

batman-ezio
Copy link
Contributor

@batman-ezio batman-ezio commented Mar 5, 2021

Please answer these questions before submitting a pull request

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches
  • We has added two fields for upstream in APISIX.

Support duplicate one existing Route #1487

New feature or improvement
1: duplicate button from route list
2: check duplicate name from POST route api

Describe the details and related test reports.

1:Click duplicate button from the router list, the address will be routes/:rid/duplicate
image

2: update the name to make sure it's no duplicated
image

3: submit data, return to the list. The new route will be there

image

@batman-ezio batman-ezio force-pushed the issue_1487 branch 3 times, most recently from 38cc523 to fb85518 Compare March 5, 2021 09:40
@@ -307,6 +307,12 @@ func generateLuaCode(script map[string]interface{}) (string, error) {

func (h *Handler) Create(c droplet.Context) (interface{}, error) {
input := c.Input().(*entity.Route)
// check duplicate name
if err := h.checkDuplicateName(c, input.Name, ""); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add this check for Update too. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@nic-chen
Copy link
Member

nic-chen commented Mar 5, 2021

need some test cases for duplicate check, thanks. @batman-ezio

@codecov-io
Copy link

codecov-io commented Mar 6, 2021

Codecov Report

Merging #1558 (a57e082) into master (8e009b0) will decrease coverage by 20.69%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1558       +/-   ##
===========================================
- Coverage   72.46%   51.77%   -20.70%     
===========================================
  Files         134       38       -96     
  Lines        5738     2650     -3088     
  Branches      666        0      -666     
===========================================
- Hits         4158     1372     -2786     
+ Misses       1337     1090      -247     
+ Partials      243      188       -55     
Flag Coverage Δ
backend-e2e-test ?
backend-e2e-test-ginkgo ?
backend-unit-test 51.77% <ø> (-0.04%) ⬇️
frontend-e2e-test ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/internal/utils/version.go 0.00% <0.00%> (-100.00%) ⬇️
api/internal/filter/request_id.go 0.00% <0.00%> (-100.00%) ⬇️
api/internal/core/entity/entity.go 0.00% <0.00%> (-100.00%) ⬇️
api/internal/core/store/storehub.go 0.00% <0.00%> (-71.03%) ⬇️
api/internal/filter/cors.go 0.00% <0.00%> (-66.67%) ⬇️
api/internal/filter/schema.go 0.00% <0.00%> (-55.47%) ⬇️
api/internal/utils/consts/api_error.go 0.00% <0.00%> (-50.00%) ⬇️
api/internal/handler/data_loader/route_import.go 27.41% <0.00%> (-37.50%) ⬇️
api/internal/handler/handler.go 42.59% <0.00%> (-35.19%) ⬇️
api/internal/handler/schema/schema.go 66.66% <0.00%> (-33.34%) ⬇️
... and 118 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e009b0...a57e082. Read the comment docs.

@batman-ezio
Copy link
Contributor Author

need some test cases for duplicate check, thanks. @batman-ezio

@nic-chen after I check duplicate name in create/update route api. some test cases failed. I think they are use the same route name to test before. some errors throw from the route test are very strange , like this

=== RUN   TestRoute_Create/create_route_success
panic: 
assert: mock: I don't know what to return because the method call was unexpected.
	Either do Mock.On("List").Return(...) first, or remove the List() call.
	This method was unexpected:
		List(store.ListInput)
		0: store.ListInput{Predicate:(func(interface {}) bool)(0x11bf5a0), Format:(func(interface {}) interface {})(nil), PageSize:0, PageNumber:0, Less:(func(interface {}, interface {}) bool)(nil)}
	at: [store_mock.go:35 route.go:537 route.go:311 route_test.go:1005] [recovered]
	panic: 
assert: mock: I don't know what to return because the method call was unexpected.
	Either do Mock.On("List").Return(...) first, or remove the List() call.
	This method was unexpected:
		List(store.ListInput)
		0: store.ListInput{Predicate:(func(interface {}) bool)(0x11bf5a0), Format:(func(interface {}) interface {})(nil), PageSize:0, PageNumber:0, Less:(func(interface {}, interface {}) bool)(nil)}
	at: [store_mock.go:35 route.go:537 route.go:311 route_test.go:1005]

I have change the route name but still got this. can you help?

@nic-chen
Copy link
Member

nic-chen commented Mar 8, 2021

need some test cases for duplicate check, thanks. @batman-ezio

@nic-chen after I check duplicate name in create/update route api. some test cases failed. I think they are use the same route name to test before. some errors throw from the route test are very strange , like this

=== RUN   TestRoute_Create/create_route_success
panic: 
assert: mock: I don't know what to return because the method call was unexpected.
	Either do Mock.On("List").Return(...) first, or remove the List() call.
	This method was unexpected:
		List(store.ListInput)
		0: store.ListInput{Predicate:(func(interface {}) bool)(0x11bf5a0), Format:(func(interface {}) interface {})(nil), PageSize:0, PageNumber:0, Less:(func(interface {}, interface {}) bool)(nil)}
	at: [store_mock.go:35 route.go:537 route.go:311 route_test.go:1005] [recovered]
	panic: 
assert: mock: I don't know what to return because the method call was unexpected.
	Either do Mock.On("List").Return(...) first, or remove the List() call.
	This method was unexpected:
		List(store.ListInput)
		0: store.ListInput{Predicate:(func(interface {}) bool)(0x11bf5a0), Format:(func(interface {}) interface {})(nil), PageSize:0, PageNumber:0, Less:(func(interface {}, interface {}) bool)(nil)}
	at: [store_mock.go:35 route.go:537 route.go:311 route_test.go:1005]

I have change the route name but still got this. can you help?

hi @batman-ezio , you need to mock routeStore.List for checkDuplicateName

you could refer to:

pluginConfigStore := &store.MockInterface{}
pluginConfigStore.On("BatchDelete", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
getCalled = true
input := args.Get(1).([]string)
assert.Equal(t, tc.wantInput, input)
}).Return(tc.giveErr)
mockRouteStore := &store.MockInterface{}
mockRouteStore.On("List", mock.Anything).Run(func(args mock.Arguments) {
getCalled = true
}).Return(tc.listRet, nil)
h := Handler{pluginConfigStore: pluginConfigStore, routeStore: mockRouteStore}
ctx := droplet.NewContext()
ctx.SetInput(tc.giveInput)
ret, err := h.BatchDelete(ctx)

@batman-ezio
Copy link
Contributor Author

@batman-ezio
Hi, I see that in your E2E test and unit test, when creating a route, the error code returned is 400, which is usually the wrong data format or type of the route. Please check the data format or type.

hi @Jaycean I found some test case use the same route name or empty route name for e2e test, test cases begin to bump up after my fix one by one

@Jaycean
Copy link
Member

Jaycean commented Mar 8, 2021

@batman-ezio
Hi, I see that in your E2E test and unit test, when creating a route, the error code returned is 400, which is usually the wrong data format or type of the route. Please check the data format or type.

hi @Jaycean I found some test case use the same route name or empty route name for e2e test, test cases begin to bump up after my fix one by one

Yes, 400 is usually caused by wrong data format or type. In E2E test, a route ID r1 is usually created and passed, and the route with ID r1 will be deleted, so there is no problem with the same name.

@nic-chen
Copy link
Member

nic-chen commented Mar 8, 2021

@batman-ezio would you mind if we modify your code on your branch?

@batman-ezio
Copy link
Contributor Author

batman-ezio commented Mar 8, 2021

@batman-ezio would you mind if we modify your code on your branch?

no, please
I found those test case in ece/route_with_* does not pass Name field in the body, so their route will create with a blank name and will failed for duplicate, can we add a logic in create/update API to set the name from url params if it does not exists in the request body?

the frontend e2e test will be fixed after merge this PR #1559

@nic-chen
Copy link
Member

nic-chen commented Mar 8, 2021

can we add a logic in create/update API to set the name from url params if it does not exists in the request body?

oh, no, we should not do that.
we could fix in test cases which do duplicate. I think there will not be a lot, because most of test cases will delete the routes at the end.

@batman-ezio
Copy link
Contributor Author

can we add a logic in create/update API to set the name from url params if it does not exists in the request body?

oh, no, we should not do that.
we could fix in test cases which do duplicate. I think there will not be a lot, because most of test cases will delete the routes at the end.

ok, can you help to fix the rest test cases, thanks

@batman-ezio batman-ezio force-pushed the issue_1487 branch 3 times, most recently from d4753d8 to 65f3a7c Compare March 8, 2021 23:54
@nic-chen
Copy link
Member

nic-chen commented Mar 9, 2021

can we add a logic in create/update API to set the name from url params if it does not exists in the request body?

oh, no, we should not do that.
we could fix in test cases which do duplicate. I think there will not be a lot, because most of test cases will delete the routes at the end.

ok, can you help to fix the rest test cases, thanks

sure, my pleasure. will update later.

@batman-ezio
Copy link
Contributor Author

can we add a logic in create/update API to set the name from url params if it does not exists in the request body?

oh, no, we should not do that.
we could fix in test cases which do duplicate. I think there will not be a lot, because most of test cases will delete the routes at the end.

ok, can you help to fix the rest test cases, thanks

sure, my pleasure. will update later.

thanks. I have squashed all my test case commits into one commit, and rebased from master (which includes the latest frontend e2e fix), but the test case still failed

@nic-chen
Copy link
Member

nic-chen commented Mar 9, 2021

can we add a logic in create/update API to set the name from url params if it does not exists in the request body?

oh, no, we should not do that.
we could fix in test cases which do duplicate. I think there will not be a lot, because most of test cases will delete the routes at the end.

ok, can you help to fix the rest test cases, thanks

sure, my pleasure. will update later.

thanks. I have squashed all my test case commits into one commit, and rebased from master (which includes the latest frontend e2e fix), but the test case still failed

I will try to fix backend CI this afternoon.
@LiteSun could you please help for the FE?

@LiteSun
Copy link
Member

LiteSun commented Mar 9, 2021

I will try to fix backend CI this afternoon.
@LiteSun could you please help for the FE?

ok

@starsz
Copy link
Contributor

starsz commented Mar 9, 2021

CI failed, wait for @nic-chen check this.

@nic-chen
Copy link
Member

nic-chen commented Mar 9, 2021

There are some logical problems in E2E test cases, need more time resolve

@nic-chen
Copy link
Member

backend CI had been resolved.
please help check FE CI when you have time. @LiteSun

@membphis
Copy link
Member

ping @LiteSun

@batman-ezio batman-ezio force-pushed the issue_1487 branch 2 times, most recently from db8b1b2 to fda5d75 Compare March 20, 2021 01:08
@nic-chen
Copy link
Member

please resolve conflicts

@batman-ezio
Copy link
Contributor Author

please resolve conflicts

fixed

});

it('should delete the route', function () {
cy.visit('/routes/list');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LiteSun Do we need to visit this page by clicking Sidebar Menu?

Copy link
Contributor

@liuxiran liuxiran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

and there is a UE enhancement suggestion:
when copying the route user in the page of first step and click [Next] button directly, they will get duplicate route nameerror, maybe leaving the route name blank would be a better choice.

@juzhiyuan
Copy link
Member

ok, then let me merge.

@juzhiyuan juzhiyuan merged commit 9cf91b7 into apache:master Apr 2, 2021
@juzhiyuan
Copy link
Member

thanks! @batman-ezio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet