github.com/ubuntu/ubuntu-report@v1.7.4-0.20240410144652-96f37d845fac/internal/metrics/testing.go (about)

     1  package metrics
     2  
     3  import "os/exec"
     4  
     5  // GetenvFn is used to mock os.Getenv() for testing only
     6  type GetenvFn func(key string) string
     7  
     8  // NewTestMetrics create a full mocking testing metrics element.
     9  // This is only a mock for testing, not for real use
    10  func NewTestMetrics(root string,
    11  	cmdGPU *exec.Cmd, cmdCPU *exec.Cmd, cmdScreen *exec.Cmd, cmdPartition *exec.Cmd,
    12  	cmdArch *exec.Cmd, cmdLibc6 *exec.Cmd, cmdHwCap *exec.Cmd, getenv GetenvFn) Metrics {
    13  	// do not use helper as in _test.go package
    14  	return Metrics{
    15  		root:          root,
    16  		gpuInfoCmd:    cmdGPU,
    17  		cpuInfoCmd:    cmdCPU,
    18  		screenInfoCmd: cmdScreen,
    19  		spaceInfoCmd:  cmdPartition,
    20  		archCmd:       cmdArch,
    21  		hwCapCmd:      cmdHwCap,
    22  		getenv:        getenv,
    23  	}
    24  }