| 1 | package lb_domains_test |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | |
| 7 | "github.com/jarcoal/httpmock" |
| 8 | . "github.com/onsi/ginkgo" |
| 9 | . "github.com/onsi/gomega" |
| 10 | |
| 11 | "github.com/mimuret/golang-iij-dpf/pkg/apis/dpf/v1/lb_domains" |
| 12 | "github.com/mimuret/golang-iij-dpf/pkg/testtool" |
| 13 | ) |
| 14 | |
| 15 | var _ = Describe("EndpointManualFailover", func() { |
| 16 | var ( |
| 17 | cl *testtool.TestClient |
| 18 | err error |
| 19 | reqId string |
| 20 | ) |
| 21 | Describe("EndpointManualFailover", func() { |
| 22 | var s1 lb_domains.EndpointManualFailover |
| 23 | BeforeEach(func() { |
| 24 | cl = testtool.NewTestClient("", "http://localhost", nil) |
| 25 | s1 = lb_domains.EndpointManualFailover{ |
| 26 | SiteAttributeMeta: lb_domains.SiteAttributeMeta{ |
| 27 | AttributeMeta: lb_domains.AttributeMeta{ |
| 28 | LBDomainID: "b0000000000001", |
| 29 | }, |
| 30 | SiteResourceName: "site-1", |
| 31 | }, |
| 32 | EndpointResourceName: "endpoint-1", |
| 33 | } |
| 34 | }) |
| 35 | Context("Apply", func() { |
| 36 | id1, bs1 := testtool.CreateAsyncResponse() |
| 37 | BeforeEach(func() { |
| 38 | httpmock.RegisterResponder(http.MethodPost, "http://localhost/lb_domains/b0000000000001/sites/site-1/endpoints/endpoint-1/failover", httpmock.NewBytesResponder(202, bs1)) |
| 39 | reqId, err = cl.Apply(context.Background(), &s1, nil) |
| 40 | }) |
| 41 | AfterEach(func() { |
| 42 | httpmock.Reset() |
| 43 | }) |
| 44 | It("returns job_id", func() { |
| 45 | Expect(err).To(Succeed()) |
| 46 | Expect(reqId).To(Equal(id1)) |
| 47 | }) |
| 48 | It("post json", func() { |
| 49 | Expect(cl.RequestBody["/lb_domains/b0000000000001/sites/site-1/endpoints/endpoint-1/failover"]).To(MatchJSON(`{}`)) |
| 50 | }) |
| 51 | }) |
| 52 | Context("SetPathParams", func() { |
| 53 | When("no arguments, nothing to do", func() { |
| 54 | BeforeEach(func() { |
| 55 | err = s1.SetPathParams() |
| 56 | }) |
| 57 | It("returns error", func() { |
| 58 | Expect(err).To(Succeed()) |
| 59 | }) |
| 60 | }) |
| 61 | When("enough arguments", func() { |
| 62 | BeforeEach(func() { |
| 63 | err = s1.SetPathParams("b0000000000010", "site-1", "endpoint-1") |
| 64 | }) |
| 65 | It("not returns error", func() { |
| 66 | Expect(err).To(Succeed()) |
| 67 | }) |
| 68 | It("can set LBDomainID", func() { |
| 69 | Expect(s1.LBDomainID).To(Equal("b0000000000010")) |
| 70 | Expect(s1.SiteResourceName).To(Equal("site-1")) |
| 71 | Expect(s1.EndpointResourceName).To(Equal("endpoint-1")) |
| 72 | }) |
| 73 | }) |
| 74 | When("arguments has extra value", func() { |
| 75 | BeforeEach(func() { |
| 76 | err = s1.SetPathParams("b0000000000010", "site-1", "endpoint-1", 1) |
| 77 | }) |
| 78 | It("returns error", func() { |
| 79 | Expect(err).To(HaveOccurred()) |
| 80 | }) |
| 81 | }) |
| 82 | When("arguments type missmatch", func() { |
| 83 | BeforeEach(func() { |
| 84 | err = s1.SetPathParams("b0000000000010", "site-1", 1) |
| 85 | }) |
| 86 | It("returns error", func() { |
| 87 | Expect(err).To(HaveOccurred()) |
| 88 | }) |
| 89 | }) |
| 90 | }) |
| 91 | }) |
| 92 | Describe("EndpointManualFailback", func() { |
| 93 | var s1 lb_domains.EndpointManualFailback |
| 94 | BeforeEach(func() { |
| 95 | cl = testtool.NewTestClient("", "http://localhost", nil) |
| 96 | s1 = lb_domains.EndpointManualFailback{ |
| 97 | SiteAttributeMeta: lb_domains.SiteAttributeMeta{ |
| 98 | AttributeMeta: lb_domains.AttributeMeta{ |
| 99 | LBDomainID: "b0000000000001", |
| 100 | }, |
| 101 | SiteResourceName: "site-1", |
| 102 | }, |
| 103 | EndpointResourceName: "endpoint-1", |
| 104 | } |
| 105 | }) |
| 106 | Context("Apply", func() { |
| 107 | id1, bs1 := testtool.CreateAsyncResponse() |
| 108 | BeforeEach(func() { |
| 109 | httpmock.RegisterResponder(http.MethodPost, "http://localhost/lb_domains/b0000000000001/sites/site-1/endpoints/endpoint-1/failback", httpmock.NewBytesResponder(202, bs1)) |
| 110 | reqId, err = cl.Apply(context.Background(), &s1, nil) |
| 111 | }) |
| 112 | AfterEach(func() { |
| 113 | httpmock.Reset() |
| 114 | }) |
| 115 | It("returns job_id", func() { |
| 116 | Expect(err).To(Succeed()) |
| 117 | Expect(reqId).To(Equal(id1)) |
| 118 | }) |
| 119 | It("post json", func() { |
| 120 | Expect(cl.RequestBody["/lb_domains/b0000000000001/sites/site-1/endpoints/endpoint-1/failback"]).To(MatchJSON(`{}`)) |
| 121 | }) |
| 122 | }) |
| 123 | Context("SetPathParams", func() { |
| 124 | When("no arguments, nothing to do", func() { |
| 125 | BeforeEach(func() { |
| 126 | err = s1.SetPathParams() |
| 127 | }) |
| 128 | It("returns error", func() { |
| 129 | Expect(err).To(Succeed()) |
| 130 | }) |
| 131 | }) |
| 132 | When("enough arguments", func() { |
| 133 | BeforeEach(func() { |
| 134 | err = s1.SetPathParams("b0000000000010", "site-1", "endpoint-1") |
| 135 | }) |
| 136 | It("not returns error", func() { |
| 137 | Expect(err).To(Succeed()) |
| 138 | }) |
| 139 | It("can set LBDomainID", func() { |
| 140 | Expect(s1.LBDomainID).To(Equal("b0000000000010")) |
| 141 | Expect(s1.SiteResourceName).To(Equal("site-1")) |
| 142 | Expect(s1.EndpointResourceName).To(Equal("endpoint-1")) |
| 143 | }) |
| 144 | }) |
| 145 | When("arguments has extra value", func() { |
| 146 | BeforeEach(func() { |
| 147 | err = s1.SetPathParams("b0000000000010", "site-1", "endpoint-1", 1) |
| 148 | }) |
| 149 | It("returns error", func() { |
| 150 | Expect(err).To(HaveOccurred()) |
| 151 | }) |
| 152 | }) |
| 153 | When("arguments type missmatch", func() { |
| 154 | BeforeEach(func() { |
| 155 | err = s1.SetPathParams("b0000000000010", "site-1", 1) |
| 156 | }) |
| 157 | It("returns error", func() { |
| 158 | Expect(err).To(HaveOccurred()) |
| 159 | }) |
| 160 | }) |
| 161 | }) |
| 162 | }) |
| 163 | }) |