1package tools
2
3import (
4 "testing"
5
6 "github.com/charmbracelet/crush/internal/config"
7 "github.com/stretchr/testify/assert"
8 "github.com/stretchr/testify/require"
9)
10
11func TestResolveBlockFuncsFromEmptyConfig(t *testing.T) {
12 cfg := config.ToolBash{
13 DisableDefaults: false,
14 BannedCommands: []string{},
15 BannedSubCommands: []config.BannedToolArgsAndOrParams{},
16 }
17
18 bannedCmds := resolveBannedCommandsList(cfg)
19 require.Len(t, bannedCmds, len(defaultBannedCommands))
20 assert.Equal(t, defaultBannedCommands, bannedCmds)
21}
22
23func TestResolveBlockFuncsFromEmptyConfigWithDefaultDisabled(t *testing.T) {
24 cfg := config.ToolBash{
25 DisableDefaults: true,
26 BannedCommands: []string{},
27 BannedSubCommands: []config.BannedToolArgsAndOrParams{},
28 }
29
30 bannedCmds := resolveBannedCommandsList(cfg)
31 require.Len(t, bannedCmds, 0)
32 assert.Equal(t, []string{}, bannedCmds)
33}
34
35func TestResolveBlockFuncsDefaultDisabledWithBannedCommands(t *testing.T) {
36 cfg := config.ToolBash{
37 DisableDefaults: true,
38 BannedCommands: []string{
39 "pacman",
40 "mount",
41 },
42 BannedSubCommands: []config.BannedToolArgsAndOrParams{},
43 }
44
45 bannedCmds := resolveBannedCommandsList(cfg)
46 require.Len(t, bannedCmds, 2)
47 assert.Equal(t, []string{"pacman", "mount"}, bannedCmds)
48}
49
50func TestResolveBlockFuncsWithDefaultAndAddtionalBannedCommands(t *testing.T) {
51 additionalBannedCommands := []string{"lazygit", "btop"}
52 cfg := config.ToolBash{
53 DisableDefaults: false,
54 BannedCommands: additionalBannedCommands,
55 BannedSubCommands: []config.BannedToolArgsAndOrParams{},
56 }
57
58 bannedCmds := resolveBannedCommandsList(cfg)
59 require.Len(t, bannedCmds, len(defaultBannedCommands)+len(additionalBannedCommands))
60}