Debian Codegraph @

pkg/apis/dpf/v1/core/log_test.go

raw
1 package core_test
2
3 import (
4 "net/url"
5 "time"
6
7 . "github.com/onsi/ginkgo"
8 . "github.com/onsi/gomega"
9
10 "github.com/mimuret/golang-iij-dpf/pkg/api"
11 "github.com/mimuret/golang-iij-dpf/pkg/apis/dpf/v1/core"
12 "github.com/mimuret/golang-iij-dpf/pkg/types"
13 )
14
15 var _ = Describe("log", func() {
16 var (
17 err error
18 s1 core.Log
19 atTime types.Time
20 )
21 BeforeEach(func() {
22 atTime, err = types.ParseTime(time.RFC3339Nano, "2021-06-20T13:21:12.881Z")
23 Expect(err).To(Succeed())
24 s1 = core.Log{
25 Time: atTime,
26 LogType: "service",
27 Operator: "user1",
28 Operation: "add_cc_primary",
29 Target: "1",
30 Status: core.LogStatusStart,
31 }
32 })
33 Describe("Log", func() {
34 Context("DeepCopy", func() {
35 var (
36 copy *core.Log
37 nilMeta *core.Log
38 )
39 When("Log is not nil", func() {
40 BeforeEach(func() {
41 copy = s1.DeepCopy()
42 })
43 It("returns copy ", func() {
44 Expect(copy).To(Equal(&s1))
45 })
46 })
47 When("Log is nil", func() {
48 BeforeEach(func() {
49 copy = nilMeta.DeepCopy()
50 })
51 It("returns copy ", func() {
52 Expect(copy).To(BeNil())
53 })
54 })
55 })
56 })
57 Describe("LogStatus", func() {
58 Context("String", func() {
59 It("returns string", func() {
60 Expect(core.LogStatusStart.String()).To(Equal("start"))
61 })
62 })
63 })
64 Describe("SearchLogsOffset", func() {
65 Context("Validate", func() {
66 When("value < 0", func() {
67 It("returns false", func() {
68 Expect(core.SearchLogsOffset(-1).Validate()).To(BeFalse())
69 })
70 })
71 When("normal", func() {
72 It("returns true", func() {
73 Expect(core.SearchLogsOffset(0).Validate()).To(BeTrue())
74 Expect(core.SearchLogsOffset(9900).Validate()).To(BeTrue())
75 })
76 })
77 When("value > 9900", func() {
78 It("returns false", func() {
79 Expect(core.SearchLogsOffset(9901).Validate()).To(BeFalse())
80 })
81 })
82 })
83 })
84 Describe("SearchLogsLimit", func() {
85 Context("Validate", func() {
86 When("value < 0", func() {
87 It("returns false", func() {
88 Expect(core.SearchLogsLimit(0).Validate()).To(BeFalse())
89 Expect(core.SearchLogsLimit(-1).Validate()).To(BeFalse())
90 })
91 })
92 When("normal", func() {
93 It("returns true", func() {
94 Expect(core.SearchLogsLimit(1).Validate()).To(BeTrue())
95 Expect(core.SearchLogsLimit(100).Validate()).To(BeTrue())
96 })
97 })
98 When("value > 9900", func() {
99 It("returns false", func() {
100 Expect(core.SearchLogsLimit(101).Validate()).To(BeFalse())
101 })
102 })
103 })
104 })
105 Describe("TestLogListSearchKeywords", func() {
106 Context("GetValues", func() {
107 testcase := []struct {
108 keyword core.LogListSearchKeywords
109 values url.Values
110 }{
111 {
112 core.LogListSearchKeywords{
113 CommonSearchParams: api.CommonSearchParams{
114 Type: api.SearchTypeAND,
115 Offset: int32(10),
116 Limit: int32(100),
117 },
118 },
119 url.Values{
120 "type": []string{"AND"},
121 "offset": []string{"10"},
122 "limit": []string{"100"},
123 },
124 },
125 {
126 core.LogListSearchKeywords{
127 CommonSearchParams: api.CommonSearchParams{
128 Type: api.SearchTypeOR,
129 Offset: int32(10),
130 Limit: int32(100),
131 },
132 FullText: api.KeywordsString{"hogehoge", "🐰"},
133 LogType: api.KeywordsString{"service", "record", "dnssec"},
134 Operator: api.KeywordsString{"[email protected]", "SA0000000"},
135 Operation: api.KeywordsString{"updating_default_ttl", "dismiss_zone_edits"},
136 Target: api.KeywordsString{"hoge", "fuga"},
137 Detail: api.KeywordsString{"🐇", "🍺"},
138 RequestID: api.KeywordsString{"f02fe1e1404140cab93c8f7af26081b7", "f098f808cde249d48a885490f7622df9"},
139 Status: core.KeywordsLogStatus{core.LogStatusStart, core.LogStatusSuccess, core.LogStatusFailure, core.LogStatusRetry},
140 },
141 /*
142 _keywords_full_text[]
143 _keywords_log_type[]
144 _keywords_operator[]
145 _keywords_operation[]
146 _keywords_target[]
147 _keywords_detail[]
148 _keywords_request_id[]
149 _keywords_status[]
150
151 */
152 url.Values{
153 "type": []string{"OR"},
154 "offset": []string{"10"},
155 "limit": []string{"100"},
156 "_keywords_full_text[]": []string{"hogehoge", "🐰"},
157 "_keywords_log_type[]": []string{"service", "record", "dnssec"},
158 "_keywords_operator[]": []string{"[email protected]", "SA0000000"},
159 "_keywords_operation[]": []string{"updating_default_ttl", "dismiss_zone_edits"},
160 "_keywords_target[]": []string{"hoge", "fuga"},
161 "_keywords_detail[]": []string{"🐇", "🍺"},
162 "_keywords_request_id[]": []string{"f02fe1e1404140cab93c8f7af26081b7", "f098f808cde249d48a885490f7622df9"},
163 "_keywords_status[]": []string{"start", "success", "failure", "retry"},
164 },
165 },
166 }
167 It("can convert url.Value", func() {
168 for _, tc := range testcase {
169 s, err := tc.keyword.GetValues()
170 Expect(err).To(Succeed())
171 Expect(s).To(Equal(tc.values))
172 }
173 })
174 })
175 })
176 })