(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func TestGetShellHistory(t *testing.T) { |
| 53 | testCases := []struct { |
| 54 | name string |
| 55 | shell string |
| 56 | historyContent string |
| 57 | expectedContent string |
| 58 | expectError bool |
| 59 | }{ |
| 60 | { |
| 61 | name: "Bash History", |
| 62 | shell: "bash", |
| 63 | historyContent: "ls -la\ngit status", |
| 64 | expectedContent: "ls -la\ngit status", |
| 65 | expectError: false, |
| 66 | }, |
| 67 | { |
| 68 | name: "Zsh History", |
| 69 | shell: "zsh", |
| 70 | historyContent: ": 1663200000:0;ls -la\n: 1663200001:0;git status", |
| 71 | expectedContent: "ls -la\ngit status", |
| 72 | expectError: false, |
| 73 | }, |
| 74 | { |
| 75 | name: "Fish History", |
| 76 | shell: "fish", |
| 77 | historyContent: "- cmd: ls -la\n- cmd: git status", |
| 78 | expectedContent: "- cmd: ls -la\n- cmd: git status", // fish não tem processamento especial |
| 79 | expectError: false, |
| 80 | }, |
| 81 | { |
| 82 | name: "Unsupported Shell", |
| 83 | shell: "csh", |
| 84 | expectError: true, |
| 85 | }, |
| 86 | } |
| 87 | |
| 88 | for _, tc := range testCases { |
| 89 | t.Run(tc.name, func(t *testing.T) { |
| 90 | setupShellTest(t, tc.shell, tc.historyContent) |
| 91 | |
| 92 | content, err := GetShellHistory() |
| 93 | |
| 94 | if tc.expectError { |
| 95 | assert.Error(t, err) |
| 96 | } else { |
| 97 | require.NoError(t, err) |
| 98 | assert.Equal(t, tc.expectedContent, content) |
| 99 | } |
| 100 | }) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | func TestGetShellHistory_FileNotExist(t *testing.T) { |
| 105 | setupShellTest(t, "bash", "") |
nothing calls this directly
no test coverage detected