File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ package fetch
2
+
3
+ import (
4
+ "device-chronicle-client/models"
5
+ "github.com/stretchr/testify/assert"
6
+ "github.com/stretchr/testify/mock"
7
+ "runtime"
8
+ "testing"
9
+ )
10
+
11
+ // MockOS is a mock that simulates the OS interface
12
+ type MockOS struct {
13
+ mock.Mock
14
+ }
15
+
16
+ // Linux mocks the os.Linux function
17
+ func (m * MockOS ) Linux () (* models.System , error ) {
18
+ args := m .Called ()
19
+ if args .Get (0 ) == nil {
20
+ return nil , args .Error (1 )
21
+ }
22
+ return args .Get (0 ).(* models.System ), args .Error (1 )
23
+ }
24
+
25
+ // TestFetchData tests the FetchData function
26
+ func TestFetchData (t * testing.T ) {
27
+ // We can only test the expected behavior for the current OS
28
+ system , err := FetchData ()
29
+
30
+ if runtime .GOOS == "linux" {
31
+ assert .NoError (t , err )
32
+ assert .NotNil (t , system )
33
+
34
+ // Verify system has expected structure
35
+ assert .NotEmpty (t , system .Hostname )
36
+ assert .NotNil (t , system .CPUCores )
37
+ } else {
38
+ assert .Error (t , err )
39
+ assert .Nil (t , system )
40
+ assert .Contains (t , err .Error (), "unsupported OS" )
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ require (
17
17
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
18
18
github.com/pmezard/go-difflib v1.0.0 // indirect
19
19
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
20
+ github.com/stretchr/objx v0.5.2 // indirect
20
21
github.com/tklauser/go-sysconf v0.3.12 // indirect
21
22
github.com/tklauser/numcpus v0.6.1 // indirect
22
23
github.com/yusufpapurcu/wmi v1.2.4 // indirect
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF
24
24
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c /go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE =
25
25
github.com/shirou/gopsutil/v4 v4.24.11 h1:WaU9xqGFKvFfsUv94SXcUPD7rCkU0vr/asVdQOBZNj8 =
26
26
github.com/shirou/gopsutil/v4 v4.24.11 /go.mod h1:s4D/wg+ag4rG0WO7AiTj2BeYCRhym0vM7DHbZRxnIT8 =
27
+ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY =
28
+ github.com/stretchr/objx v0.5.2 /go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA =
27
29
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA =
28
30
github.com/stretchr/testify v1.10.0 /go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY =
29
31
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU =
You can’t perform that action at this time.
0 commit comments