|
| 1 | +package regcenter_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "e2e/tools" |
| 5 | + "e2e/tools/common" |
| 6 | + "time" |
| 7 | + |
| 8 | + . "github.com/onsi/ginkgo/v2" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | +) |
| 11 | + |
| 12 | +var _ = Describe("Normal test", Ordered, func() { |
| 13 | + Context("single route, one server", func() { |
| 14 | + |
| 15 | + type normalCase struct { |
| 16 | + URI string |
| 17 | + Route *tools.Route |
| 18 | + Server *tools.SimServer |
| 19 | + Reg tools.IRegCenter |
| 20 | + ExpectBody string |
| 21 | + } |
| 22 | + |
| 23 | + DescribeTable("general logic", Ordered, |
| 24 | + func(tc normalCase) { |
| 25 | + Expect(tools.CreateRoutes([]*tools.Route{tc.Route})).To(BeNil()) |
| 26 | + //create sim server |
| 27 | + Expect(tools.CreateSimServer([]*tools.SimServer{tc.Server})).To(BeNil()) |
| 28 | + |
| 29 | + // upstream server online |
| 30 | + Expect(tc.Server.Register(tc.Reg)).To(BeNil()) |
| 31 | + time.Sleep(3 * time.Second) |
| 32 | + status, body, err := common.Request(tc.URI) |
| 33 | + Expect(err).To(BeNil()) |
| 34 | + Expect(status).To(Equal(200)) |
| 35 | + Expect(body).To(Equal(tc.ExpectBody)) |
| 36 | + // upstream server offline |
| 37 | + Expect(tc.Server.LogOut(tc.Reg)).To(BeNil()) |
| 38 | + time.Sleep(3 * time.Second) |
| 39 | + status, _, err = common.Request(tc.URI) |
| 40 | + Expect(err).To(BeNil()) |
| 41 | + Expect(status).To(Equal(503)) |
| 42 | + }, |
| 43 | + Entry("Nacos", normalCase{ |
| 44 | + URI: "/test1", |
| 45 | + Route: tools.NewRoute("1", "/test1", "APISIX-NACOS", "nacos"), |
| 46 | + Server: tools.NewSimServer("0.0.0.0", "9990", "APISIX-NACOS"), |
| 47 | + Reg: tools.NewIRegCenter("nacos"), |
| 48 | + ExpectBody: "response: 0.0.0.0:9990", |
| 49 | + }), |
| 50 | + Entry("Zookeeper", normalCase{ |
| 51 | + URI: "/test2", |
| 52 | + Route: tools.NewRoute("2", "/test2", "APISIX-ZK", "zookeeper"), |
| 53 | + Server: tools.NewSimServer("0.0.0.0", "9991", "APISIX-ZK"), |
| 54 | + Reg: tools.NewIRegCenter("zookeeper"), |
| 55 | + ExpectBody: "response: 0.0.0.0:9991", |
| 56 | + }), |
| 57 | + ) |
| 58 | + }) |
| 59 | +}) |
0 commit comments