github.com/ubuntu/ubuntu-report@v1.7.4-0.20240410144652-96f37d845fac/internal/metrics/export_test.go (about) 1 package metrics 2 3 import ( 4 "os/exec" 5 6 log "github.com/sirupsen/logrus" 7 "github.com/ubuntu/ubuntu-report/internal/helper" 8 ) 9 10 // WithRootAt tweaks the root directory of the file system 11 func WithRootAt(p string) func(*Metrics) error { 12 log.Debugf("Setting root directory to %s", p) 13 return func(m *Metrics) error { 14 m.root = p 15 return nil 16 } 17 } 18 19 // WithCPUInfoCommand tweaks the default cpu info command 20 func WithCPUInfoCommand(cmd *exec.Cmd) func(*Metrics) error { 21 log.Debugf("Setting cpu info command to '%s'", cmd.Args) 22 return func(m *Metrics) error { 23 m.cpuInfoCmd = cmd 24 return nil 25 } 26 } 27 28 // WithGPUInfoCommand tweaks the default gpu info command 29 func WithGPUInfoCommand(cmd *exec.Cmd) func(*Metrics) error { 30 log.Debugf("Setting gpu info command to '%s'", cmd.Args) 31 return func(m *Metrics) error { 32 m.gpuInfoCmd = cmd 33 return nil 34 } 35 } 36 37 // WithScreenInfoCommand tweaks the default screen info command 38 func WithScreenInfoCommand(cmd *exec.Cmd) func(*Metrics) error { 39 log.Debugf("Setting screen info command to '%s'", cmd.Args) 40 return func(m *Metrics) error { 41 m.screenInfoCmd = cmd 42 return nil 43 } 44 } 45 46 // WithSpaceInfoCommand tweaks the default space info command 47 func WithSpaceInfoCommand(cmd *exec.Cmd) func(*Metrics) error { 48 log.Debugf("Setting space info command to '%s'", cmd.Args) 49 return func(m *Metrics) error { 50 m.spaceInfoCmd = cmd 51 return nil 52 } 53 } 54 55 // WithArchitectureCommand tweaks the current given architecture 56 func WithArchitectureCommand(cmd *exec.Cmd) func(*Metrics) error { 57 log.Debugf("Setting architecture command to '%s'", cmd.Args) 58 return func(m *Metrics) error { 59 m.archCmd = cmd 60 return nil 61 } 62 } 63 64 // WithLibc6Command tweaks the version of libc6 that is reported 65 func WithLibc6Command(cmd *exec.Cmd) func(*Metrics) error { 66 log.Debugf("Setting libc6 command to '%s'", cmd.Args) 67 return func(m *Metrics) error { 68 m.libc6Cmd = cmd 69 return nil 70 } 71 } 72 73 // WithHwCapCommand tweaks the path to ld-linux 74 func WithHwCapCommand(cmd *exec.Cmd) func(*Metrics) error { 75 log.Debugf("Setting hwcap command to '%s'", cmd.Args) 76 return func(m *Metrics) error { 77 m.hwCapCmd = cmd 78 return nil 79 } 80 } 81 82 // WithMapForEnv replace system getenv with given environ hashmap 83 func WithMapForEnv(env map[string]string) func(*Metrics) error { 84 log.Debugf("Setting new environment to '%v'", env) 85 return func(m *Metrics) error { 86 m.getenv = helper.GetenvFromMap(env) 87 return nil 88 } 89 }