forked from Azure/AgentBaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.go
More file actions
60 lines (48 loc) · 1.08 KB
/
log.go
File metadata and controls
60 lines (48 loc) · 1.08 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package e2e_test
import (
"bufio"
"os"
"path/filepath"
)
const (
e2eLogsDir = "scenario-logs"
)
func createDirIfNeeded(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}
}
return nil
}
func createE2ELoggingDir() error {
return createDirIfNeeded(e2eLogsDir)
}
func createVMLogsDir(caseName string) (string, error) {
logDir := filepath.Join(e2eLogsDir, caseName)
return logDir, createDirIfNeeded(logDir)
}
func writeToFile(fileName, content string) error {
outputFile, err := os.Create(fileName)
if err != nil {
return err
}
defer outputFile.Close()
w := bufio.NewWriter(outputFile)
defer w.Flush()
contentBytes := []byte(content)
if _, err := w.Write(contentBytes); err != nil {
return err
}
return nil
}
func dumpFileMapToDir(baseDir string, files map[string]string) error {
for path, contents := range files {
path = filepath.Base(path)
fullPath := filepath.Join(baseDir, path)
if err := writeToFile(fullPath, contents); err != nil {
return err
}
}
return nil
}