diff --git a/internal/runtime/deno/deno_test.go b/internal/runtime/deno/deno_test.go index 4e507cb..6d58343 100644 --- a/internal/runtime/deno/deno_test.go +++ b/internal/runtime/deno/deno_test.go @@ -34,17 +34,15 @@ import ( ) func Test_Deno_New(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedDeno *Deno }{ - { - name: "New Deno instance", + "New Deno instance": { expectedDeno: &Deno{version: defaultVersion}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { d := New() require.Equal(t, tc.expectedDeno, d) }) @@ -52,17 +50,15 @@ func Test_Deno_New(t *testing.T) { } func Test_Deno_IgnoreDirectories(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedIgnoreDirectories []string }{ - { - name: "No directories", + "No directories": { expectedIgnoreDirectories: []string{}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { d := New() require.Equal(t, tc.expectedIgnoreDirectories, d.IgnoreDirectories()) }) @@ -70,8 +66,7 @@ func Test_Deno_IgnoreDirectories(t *testing.T) { } func Test_Deno_InstallProjectDependencies(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { projectDirPath string lookPathError error hookExecutorError error @@ -80,8 +75,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) { expectedResponse string expectedHookExecutorCalls int }{ - { - name: "Deno executable not found", + "Deno executable not found": { projectDirPath: "/path/to/project-name", lookPathError: exec.ErrNotFound, hookExecutorError: nil, @@ -90,8 +84,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) { expectedResponse: "", expectedHookExecutorCalls: 0, }, - { - name: "No manifest files", + "No manifest files": { projectDirPath: "/path/to/project-name", lookPathError: nil, hookExecutorError: nil, @@ -100,8 +93,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) { expectedResponse: "", expectedHookExecutorCalls: 0, }, - { - name: "InstallProjectDependencies cache dependencies when manifest file exists", + "InstallProjectDependencies cache dependencies when manifest file exists": { projectDirPath: "/path/to/project-name", lookPathError: nil, hookExecutorError: nil, @@ -110,8 +102,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) { expectedResponse: "", expectedHookExecutorCalls: 1, // Cache dependencies script executed }, - { - name: "InstallProjectDependencies cache dependencies when multiple manifest files exist", + "InstallProjectDependencies cache dependencies when multiple manifest files exist": { projectDirPath: "/path/to/project-name", lookPathError: nil, hookExecutorError: nil, @@ -120,8 +111,7 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) { expectedResponse: "", expectedHookExecutorCalls: 2, // Cache dependencies script executed multiple times (manifest.ts, manifest.json) }, - { - name: "InstallProjectDependencies should not error when cache dependencies fails", + "InstallProjectDependencies should not error when cache dependencies fails": { projectDirPath: "/path/to/project-name", lookPathError: nil, hookExecutorError: slackerror.New(slackerror.ErrSDKHookNotFound), // Cache dependencies script error @@ -131,8 +121,8 @@ func Test_Deno_InstallProjectDependencies(t *testing.T) { expectedHookExecutorCalls: 1, // Cache dependencies script executed }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup ctx := slackcontext.MockContext(t.Context()) projectDirPath := "/path/to/project-name" @@ -181,53 +171,46 @@ func Test_Deno_Name(t *testing.T) { } func Test_Deno_Version(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { deno *Deno expectedVersion string }{ - { - name: "Default version", + "Default version": { deno: New(), expectedVersion: defaultVersion, }, - { - name: "Custom version", + "Custom version": { deno: &Deno{version: "deno@2"}, expectedVersion: "deno@2", }, - { - name: "Undefined version", + "Undefined version": { deno: &Deno{version: ""}, expectedVersion: defaultVersion, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { require.Equal(t, tc.expectedVersion, tc.deno.Version()) }) } } func Test_Deno_SetVersion(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { version string expectedVersion string }{ - { - name: "Default version", + "Default version": { version: "", expectedVersion: defaultVersion, }, - { - name: "Custom version", + "Custom version": { version: "deno@2", expectedVersion: "deno@2", }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { d := New() d.SetVersion(tc.version) require.Equal(t, tc.expectedVersion, d.Version()) @@ -236,24 +219,21 @@ func Test_Deno_SetVersion(t *testing.T) { } func Test_Deno_HooksJSONTemplate(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { hooksJSONTemplate []byte expectedErrorType error }{ - { - name: "HooksJSONTemplate() should be valid JSON", + "HooksJSONTemplate() should be valid JSON": { hooksJSONTemplate: New().HooksJSONTemplate(), expectedErrorType: nil, }, - { - name: "Should fail on invalid JSON", + "Should fail on invalid JSON": { hooksJSONTemplate: []byte(`}{`), expectedErrorType: &json.SyntaxError{}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup var anyJSON map[string]interface{} @@ -267,24 +247,21 @@ func Test_Deno_HooksJSONTemplate(t *testing.T) { } func Test_Deno_PreparePackage(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { hookExecutorError error expectedPreparePackageError error }{ - { - name: "Hook successful", + "Hook successful": { hookExecutorError: nil, expectedPreparePackageError: nil, }, - { - name: "Hook error", + "Hook error": { hookExecutorError: slackerror.New(slackerror.ErrSDKHookInvocationFailed), expectedPreparePackageError: slackerror.New(slackerror.ErrSDKHookInvocationFailed), }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { ctx := slackcontext.MockContext(t.Context()) // Setup SDKConfig @@ -315,39 +292,34 @@ func Test_Deno_PreparePackage(t *testing.T) { } func Test_Deno_IsRuntimeForProject(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { sdkConfigRuntime string existingFilePaths []string expectedBool bool }{ - { - name: "SDKConfig Runtime is Deno", + "SDKConfig Runtime is Deno": { sdkConfigRuntime: "deno", existingFilePaths: []string{}, // Unset to check SDKConfig expectedBool: true, }, - { - name: "deno.json file exists", + "deno.json file exists": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{"deno.json"}, expectedBool: true, }, - { - name: "deno.jsonc file exists", + "deno.jsonc file exists": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{"deno.jsonc"}, expectedBool: true, }, - { - name: "import_map.json file exists", + "import_map.json file exists": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{"import_map.json"}, expectedBool: true, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup ctx := slackcontext.MockContext(t.Context()) fs := slackdeps.NewFsMock() diff --git a/internal/runtime/node/node_test.go b/internal/runtime/node/node_test.go index ebfb2e5..2ba8706 100644 --- a/internal/runtime/node/node_test.go +++ b/internal/runtime/node/node_test.go @@ -33,17 +33,15 @@ import ( ) func Test_Node_New(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedNode *Node }{ - { - name: "New Node instance", + "New Node instance": { expectedNode: &Node{}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name := range tests { + t.Run(name, func(t *testing.T) { n := New() require.IsType(t, Node{}, *n) }) @@ -51,17 +49,15 @@ func Test_Node_New(t *testing.T) { } func Test_Node_IgnoreDirectories(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedIgnoreDirectories []string }{ - { - name: "Ignore node modules", + "Ignore node modules": { expectedIgnoreDirectories: []string{"node_modules"}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { n := New() require.Equal(t, tc.expectedIgnoreDirectories, n.IgnoreDirectories()) }) @@ -69,8 +65,7 @@ func Test_Node_IgnoreDirectories(t *testing.T) { } func Test_Node_InstallProjectDependencies(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { hookExecutorError []error hookInstallationStdout string hookInstallationStderr string @@ -79,8 +74,7 @@ func Test_Node_InstallProjectDependencies(t *testing.T) { expectedOutputs []string npmMock func() NPM }{ - { - name: "When @slack/cli-hooks found then skip installing it and continue", + "When @slack/cli-hooks found then skip installing it and continue": { expectedOutputs: []string{ "Found package @slack/cli-hooks@1.1.2", "Installed dependencies", @@ -95,8 +89,7 @@ func Test_Node_InstallProjectDependencies(t *testing.T) { return npmMock }, }, - { - name: "When @slack/cli-hooks not found then install it and continue", + "When @slack/cli-hooks not found then install it and continue": { expectedOutputs: []string{ "Added package @slack/cli-hooks@1.1.2", "Installed dependencies", @@ -115,8 +108,7 @@ func Test_Node_InstallProjectDependencies(t *testing.T) { return npmMock }, }, - { - name: "When @slack/cli-hooks install fails then error and continue", + "When @slack/cli-hooks install fails then error and continue": { expectedOutputs: []string{ "Error adding package @slack/cli-hooks", "Installed dependencies", @@ -135,8 +127,7 @@ func Test_Node_InstallProjectDependencies(t *testing.T) { return npmMock }, }, - { - name: "When npm install successful", + "When npm install successful": { expectedOutputs: []string{ "Found package @slack/cli-hooks@1.1.2", "Installed dependencies", @@ -151,8 +142,7 @@ func Test_Node_InstallProjectDependencies(t *testing.T) { return npmMock }, }, - { - name: "When npm install fails return error", + "When npm install fails return error": { expectedOutputs: []string{ "Found package @slack/cli-hooks@1.1.2", "Error installing dependencies", @@ -167,8 +157,7 @@ func Test_Node_InstallProjectDependencies(t *testing.T) { return npmMock }, }, - { - name: "When @slack/cli-hooks and npm install both fail return first error", + "When @slack/cli-hooks and npm install both fail return first error": { expectedOutputs: []string{ "Error adding package @slack/cli-hooks", "Error installing dependencies", @@ -188,8 +177,8 @@ func Test_Node_InstallProjectDependencies(t *testing.T) { }, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup ctx := slackcontext.MockContext(t.Context()) projectDirPath := "/path/to/project-name" @@ -222,17 +211,15 @@ func Test_Node_Name(t *testing.T) { } func Test_Node_Version(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedVersion string }{ - { - name: "Default version", + "Default version": { expectedVersion: "node", }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { n := New() require.Equal(t, tc.expectedVersion, n.Version()) }) @@ -247,24 +234,21 @@ func Test_Node_SetVersion(t *testing.T) { } func Test_Node_HooksJSONTemplate(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { hooksJSONTemplate []byte expectedErrorType error }{ - { - name: "HooksJSONTemplate() should be valid JSON", + "HooksJSONTemplate() should be valid JSON": { hooksJSONTemplate: New().HooksJSONTemplate(), expectedErrorType: nil, }, - { - name: "Should fail on invalid JSON", + "Should fail on invalid JSON": { hooksJSONTemplate: []byte(`}{`), expectedErrorType: &json.SyntaxError{}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup var anyJSON map[string]interface{} @@ -278,19 +262,17 @@ func Test_Node_HooksJSONTemplate(t *testing.T) { } func Test_Node_PreparePackage(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { hookExecutorError error expectedPreparePackageError error }{ - { - name: "Should return no error because unsupported", + "Should return no error because unsupported": { hookExecutorError: nil, expectedPreparePackageError: nil, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { ctx := slackcontext.MockContext(t.Context()) // Setup SDKConfig @@ -321,33 +303,29 @@ func Test_Node_PreparePackage(t *testing.T) { } func Test_Node_IsRuntimeForProject(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { sdkConfigRuntime string existingFilePaths []string expectedBool bool }{ - { - name: "Not a Node.js project", + "Not a Node.js project": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{}, expectedBool: false, }, - { - name: "SDKConfig Runtime is Node.js", + "SDKConfig Runtime is Node.js": { sdkConfigRuntime: "node", existingFilePaths: []string{}, // Unset to check SDKConfig expectedBool: true, }, - { - name: "package.json file exists", + "package.json file exists": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{"package.json"}, expectedBool: true, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup ctx := slackcontext.MockContext(t.Context()) fs := slackdeps.NewFsMock() diff --git a/internal/runtime/python/python_test.go b/internal/runtime/python/python_test.go index 1ae9df5..84b74c3 100644 --- a/internal/runtime/python/python_test.go +++ b/internal/runtime/python/python_test.go @@ -32,17 +32,15 @@ import ( ) func Test_Python_New(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedPython *Python }{ - { - name: "New Python instance", + "New Python instance": { expectedPython: &Python{}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { p := New() require.Equal(t, tc.expectedPython, p) }) @@ -50,17 +48,15 @@ func Test_Python_New(t *testing.T) { } func Test_Python_IgnoreDirectories(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedIgnoreDirectories []string }{ - { - name: "No directories", + "No directories": { expectedIgnoreDirectories: []string{}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { p := New() require.Equal(t, tc.expectedIgnoreDirectories, p.IgnoreDirectories()) }) @@ -68,22 +64,19 @@ func Test_Python_IgnoreDirectories(t *testing.T) { } func Test_Python_InstallProjectDependencies(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { existingFiles map[string]string expectedFiles map[string]string expectedOutputs []string notExpectedOutputs []string expectedError bool }{ - { - name: "Error when requirements.txt is missing", + "Error when requirements.txt is missing": { existingFiles: map[string]string{}, // No files expectedOutputs: []string{"Error"}, expectedError: true, }, - { - name: "Skip when requirements.txt contains slack-cli-hooks", + "Skip when requirements.txt contains slack-cli-hooks": { existingFiles: map[string]string{ "requirements.txt": "slack-cli-hooks\npytest==8.3.2\nruff==0.7.2", }, @@ -93,8 +86,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { expectedOutputs: []string{"Found"}, expectedError: false, }, - { - name: "Skip when requirements.txt contains slack-cli-hooks<1.0.0", + "Skip when requirements.txt contains slack-cli-hooks<1.0.0": { existingFiles: map[string]string{ "requirements.txt": "slack-cli-hooks<1.0.0\npytest==8.3.2\nruff==0.7.2", }, @@ -104,8 +96,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { expectedOutputs: []string{"Found"}, expectedError: false, }, - { - name: "Update when requirements.txt contain slack-bolt at top of file", + "Update when requirements.txt contain slack-bolt at top of file": { existingFiles: map[string]string{ "requirements.txt": "slack-bolt==2.31.2\npytest==8.3.2\nruff==0.7.2", }, @@ -115,8 +106,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { expectedOutputs: []string{"Updated"}, expectedError: false, }, - { - name: "Update when requirements.txt contain slack-bolt at middle of file", + "Update when requirements.txt contain slack-bolt at middle of file": { existingFiles: map[string]string{ "requirements.txt": "pytest==8.3.2\nslack-bolt==2.31.2\nruff==0.7.2", }, @@ -126,8 +116,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { expectedOutputs: []string{"Updated"}, expectedError: false, }, - { - name: "Update when requirements.txt contain slack-bolt at bottom of file", + "Update when requirements.txt contain slack-bolt at bottom of file": { existingFiles: map[string]string{ "requirements.txt": "pytest==8.3.2\nruff==0.7.2\nslack-bolt==2.31.2", }, @@ -137,8 +126,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { expectedOutputs: []string{"Updated"}, expectedError: false, }, - { - name: "Update when requirements.txt does not contain slack-bolt", + "Update when requirements.txt does not contain slack-bolt": { existingFiles: map[string]string{ "requirements.txt": "pytest==8.3.2\nruff==0.7.2", }, @@ -148,8 +136,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { expectedOutputs: []string{"Updated"}, expectedError: false, }, - { - name: "Update when requirements.txt with trailing whitespace does not contain slack-bolt", + "Update when requirements.txt with trailing whitespace does not contain slack-bolt": { existingFiles: map[string]string{ "requirements.txt": "pytest==8.3.2\nruff==0.7.2\n\n\n ", }, @@ -159,16 +146,14 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { expectedOutputs: []string{"Updated"}, expectedError: false, }, - { - name: "Should output help text because installing project dependencies is unsupported", + "Should output help text because installing project dependencies is unsupported": { existingFiles: map[string]string{ "requirements.txt": "slack-cli-hooks\npytest==8.3.2\nruff==0.7.2", }, expectedOutputs: []string{"Manually setup a Python virtual environment"}, expectedError: false, }, - { - name: "Should output pip install -r requirements.txt when only requirements.txt exists", + "Should output pip install -r requirements.txt when only requirements.txt exists": { existingFiles: map[string]string{ "requirements.txt": "slack-cli-hooks\npytest==8.3.2", }, @@ -176,8 +161,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) { notExpectedOutputs: []string{"pip install -e ."}, expectedError: false, }, - { - name: "Should output pip install -e . when only pyproject.toml exists", + "Should output pip install -e . when only pyproject.toml exists": { existingFiles: map[string]string{ "pyproject.toml": `[project] name = "my-app" @@ -187,8 +171,7 @@ dependencies = ["slack-cli-hooks<1.0.0"]`, notExpectedOutputs: []string{"pip install -r requirements.txt"}, expectedError: false, }, - { - name: "Should output both install commands when both files exist", + "Should output both install commands when both files exist": { existingFiles: map[string]string{ "requirements.txt": "slack-cli-hooks\npytest==8.3.2", "pyproject.toml": `[project] @@ -198,16 +181,14 @@ dependencies = ["slack-cli-hooks<1.0.0"]`, expectedOutputs: []string{"pip install -r requirements.txt", "pip install -e ."}, expectedError: false, }, - { - name: "Error when neither requirements.txt nor pyproject.toml exists", + "Error when neither requirements.txt nor pyproject.toml exists": { existingFiles: map[string]string{ "main.py": "# some python code", }, expectedOutputs: []string{"Error: no Python dependency file found"}, expectedError: true, }, - { - name: "Skip when pyproject.toml contains slack-cli-hooks", + "Skip when pyproject.toml contains slack-cli-hooks": { existingFiles: map[string]string{ "pyproject.toml": `[project] name = "my-app" @@ -227,8 +208,7 @@ dependencies = [ expectedOutputs: []string{"Found pyproject.toml"}, expectedError: false, }, - { - name: "Update when pyproject.toml contains slack-bolt", + "Update when pyproject.toml contains slack-bolt": { existingFiles: map[string]string{ "pyproject.toml": `[project] name = "my-app" @@ -249,8 +229,7 @@ dependencies = [ expectedOutputs: []string{"Updated pyproject.toml"}, expectedError: false, }, - { - name: "Update when pyproject.toml does not contain slack-bolt", + "Update when pyproject.toml does not contain slack-bolt": { existingFiles: map[string]string{ "pyproject.toml": `[project] name = "my-app" @@ -269,8 +248,7 @@ dependencies = [ expectedOutputs: []string{"Updated pyproject.toml"}, expectedError: false, }, - { - name: "Update both requirements.txt and pyproject.toml when both exist", + "Update both requirements.txt and pyproject.toml when both exist": { existingFiles: map[string]string{ "requirements.txt": "slack-bolt==2.31.2\npytest==8.3.2", "pyproject.toml": `[project] @@ -291,8 +269,7 @@ dependencies = [ expectedOutputs: []string{"Updated requirements.txt"}, expectedError: false, }, - { - name: "Error when pyproject.toml has no dependencies array", + "Error when pyproject.toml has no dependencies array": { existingFiles: map[string]string{ "pyproject.toml": `[project] name = "my-app"`, @@ -300,8 +277,7 @@ name = "my-app"`, expectedOutputs: []string{"Error: pyproject.toml missing dependencies array"}, expectedError: true, }, - { - name: "Error when pyproject.toml has no [project] section", + "Error when pyproject.toml has no [project] section": { existingFiles: map[string]string{ "pyproject.toml": `[tool.black] line-length = 88`, @@ -309,8 +285,7 @@ line-length = 88`, expectedOutputs: []string{"Error: pyproject.toml missing project section"}, expectedError: true, }, - { - name: "Error when pyproject.toml is invalid TOML", + "Error when pyproject.toml is invalid TOML": { existingFiles: map[string]string{ "pyproject.toml": `[project name = "broken`, @@ -319,8 +294,8 @@ name = "broken`, expectedError: true, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup ctx := slackcontext.MockContext(t.Context()) fs := slackdeps.NewFsMock() @@ -382,17 +357,15 @@ func Test_Python_Name(t *testing.T) { } func Test_Python_Version(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { expectedVersion string }{ - { - name: "Default version", + "Default version": { expectedVersion: "python", }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { p := New() require.Equal(t, tc.expectedVersion, p.Version()) }) @@ -407,24 +380,21 @@ func Test_Python_SetVersion(t *testing.T) { } func Test_Python_HooksJSONTemplate(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { hooksJSONTemplate []byte expectedErrorType error }{ - { - name: "HooksJSONTemplate() should be valid JSON", + "HooksJSONTemplate() should be valid JSON": { hooksJSONTemplate: New().HooksJSONTemplate(), expectedErrorType: nil, }, - { - name: "Should fail on invalid JSON", + "Should fail on invalid JSON": { hooksJSONTemplate: []byte(`}{`), expectedErrorType: &json.SyntaxError{}, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup var anyJSON map[string]interface{} @@ -438,19 +408,17 @@ func Test_Python_HooksJSONTemplate(t *testing.T) { } func Test_Python_PreparePackage(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { hookExecutorError error expectedPreparePackageError error }{ - { - name: "Should return no error because unsupported", + "Should return no error because unsupported": { hookExecutorError: nil, expectedPreparePackageError: nil, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { ctx := slackcontext.MockContext(t.Context()) // Setup SDKConfig @@ -481,45 +449,39 @@ func Test_Python_PreparePackage(t *testing.T) { } func Test_Python_IsRuntimeForProject(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { sdkConfigRuntime string existingFilePaths []string expectedBool bool }{ - { - name: "Not a Python project", + "Not a Python project": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{}, expectedBool: false, }, - { - name: "SDKConfig Runtime is Python", + "SDKConfig Runtime is Python": { sdkConfigRuntime: "python", existingFilePaths: []string{}, // Unset to check SDKConfig expectedBool: true, }, - { - name: "requirements.txt file exists", + "requirements.txt file exists": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{"requirements.txt"}, expectedBool: true, }, - { - name: "pyproject.toml file exists", + "pyproject.toml file exists": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{"pyproject.toml"}, expectedBool: true, }, - { - name: "both requirements.txt and pyproject.toml exist", + "both requirements.txt and pyproject.toml exist": { sdkConfigRuntime: "", // Unset to check for file existingFilePaths: []string{"requirements.txt", "pyproject.toml"}, expectedBool: true, }, } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { + for name, tc := range tests { + t.Run(name, func(t *testing.T) { // Setup ctx := slackcontext.MockContext(t.Context()) fs := slackdeps.NewFsMock()