(t *testing.T)
| 64 | } |
| 65 | |
| 66 | func TestOneShot(t *testing.T) { |
| 67 | ctx := t.Context() |
| 68 | tmpDir := t.TempDir() |
| 69 | deletedFile := filepath.Join(tmpDir, "test_delete.log") |
| 70 | |
| 71 | permDeniedFile := "/etc/shadow" |
| 72 | permDeniedError := "failed opening /etc/shadow: open /etc/shadow: permission denied" |
| 73 | |
| 74 | if runtime.GOOS == "windows" { |
| 75 | // Technically, this is not a permission denied error, but we just want to test what happens |
| 76 | // if we do not have access to the file |
| 77 | permDeniedFile = `C:\Windows\System32\config\SAM` |
| 78 | permDeniedError = `failed opening C:\Windows\System32\config\SAM: open C:\Windows\System32\config\SAM: The process cannot access the file because it is being used by another process.` |
| 79 | } |
| 80 | |
| 81 | tests := []struct { |
| 82 | name string |
| 83 | config string |
| 84 | expectedConfigErr string |
| 85 | expectedErr string |
| 86 | expectedOutput string |
| 87 | expectedLines int |
| 88 | logLevel log.Level |
| 89 | setup func() |
| 90 | afterConfigure func() |
| 91 | teardown func() |
| 92 | }{ |
| 93 | { |
| 94 | name: "permission denied", |
| 95 | config: fmt.Sprintf(` |
| 96 | mode: cat |
| 97 | filename: %s`, permDeniedFile), |
| 98 | expectedErr: permDeniedError, |
| 99 | logLevel: log.WarnLevel, |
| 100 | expectedLines: 0, |
| 101 | }, |
| 102 | { |
| 103 | name: "ignored directory", |
| 104 | config: ` |
| 105 | mode: cat |
| 106 | filename: /`, |
| 107 | expectedOutput: "/ is a directory, ignoring it", |
| 108 | logLevel: log.WarnLevel, |
| 109 | expectedLines: 0, |
| 110 | }, |
| 111 | { |
| 112 | name: "glob syntax error", |
| 113 | config: ` |
| 114 | mode: cat |
| 115 | filename: "[*-.log"`, |
| 116 | expectedConfigErr: "glob failure: syntax error in pattern", |
| 117 | logLevel: log.WarnLevel, |
| 118 | expectedLines: 0, |
| 119 | }, |
| 120 | { |
| 121 | name: "no matching files", |
| 122 | config: ` |
| 123 | mode: cat |
nothing calls this directly
no test coverage detected
searching dependent graphs…