| 1 | package lb_domains_test |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | |
| 6 | . "github.com/onsi/ginkgo" |
| 7 | . "github.com/onsi/gomega" |
| 8 | |
| 9 | api "github.com/mimuret/golang-iij-dpf/pkg/api" |
| 10 | "github.com/mimuret/golang-iij-dpf/pkg/apis/dpf/v1/lb_domains" |
| 11 | ) |
| 12 | |
| 13 | var _ = Describe("MonitoringPorpsTCP", func() { |
| 14 | var ( |
| 15 | bs []byte |
| 16 | c lb_domains.MonitoringPorpsTCP |
| 17 | err error |
| 18 | s1, s2, s3 lb_domains.MonitoringPorpsTCP |
| 19 | ) |
| 20 | BeforeEach(func() { |
| 21 | s1 = lb_domains.MonitoringPorpsTCP{ |
| 22 | MonitoringPorpsCommon: lb_domains.MonitoringPorpsCommon{ |
| 23 | Location: lb_domains.MonitoringPropsLocationAll, |
| 24 | Interval: 30, |
| 25 | Holdtime: 0, |
| 26 | Timeout: 1, |
| 27 | }, |
| 28 | Port: 443, |
| 29 | TLSEnabled: true, |
| 30 | TLSSNI: "example.jp", |
| 31 | } |
| 32 | s2 = lb_domains.MonitoringPorpsTCP{ |
| 33 | MonitoringPorpsCommon: lb_domains.MonitoringPorpsCommon{ |
| 34 | Location: lb_domains.MonitoringPropsLocationJP, |
| 35 | Interval: 600, |
| 36 | Holdtime: 3600, |
| 37 | Timeout: 30, |
| 38 | }, |
| 39 | Port: 80, |
| 40 | TLSEnabled: false, |
| 41 | TLSSNI: "", |
| 42 | } |
| 43 | s3 = lb_domains.MonitoringPorpsTCP{ |
| 44 | Port: 53, |
| 45 | } |
| 46 | }) |
| 47 | Context("Read", func() { |
| 48 | Context("s1", func() { |
| 49 | BeforeEach(func() { |
| 50 | err = api.UnmarshalRead(json.RawMessage(`{ |
| 51 | "location": "all", |
| 52 | "interval": 30, |
| 53 | "holdtime": 0, |
| 54 | "timeout": 1, |
| 55 | "port": 443, |
| 56 | "tls_enabled": true, |
| 57 | "tls_sni": "example.jp" |
| 58 | }`), &c) |
| 59 | }) |
| 60 | It("succeed", func() { |
| 61 | Expect(err).To(Succeed()) |
| 62 | Expect(c).To(Equal(s1)) |
| 63 | }) |
| 64 | }) |
| 65 | Context("s2", func() { |
| 66 | BeforeEach(func() { |
| 67 | err = api.UnmarshalRead(json.RawMessage(`{ |
| 68 | "location": "jp", |
| 69 | "interval": 600, |
| 70 | "holdtime": 3600, |
| 71 | "timeout": 30, |
| 72 | "port": 80, |
| 73 | "tls_enabled": false, |
| 74 | "tls_sni": "" |
| 75 | }`), &c) |
| 76 | }) |
| 77 | It("succeed", func() { |
| 78 | Expect(err).To(Succeed()) |
| 79 | Expect(c).To(Equal(s2)) |
| 80 | }) |
| 81 | }) |
| 82 | }) |
| 83 | Context("Update", func() { |
| 84 | Context("s1", func() { |
| 85 | BeforeEach(func() { |
| 86 | bs, err = api.MarshalUpdate(s1) |
| 87 | }) |
| 88 | It("succeed", func() { |
| 89 | Expect(err).To(Succeed()) |
| 90 | Expect(bs).To(MatchJSON(`{ |
| 91 | "location": "all", |
| 92 | "interval": 30, |
| 93 | "holdtime": 0, |
| 94 | "timeout": 1, |
| 95 | "port": 443, |
| 96 | "tls_enabled": true, |
| 97 | "tls_sni": "example.jp" |
| 98 | }`)) |
| 99 | }) |
| 100 | }) |
| 101 | Context("s3", func() { |
| 102 | BeforeEach(func() { |
| 103 | bs, err = api.MarshalUpdate(s3) |
| 104 | }) |
| 105 | It("succeed", func() { |
| 106 | Expect(err).To(Succeed()) |
| 107 | Expect(bs).To(MatchJSON(`{ |
| 108 | "location": "", |
| 109 | "interval": 0, |
| 110 | "holdtime": 0, |
| 111 | "timeout": 0, |
| 112 | "port": 53, |
| 113 | "tls_enabled": false, |
| 114 | "tls_sni": "" |
| 115 | }`)) |
| 116 | }) |
| 117 | }) |
| 118 | }) |
| 119 | Context("Create", func() { |
| 120 | Context("s1", func() { |
| 121 | BeforeEach(func() { |
| 122 | bs, err = api.MarshalCreate(s1) |
| 123 | }) |
| 124 | It("succeed", func() { |
| 125 | Expect(err).To(Succeed()) |
| 126 | Expect(bs).To(MatchJSON(`{ |
| 127 | "location": "all", |
| 128 | "interval": 30, |
| 129 | "holdtime": 0, |
| 130 | "timeout": 1, |
| 131 | "port": 443, |
| 132 | "tls_enabled": true, |
| 133 | "tls_sni": "example.jp" |
| 134 | }`)) |
| 135 | }) |
| 136 | }) |
| 137 | Context("s3", func() { |
| 138 | BeforeEach(func() { |
| 139 | bs, err = api.MarshalCreate(s3) |
| 140 | }) |
| 141 | It("succeed", func() { |
| 142 | Expect(err).To(Succeed()) |
| 143 | Expect(bs).To(MatchJSON(`{ |
| 144 | "holdtime": 0, |
| 145 | "port": 53, |
| 146 | "tls_enabled": false |
| 147 | }`)) |
| 148 | }) |
| 149 | }) |
| 150 | }) |
| 151 | }) |