| Conditions | 3 |
| Total Lines | 69 |
| Code Lines | 44 |
| 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 | package application |
||
| 14 | func TestExecute_ValidArguments_NoError(t *testing.T) { |
||
| 15 | tests := []struct { |
||
| 16 | name string |
||
| 17 | arguments []string |
||
| 18 | }{ |
||
| 19 | { |
||
| 20 | "serve command with short url", |
||
| 21 | []string{ |
||
| 22 | "serve", |
||
| 23 | "-u", |
||
| 24 | testSpecificationURL, |
||
| 25 | }, |
||
| 26 | }, |
||
| 27 | { |
||
| 28 | "serve command with long url", |
||
| 29 | []string{ |
||
| 30 | "serve", |
||
| 31 | "--specification-url", |
||
| 32 | testSpecificationURL, |
||
| 33 | }, |
||
| 34 | }, |
||
| 35 | { |
||
| 36 | "serve command with url from config (short)", |
||
| 37 | []string{ |
||
| 38 | "serve", |
||
| 39 | "-c", |
||
| 40 | testConfigFilename, |
||
| 41 | }, |
||
| 42 | }, |
||
| 43 | { |
||
| 44 | "serve command with url from config (long)", |
||
| 45 | []string{ |
||
| 46 | "serve", |
||
| 47 | "--configuration", |
||
| 48 | testConfigFilename, |
||
| 49 | }, |
||
| 50 | }, |
||
| 51 | { |
||
| 52 | "validate command with short url", |
||
| 53 | []string{ |
||
| 54 | "validate", |
||
| 55 | "-u", |
||
| 56 | testSpecificationURL, |
||
| 57 | }, |
||
| 58 | }, |
||
| 59 | { |
||
| 60 | "validate command with long url", |
||
| 61 | []string{ |
||
| 62 | "validate", |
||
| 63 | "--specification-url", |
||
| 64 | testSpecificationURL, |
||
| 65 | }, |
||
| 66 | }, |
||
| 67 | { |
||
| 68 | "help command with short argument", |
||
| 69 | []string{"-h"}, |
||
| 70 | }, |
||
| 71 | { |
||
| 72 | "help command with long argument", |
||
| 73 | []string{"--help"}, |
||
| 74 | }, |
||
| 75 | } |
||
| 76 | for _, test := range tests { |
||
| 77 | t.Run(test.name, func(t *testing.T) { |
||
| 78 | args := append(test.arguments, "--dry-run") |
||
| 79 | |||
| 80 | err := Execute(Arguments(args)) |
||
| 81 | |||
| 82 | assert.NoError(t, err) |
||
| 83 | }) |
||
| 109 |