Conditions | 3 |
Total Lines | 58 |
Code Lines | 42 |
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 mollie |
||
108 | func TestClientLinkService_GetFinalClientLink(t *testing.T) { |
||
109 | setEnv() |
||
110 | defer unsetEnv() |
||
111 | |||
112 | type args struct { |
||
113 | ctx context.Context |
||
114 | clientLink string |
||
115 | options *ClientLinkAuthorizeOptions |
||
116 | } |
||
117 | tests := []struct { |
||
118 | name string |
||
119 | args args |
||
120 | wantClientLinkURI string |
||
121 | }{ |
||
122 | { |
||
123 | "constructs client link finalize step correctly.", |
||
124 | args{ |
||
125 | context.Background(), |
||
126 | "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH", |
||
127 | &ClientLinkAuthorizeOptions{ |
||
128 | ClientID: "app_j9Pakf56Ajta6Y65AkdTtAv", |
||
129 | State: "unique_string_to_compare", |
||
130 | Scope: []PermissionGrant{OnboardingRead, OnboardingWrite}, |
||
131 | }, |
||
132 | }, |
||
133 | "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?clientId=app_j9Pakf56Ajta6Y65AkdTtAv&scope=onboarding.read%2Bonbording.write&state=unique_string_to_compare", |
||
134 | }, |
||
135 | { |
||
136 | "constructs client link finalize with complex values", |
||
137 | args{ |
||
138 | context.Background(), |
||
139 | "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH", |
||
140 | &ClientLinkAuthorizeOptions{ |
||
141 | ClientID: "", |
||
142 | State: "\ns\\s\\s\\s\n", |
||
143 | Scope: []PermissionGrant{}, |
||
144 | }, |
||
145 | }, |
||
146 | "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?state=%0As%5Cs%5Cs%5Cs%0A", |
||
147 | }, |
||
148 | { |
||
149 | "constructs client link finalize with no query params", |
||
150 | args{ |
||
151 | context.Background(), |
||
152 | "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH", |
||
153 | &ClientLinkAuthorizeOptions{}, |
||
154 | }, |
||
155 | "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?", |
||
156 | }, |
||
157 | } |
||
158 | |||
159 | setup() |
||
160 | defer teardown() |
||
161 | for _, tt := range tests { |
||
162 | t.Run(tt.name, func(t *testing.T) { |
||
163 | gotClientLinkURI := tClient.ClientLinks.GetFinalClientLink(tt.args.ctx, tt.args.clientLink, tt.args.options) |
||
164 | |||
165 | assert.Equal(t, tt.wantClientLinkURI, gotClientLinkURI) |
||
166 | }) |
||
169 |