tokers commented on code in PR #937:
URL:
https://github.com/apache/apisix-ingress-controller/pull/937#discussion_r844945283
##########
test/e2e/scaffold/k8s.go:
##########
@@ -251,6 +252,75 @@ func (s *Scaffold)
EnsureNumApisixPluginConfigCreated(desired int) error {
return s.ensureNumApisixCRDsCreated(u.String(), desired)
}
+// CreateApisixRouteByApisixAdmin create a route
+func (s *Scaffold) CreateApisixRouteByApisixAdmin(routeID string, body []byte)
error {
+ u := url.URL{
+ Scheme: "http",
+ Host: s.apisixAdminTunnel.Endpoint(),
+ Path: "/apisix/admin/routes/" + routeID,
+ }
+ return s.ensureHTTPPutSuccess(u.String(), body)
+}
+
+func (s *Scaffold) ensureHTTPPutSuccess(url string, body []byte) error {
+ condFunc := func() (bool, error) {
+ req, err := http.NewRequest("PUT", url, bytes.NewBuffer(body))
+ if err != nil {
+ return false, err
+ }
+ if s.opts.APISIXAdminAPIKey != "" {
+ req.Header.Set("X-API-Key", s.opts.APISIXAdminAPIKey)
+ }
+ req.Header.Set("Content-Type", "application/json")
+
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ ginkgo.GinkgoT().Logf("failed to create resources from
APISIX: %s", err.Error())
+ return false, nil
+ }
+ if resp.StatusCode != http.StatusOK {
+ ginkgo.GinkgoT().Logf("got status code %d from APISIX",
resp.StatusCode)
+ return false, nil
+ }
+ return true, nil
+ }
+ return wait.Poll(3*time.Second, 35*time.Second, condFunc)
+}
+
+// DeleteApisixRouteByApisixAdmin deletes a route by its route name in APISIX
cluster.
+func (s *Scaffold) DeleteApisixRouteByApisixAdmin(routeID string) error {
+ u := url.URL{
+ Scheme: "http",
+ Host: s.apisixAdminTunnel.Endpoint(),
+ Path: "/apisix/admin/routes/" + routeID,
+ }
+ return s.ensureHTTPDeleteSuccess(u.String())
+}
+
+func (s *Scaffold) ensureHTTPDeleteSuccess(url string) error {
Review Comment:
I think we can encapsulate a method `ensureAdminOperationIsSuccessful`, and
pass the request, so that we can reuse the code base of `ensureHTTPPutSuccess`.
--
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]