Debian Codegraph @

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

raw symbols SCIP
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/api"
12 "github.com/mimuret/golang-iij-dpf/pkg/apis/dpf/v1/zones"
13 "github.com/mimuret/golang-iij-dpf/pkg/testtool"
14 )
15
16 var _ = Describe("dnssec/ksk_rollover", func() {
17 var (
18 cl *testtool.TestClient
19 err error
20 reqId string
21 s1 zones.DnssecKskRollover
22 )
23 BeforeEach(func() {
24 cl = testtool.NewTestClient("", "http://localhost", nil)
25 s1 = zones.DnssecKskRollover{
26 AttributeMeta: zones.AttributeMeta{
27 ZoneID: "m1",
28 },
29 }
30 })
31 Describe("DnssecKskRollover", func() {
32 Context("Apply", func() {
33 id1, bs1 := testtool.CreateAsyncResponse()
34 BeforeEach(func() {
35 httpmock.RegisterResponder(http.MethodPatch, "http://localhost/zones/m1/dnssec/ksk_rollover", httpmock.NewBytesResponder(202, bs1))
36 reqId, err = cl.Apply(context.Background(), &s1, nil)
37 })
38 AfterEach(func() {
39 httpmock.Reset()
40 })
41 It("returns job_id", func() {
42 Expect(err).To(Succeed())
43 Expect(reqId).To(Equal(id1))
44 })
45 It("post json", func() {
46 Expect(cl.RequestBody["/zones/m1/dnssec/ksk_rollover"]).To(MatchJSON(`{}`))
47 })
48 })
49 Context("SetPathParams", func() {
50 When("no arguments, nothing to do", func() {
51 BeforeEach(func() {
52 err = s1.SetPathParams()
53 })
54 It("returns error", func() {
55 Expect(err).To(Succeed())
56 })
57 })
58 When("enough arguments", func() {
59 BeforeEach(func() {
60 err = s1.SetPathParams("m10")
61 })
62 It("not returns error", func() {
63 Expect(err).To(Succeed())
64 })
65 It("can set ContractID", func() {
66 Expect(s1.GetZoneID()).To(Equal("m10"))
67 })
68 })
69 When("arguments has extra value", func() {
70 BeforeEach(func() {
71 err = s1.SetPathParams("m10", 2)
72 })
73 It("returns error", func() {
74 Expect(err).To(HaveOccurred())
75 })
76 })
77 When("arguments type missmatch (ZoneID)", func() {
78 BeforeEach(func() {
79 err = s1.SetPathParams(2)
80 })
81 It("returns error", func() {
82 Expect(err).To(HaveOccurred())
83 })
84 })
85 })
86 Context("api.Spec common test", func() {
87 var nilSpec *zones.DnssecKskRollover
88 testtool.TestDeepCopyObject(&s1, nilSpec)
89 testtool.TestGetName(&s1, "dnssec/ksk_rollover")
90
91 Context("GetPathMethod", func() {
92 When("action is ActionApply", func() {
93 testtool.TestGetPathMethod(&s1, api.ActionApply, http.MethodPatch, "/zones/m1/dnssec/ksk_rollover")
94 })
95 When("action is other", func() {
96 testtool.TestGetPathMethod(&s1, api.ActionUpdate, "", "")
97 })
98 })
99 })
100 })
101 })