MCPcopy Create free account
hub / github.com/diillson/chatcli / setupShellTest

Function setupShellTest

utils/shell_utils_test.go:13–50  ·  view source on GitHub ↗

setupShellTest Mocks das funções de OS para os testes de shell

(t *testing.T, shell, historyContent string)

Source from the content-addressed store, hash-verified

11
12// setupShellTest Mocks das funções de OS para os testes de shell
13func setupShellTest(t *testing.T, shell, historyContent string) {
14 // Salva as funções originais
15 originalGetenv := osGetenv
16 originalUserCurrent := userCurrent
17 originalReadFile := osReadFile
18 originalStat := osStat
19
20 // Adiciona cleanup para restaurar as funções originais após o teste
21 t.Cleanup(func() {
22 osGetenv = originalGetenv
23 userCurrent = originalUserCurrent
24 osReadFile = originalReadFile
25 osStat = originalStat
26 })
27
28 // Mock os.Getenv
29 osGetenv = func(key string) string {
30 if key == "SHELL" {
31 return "/bin/" + shell
32 }
33 return os.Getenv(key)
34 }
35
36 // Mock user.Current
37 userCurrent = func() (*user.User, error) {
38 return &user.User{HomeDir: "/home/testuser"}, nil
39 }
40
41 // Mock os.ReadFile
42 osReadFile = func(name string) ([]byte, error) {
43 return []byte(historyContent), nil
44 }
45
46 // Mock os.Stat
47 osStat = func(name string) (os.FileInfo, error) {
48 return nil, nil // Retorna sucesso, indicando que o arquivo existe
49 }
50}
51
52func TestGetShellHistory(t *testing.T) {
53 testCases := []struct {

Callers 2

TestGetShellHistoryFunction · 0.85

Calls 1

CleanupMethod · 0.45

Tested by

no test coverage detected