Skip to content

Commit

Permalink
feat: add route publish test module
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiran committed Sep 9, 2020
1 parent b6220d4 commit 5e2c54a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions api/route/route_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package route

import (
"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/service"
"net/http"
"testing"
)

// publish route
func TestPublishRoute(t *testing.T) {

// create route
handler.Post(uriPrefix+"/routes").
Header("Authorization", token).
JSON(`{
"name":"api-test",
"desc":"",
"priority":0,
"protocols":["http"],
"hosts":["test1.com"],
"paths":["/*"],
"methods":["GET","HEAD","POST","PUT","DELETE","OPTIONS","PATCH"],
"status":false,
"upstream_protocol":"keep",
"plugins":{},
"uris":["/*"],
"vars":[],
"upstream":{"type":"roundrobin","nodes":{"127.0.0.1:443":1},
"timeout":{"connect":6000,"send":6000,"read":6000}},
"upstream_header":{}
}`).Expect(t).
Status(http.StatusOK).
End()
route, _ := getRouteByName("api-test")

// publish route
handler.Put(uriPrefix + "/routes/" + route.ID.String() + "publish").Expect(t).Status(http.StatusOK).End()
// offline route
handler.Put(uriPrefix + "/routes/" + route.ID.String() + "offline").Expect(t).Status(http.StatusOK).End()

}

func getRouteByName(name string) (*service.Route, error) {
db := conf.DB()
route := &service.Route{}
if err := db.Table("routes").Where("name = ?", name).First(&route).Error; err != nil {
return nil, err
}
return route, nil
}

0 comments on commit 5e2c54a

Please sign in to comment.