Conditions | 1 |
Total Lines | 60 |
Code Lines | 47 |
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 | //////////////////////////////////////////////////////////////////////////////// |
||
55 | func casesLogPrepareLog() []testsLogPrepareLog { |
||
56 | _, fileName, fileLine, _ := runtime.Caller(2) |
||
57 | now := time.Now() |
||
58 | configFirst := configProvider() |
||
59 | configFirst.TimeFormat = time.RFC3339 |
||
60 | configSecond := configProvider() |
||
61 | loggerErr := loggerProvider() |
||
62 | loggerErr.Strategies = append(loggerErr.Strategies, file.Get("")) |
||
63 | configSecond.Loggers = Map{ |
||
64 | Info: loggerProvider(), |
||
65 | Err: loggerErr, |
||
66 | } |
||
67 | return []testsLogPrepareLog{ |
||
68 | { |
||
69 | fields: &Log{ |
||
70 | config: configFirst, |
||
71 | }, |
||
72 | args: argsLogPrepareLog{ |
||
73 | time: now, |
||
74 | msg: testMsg, |
||
75 | skip: 2, |
||
76 | }, |
||
77 | want: fmt.Sprintf( |
||
78 | messageFormatWithFileLine, |
||
79 | now.Format(time.RFC3339), |
||
80 | fileName, |
||
81 | fileLine, |
||
82 | testMsg, |
||
83 | ), |
||
84 | }, |
||
85 | { |
||
86 | fields: &Log{ |
||
87 | config: configSecond, |
||
88 | }, |
||
89 | args: argsLogPrepareLog{ |
||
90 | time: now, |
||
91 | msg: testMsg, |
||
92 | skip: 2, |
||
93 | }, |
||
94 | want: fmt.Sprintf( |
||
95 | messageFormatWithFileLine, |
||
96 | now.Format(time.RFC3339Nano), |
||
97 | fileName, |
||
98 | fileLine, |
||
99 | testMsg, |
||
100 | ), |
||
101 | }, |
||
102 | { |
||
103 | fields: &Log{ |
||
104 | config: configSecond, |
||
105 | }, |
||
106 | args: argsLogPrepareLog{ |
||
107 | time: now, |
||
108 | msg: testMsg, |
||
109 | skip: 1000, |
||
110 | }, |
||
111 | want: fmt.Sprintf( |
||
112 | messageFormatDefault, |
||
113 | now.Format(time.RFC3339Nano), |
||
114 | testMsg, |
||
115 | ), |
||
165 |