-
Notifications
You must be signed in to change notification settings - Fork 542
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
fix: unable to export route with nil methods field #1673
fix: unable to export route with nil methods field #1673
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1673 +/- ##
===========================================
- Coverage 72.59% 62.34% -10.25%
===========================================
Files 133 47 -86
Lines 5728 3126 -2602
Branches 666 0 -666
===========================================
- Hits 4158 1949 -2209
+ Misses 1327 865 -462
- Partials 243 312 +69
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
if route.Methods != nil && len(route.Methods) > 0 { | ||
routeMethods = route.Methods | ||
} else { | ||
routeMethods = []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch, http.MethodHead, http.MethodConnect, http.MethodTrace, http.MethodOptions} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a pre-defined unexportable variable to indicate this default method set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,Because these methods such as "GET", "POST" and so on are immutable, the use here is more uniform, and "Get", "get" and "GET" will not appear.
They don't affect the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean creating a variable _allHTTPMethods
, which is:
var (
_allHTTPMethods = []string{http.MethodGet, http.MethodPost, ...}
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misunderstood.
Done. Thks
@@ -131,7 +129,6 @@ | |||
} | |||
}, | |||
"x-apisix-enable_websocket": false, | |||
"x-apisix-plugins": {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to know why delete it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The design of import and export is to export when there is data, and not export when there is no data. Here, no data is empty. I don't think it's necessary to export, so I delete it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not deleted, Fe ci will report an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jaycean do we have some test case for x-apisix-plugins
not empty ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, most of the other test cases have data in x-apisix-plugins
For example, this test case:
func TestExportRoutes1(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation.Got it.
"172.16.238.20:1980": 1 | ||
}, | ||
"type": "roundrobin" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are the same. Can we use a variable instead?
"requestBody": {},
"responses": {
"default": {
"description": ""
}
},
"x-apisix-enable_websocket": false,
"x-apisix-hosts": ["test.com"],
"x-apisix-priority": 0,
"x-apisix-status": 1,
"x-apisix-upstream": {
"nodes": {
"172.16.238.20:1980": 1
},
"type": "roundrobin"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I intend to modify it uniformly when using ginkgo rewriting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
Please answer these questions before submitting a pull request, or your PR will get closed.
Why submit this pull request?
What changes will this PR take into?
Fixed the bug that when creating route, the methods field is nil or [] and the data cannot be exported.
When there is no plugin data in the route, the empty field is not exported.
Related issues
fix/resolve #1668
Checklist: