Conditions | 4 |
Total Lines | 59 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* Vuls - Vulnerability Scanner |
||
184 | func TestContentConvertVinfos(t *testing.T) { |
||
185 | |||
186 | var tests = []struct { |
||
187 | in1 string |
||
188 | in2 WpStatus |
||
189 | expected []models.VulnInfo |
||
190 | }{ |
||
191 | { |
||
192 | in1: "{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\":\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecure\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04.000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type\":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot.fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://github.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wordpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": null}]}}", |
||
193 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
194 | expected: []models.VulnInfo{ |
||
195 | { |
||
196 | CveID: "CVE-2018-6389", |
||
197 | AffectedPackages: models.PackageStatuses{ |
||
198 | models.PackageStatus{ |
||
199 | NotFixedYet: true, |
||
200 | }, |
||
201 | }, |
||
202 | CveContents: models.NewCveContents( |
||
203 | models.CveContent{ |
||
204 | CveID: "CVE-2018-6389", |
||
205 | Title: "WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)", |
||
206 | }, |
||
207 | ), |
||
208 | }, |
||
209 | }, |
||
210 | }, |
||
211 | { |
||
212 | in1: "{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\":\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecure\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04.000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type\":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot.fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://github.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wordpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": \"1.0\"}]}}", |
||
213 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
214 | expected: nil, |
||
215 | }, |
||
216 | { |
||
217 | in1: "{\"4.9.4\":{\"release_date\":\"2018-02-06\",\"changelog_url\":\"https://codex.wordpress.org/Version_4.9.4\",\"status\":\"insecure\",\"vulnerabilities\":[{\"id\":9021,\"title\":\"WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)\",\"created_at\":\"2018-02-05T16:50:40.000Z\",\"updated_at\":\"2018-08-29T19:13:04.000Z\",\"published_date\":\"2018-02-05T00:00:00.000Z\",\"vuln_type\":\"DOS\",\"references\":{\"url\":[\"https://baraktawily.blogspot.fr/2018/02/how-to-dos-29-of-world-wide-websites.html\",\"https://github.com/quitten/doser.py\",\"https://thehackernews.com/2018/02/wordpress-dos-exploit.html\"],\"cve\":[\"2018-6389\"]},\"fixed_in\": \"1.2\"}]}}", |
||
218 | in2: WpStatus{Name: "twentyfifteen", Status: "inactive", Update: "available", Version: "1.1"}, |
||
219 | expected: []models.VulnInfo{ |
||
220 | { |
||
221 | CveID: "CVE-2018-6389", |
||
222 | AffectedPackages: models.PackageStatuses{ |
||
223 | models.PackageStatus{ |
||
224 | NotFixedYet: false, |
||
225 | }, |
||
226 | }, |
||
227 | CveContents: models.NewCveContents( |
||
228 | models.CveContent{ |
||
229 | CveID: "CVE-2018-6389", |
||
230 | Title: "WordPress <= 4.9.4 - Application Denial of Service (DoS) (unpatched)", |
||
231 | }, |
||
232 | ), |
||
233 | }, |
||
234 | }, |
||
235 | }, |
||
236 | } |
||
237 | for _, test := range tests { |
||
238 | actual, _ := contentConvertVinfos(test.in1, test.in2) |
||
239 | if !reflect.DeepEqual(test.expected, actual) { |
||
240 | h := pp.Sprint(actual) |
||
241 | k := pp.Sprint(test.expected) |
||
242 | t.Errorf("expected %v, actual %v", k, h) |
||
243 | } |
||
246 |