-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfiles.go
More file actions
45 lines (37 loc) · 987 Bytes
/
files.go
File metadata and controls
45 lines (37 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package command
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/buildkite/test-engine-client/internal/runner"
)
func getTestFiles(fileList string, testRunner runner.TestRunner) ([]string, error) {
if fileList != "" {
return getTestFilesFromFile(fileList)
} else {
return testRunner.GetFiles()
}
}
func getTestFilesFromFile(path string) ([]string, error) {
content, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("couldn't read files from %s", path)
}
contentType := http.DetectContentType(content)
if !strings.HasPrefix(contentType, "text/") {
return nil, fmt.Errorf("%s is not a text file", path)
}
lines := strings.Split(string(content), "\n")
fileNames := []string{}
for _, line := range lines {
trimmedLine := strings.TrimSpace(line)
if trimmedLine != "" {
fileNames = append(fileNames, trimmedLine)
}
}
if len(fileNames) == 0 {
return nil, fmt.Errorf("no test files found in %s", path)
}
return fileNames, nil
}