@@ -34,44 +34,39 @@ import (
3434)
3535
3636func Test_Deno_New (t * testing.T ) {
37- tests := []struct {
38- name string
37+ tests := map [string ]struct {
3938 expectedDeno * Deno
4039 }{
41- {
42- name : "New Deno instance" ,
40+ "New Deno instance" : {
4341 expectedDeno : & Deno {version : defaultVersion },
4442 },
4543 }
46- for _ , tc := range tests {
47- t .Run (tc . name , func (t * testing.T ) {
44+ for name , tc := range tests {
45+ t .Run (name , func (t * testing.T ) {
4846 d := New ()
4947 require .Equal (t , tc .expectedDeno , d )
5048 })
5149 }
5250}
5351
5452func Test_Deno_IgnoreDirectories (t * testing.T ) {
55- tests := []struct {
56- name string
53+ tests := map [string ]struct {
5754 expectedIgnoreDirectories []string
5855 }{
59- {
60- name : "No directories" ,
56+ "No directories" : {
6157 expectedIgnoreDirectories : []string {},
6258 },
6359 }
64- for _ , tc := range tests {
65- t .Run (tc . name , func (t * testing.T ) {
60+ for name , tc := range tests {
61+ t .Run (name , func (t * testing.T ) {
6662 d := New ()
6763 require .Equal (t , tc .expectedIgnoreDirectories , d .IgnoreDirectories ())
6864 })
6965 }
7066}
7167
7268func Test_Deno_InstallProjectDependencies (t * testing.T ) {
73- tests := []struct {
74- name string
69+ tests := map [string ]struct {
7570 projectDirPath string
7671 lookPathError error
7772 hookExecutorError error
@@ -80,8 +75,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) {
8075 expectedResponse string
8176 expectedHookExecutorCalls int
8277 }{
83- {
84- name : "Deno executable not found" ,
78+ "Deno executable not found" : {
8579 projectDirPath : "/path/to/project-name" ,
8680 lookPathError : exec .ErrNotFound ,
8781 hookExecutorError : nil ,
@@ -90,8 +84,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) {
9084 expectedResponse : "" ,
9185 expectedHookExecutorCalls : 0 ,
9286 },
93- {
94- name : "No manifest files" ,
87+ "No manifest files" : {
9588 projectDirPath : "/path/to/project-name" ,
9689 lookPathError : nil ,
9790 hookExecutorError : nil ,
@@ -100,8 +93,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) {
10093 expectedResponse : "" ,
10194 expectedHookExecutorCalls : 0 ,
10295 },
103- {
104- name : "InstallProjectDependencies cache dependencies when manifest file exists" ,
96+ "InstallProjectDependencies cache dependencies when manifest file exists" : {
10597 projectDirPath : "/path/to/project-name" ,
10698 lookPathError : nil ,
10799 hookExecutorError : nil ,
@@ -110,8 +102,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) {
110102 expectedResponse : "" ,
111103 expectedHookExecutorCalls : 1 , // Cache dependencies script executed
112104 },
113- {
114- name : "InstallProjectDependencies cache dependencies when multiple manifest files exist" ,
105+ "InstallProjectDependencies cache dependencies when multiple manifest files exist" : {
115106 projectDirPath : "/path/to/project-name" ,
116107 lookPathError : nil ,
117108 hookExecutorError : nil ,
@@ -120,8 +111,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) {
120111 expectedResponse : "" ,
121112 expectedHookExecutorCalls : 2 , // Cache dependencies script executed multiple times (manifest.ts, manifest.json)
122113 },
123- {
124- name : "InstallProjectDependencies should not error when cache dependencies fails" ,
114+ "InstallProjectDependencies should not error when cache dependencies fails" : {
125115 projectDirPath : "/path/to/project-name" ,
126116 lookPathError : nil ,
127117 hookExecutorError : slackerror .New (slackerror .ErrSDKHookNotFound ), // Cache dependencies script error
@@ -131,8 +121,8 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) {
131121 expectedHookExecutorCalls : 1 , // Cache dependencies script executed
132122 },
133123 }
134- for _ , tc := range tests {
135- t .Run (tc . name , func (t * testing.T ) {
124+ for name , tc := range tests {
125+ t .Run (name , func (t * testing.T ) {
136126 // Setup
137127 ctx := slackcontext .MockContext (t .Context ())
138128 projectDirPath := "/path/to/project-name"
@@ -181,53 +171,46 @@ func Test_Deno_Name(t *testing.T) {
181171}
182172
183173func Test_Deno_Version (t * testing.T ) {
184- tests := []struct {
185- name string
174+ tests := map [string ]struct {
186175 deno * Deno
187176 expectedVersion string
188177 }{
189- {
190- name : "Default version" ,
178+ "Default version" : {
191179 deno : New (),
192180 expectedVersion : defaultVersion ,
193181 },
194- {
195- name : "Custom version" ,
182+ "Custom version" : {
196183 deno : & Deno {version : "deno@2" },
197184 expectedVersion : "deno@2" ,
198185 },
199- {
200- name : "Undefined version" ,
186+ "Undefined version" : {
201187 deno : & Deno {version : "" },
202188 expectedVersion : defaultVersion ,
203189 },
204190 }
205- for _ , tc := range tests {
206- t .Run (tc . name , func (t * testing.T ) {
191+ for name , tc := range tests {
192+ t .Run (name , func (t * testing.T ) {
207193 require .Equal (t , tc .expectedVersion , tc .deno .Version ())
208194 })
209195 }
210196}
211197
212198func Test_Deno_SetVersion (t * testing.T ) {
213- tests := []struct {
214- name string
199+ tests := map [string ]struct {
215200 version string
216201 expectedVersion string
217202 }{
218- {
219- name : "Default version" ,
203+ "Default version" : {
220204 version : "" ,
221205 expectedVersion : defaultVersion ,
222206 },
223- {
224- name : "Custom version" ,
207+ "Custom version" : {
225208 version : "deno@2" ,
226209 expectedVersion : "deno@2" ,
227210 },
228211 }
229- for _ , tc := range tests {
230- t .Run (tc . name , func (t * testing.T ) {
212+ for name , tc := range tests {
213+ t .Run (name , func (t * testing.T ) {
231214 d := New ()
232215 d .SetVersion (tc .version )
233216 require .Equal (t , tc .expectedVersion , d .Version ())
@@ -236,24 +219,21 @@ func Test_Deno_SetVersion(t *testing.T) {
236219}
237220
238221func Test_Deno_HooksJSONTemplate (t * testing.T ) {
239- tests := []struct {
240- name string
222+ tests := map [string ]struct {
241223 hooksJSONTemplate []byte
242224 expectedErrorType error
243225 }{
244- {
245- name : "HooksJSONTemplate() should be valid JSON" ,
226+ "HooksJSONTemplate() should be valid JSON" : {
246227 hooksJSONTemplate : New ().HooksJSONTemplate (),
247228 expectedErrorType : nil ,
248229 },
249- {
250- name : "Should fail on invalid JSON" ,
230+ "Should fail on invalid JSON" : {
251231 hooksJSONTemplate : []byte (`}{` ),
252232 expectedErrorType : & json.SyntaxError {},
253233 },
254234 }
255- for _ , tc := range tests {
256- t .Run (tc . name , func (t * testing.T ) {
235+ for name , tc := range tests {
236+ t .Run (name , func (t * testing.T ) {
257237 // Setup
258238 var anyJSON map [string ]interface {}
259239
@@ -267,24 +247,21 @@ func Test_Deno_HooksJSONTemplate(t *testing.T) {
267247}
268248
269249func Test_Deno_PreparePackage (t * testing.T ) {
270- tests := []struct {
271- name string
250+ tests := map [string ]struct {
272251 hookExecutorError error
273252 expectedPreparePackageError error
274253 }{
275- {
276- name : "Hook successful" ,
254+ "Hook successful" : {
277255 hookExecutorError : nil ,
278256 expectedPreparePackageError : nil ,
279257 },
280- {
281- name : "Hook error" ,
258+ "Hook error" : {
282259 hookExecutorError : slackerror .New (slackerror .ErrSDKHookInvocationFailed ),
283260 expectedPreparePackageError : slackerror .New (slackerror .ErrSDKHookInvocationFailed ),
284261 },
285262 }
286- for _ , tc := range tests {
287- t .Run (tc . name , func (t * testing.T ) {
263+ for name , tc := range tests {
264+ t .Run (name , func (t * testing.T ) {
288265 ctx := slackcontext .MockContext (t .Context ())
289266
290267 // Setup SDKConfig
@@ -315,39 +292,34 @@ func Test_Deno_PreparePackage(t *testing.T) {
315292}
316293
317294func Test_Deno_IsRuntimeForProject (t * testing.T ) {
318- tests := []struct {
319- name string
295+ tests := map [string ]struct {
320296 sdkConfigRuntime string
321297 existingFilePaths []string
322298 expectedBool bool
323299 }{
324- {
325- name : "SDKConfig Runtime is Deno" ,
300+ "SDKConfig Runtime is Deno" : {
326301 sdkConfigRuntime : "deno" ,
327302 existingFilePaths : []string {}, // Unset to check SDKConfig
328303 expectedBool : true ,
329304 },
330- {
331- name : "deno.json file exists" ,
305+ "deno.json file exists" : {
332306 sdkConfigRuntime : "" , // Unset to check for file
333307 existingFilePaths : []string {"deno.json" },
334308 expectedBool : true ,
335309 },
336- {
337- name : "deno.jsonc file exists" ,
310+ "deno.jsonc file exists" : {
338311 sdkConfigRuntime : "" , // Unset to check for file
339312 existingFilePaths : []string {"deno.jsonc" },
340313 expectedBool : true ,
341314 },
342- {
343- name : "import_map.json file exists" ,
315+ "import_map.json file exists" : {
344316 sdkConfigRuntime : "" , // Unset to check for file
345317 existingFilePaths : []string {"import_map.json" },
346318 expectedBool : true ,
347319 },
348320 }
349- for _ , tc := range tests {
350- t .Run (tc . name , func (t * testing.T ) {
321+ for name , tc := range tests {
322+ t .Run (name , func (t * testing.T ) {
351323 // Setup
352324 ctx := slackcontext .MockContext (t .Context ())
353325 fs := slackdeps .NewFsMock ()
0 commit comments