Debian Codegraph @

pkg/apis/dpf/v1/zones/managed_dns_test.go

raw
1 package zones_test
2
3 import (
4 "context"
5 "net/http"
6
7 . "github.com/onsi/ginkgo"
8 . "github.com/onsi/gomega"
9
10 "github.com/jarcoal/httpmock"
11 "github.com/mimuret/golang-iij-dpf/pkg/apis/dpf/v1/zones"
12 "github.com/mimuret/golang-iij-dpf/pkg/testtool"
13 )
14
15 var _ = Describe("managed_dns_servers", func() {
16 var (
17 c zones.ManagedDnsList
18 cl *testtool.TestClient
19 err error
20 reqId string
21 slist zones.ManagedDnsList
22 )
23 BeforeEach(func() {
24 cl = testtool.NewTestClient("", "http://localhost", nil)
25 slist = zones.ManagedDnsList{
26 AttributeMeta: zones.AttributeMeta{
27 ZoneID: "m1",
28 },
29 Items: []string{
30 "ns1.example.jp.",
31 "ns1.example.net.",
32 "ns1.example.com.",
33 },
34 }
35 })
36 Describe("ManagedDnsList", func() {
37 Context("List", func() {
38 BeforeEach(func() {
39 httpmock.RegisterResponder(http.MethodGet, "http://localhost/zones/m1/managed_dns_servers", httpmock.NewBytesResponder(200, []byte(`{
40 "request_id": "F4F8591B01B84EFBBA0AD17029DB7DA4",
41 "results": [
42 "ns1.example.jp.",
43 "ns1.example.net.",
44 "ns1.example.com."
45 ]
46 }`)))
47 })
48 AfterEach(func() {
49 httpmock.Reset()
50 })
51 When("returns managed_dns servers", func() {
52 BeforeEach(func() {
53 c = zones.ManagedDnsList{
54 AttributeMeta: zones.AttributeMeta{
55 ZoneID: "m1",
56 },
57 }
58 reqId, err = cl.List(context.Background(), &c, nil)
59 })
60 It("returns normal", func() {
61 Expect(err).To(Succeed())
62 Expect(reqId).To(Equal("F4F8591B01B84EFBBA0AD17029DB7DA4"))
63 Expect(c).To(Equal(slist))
64 })
65 })
66 })
67
68 Context("SetPathParams", func() {
69 When("no arguments, nothing to do", func() {
70 BeforeEach(func() {
71 err = slist.SetPathParams()
72 })
73 It("returns error", func() {
74 Expect(err).To(Succeed())
75 })
76 })
77 When("enough arguments", func() {
78 BeforeEach(func() {
79 err = slist.SetPathParams("m10")
80 })
81 It("not returns error", func() {
82 Expect(err).To(Succeed())
83 })
84 It("can set ZoneID", func() {
85 Expect(slist.GetZoneID()).To(Equal("m10"))
86 })
87 })
88 When("arguments has extra value", func() {
89 BeforeEach(func() {
90 err = slist.SetPathParams("m10", 2)
91 })
92 It("returns error", func() {
93 Expect(err).To(HaveOccurred())
94 })
95 })
96 When("arguments type missmatch (ZoneID)", func() {
97 BeforeEach(func() {
98 err = slist.SetPathParams(2)
99 })
100 It("returns error", func() {
101 Expect(err).To(HaveOccurred())
102 })
103 })
104 })
105 Context("api.Spec common test", func() {
106 var nilSpec *zones.ManagedDnsList
107 testtool.TestDeepCopyObject(&slist, nilSpec)
108 testtool.TestGetName(&slist, "managed_dns_servers")
109
110 testtool.TestGetPathMethodForList(&slist, "/zones/m1/managed_dns_servers")
111 })
112 Context("api.ListSpec common test", func() {
113 testtool.TestGetItems(&slist, &slist.Items)
114 testtool.TestLen(&slist, 3)
115 Context("Index", func() {
116 When("index exist", func() {
117 It("returns item", func() {
118 Expect(slist.Index(0)).To(Equal("ns1.example.jp."))
119 })
120 })
121 })
122 })
123 })
124 })