Skip to content

Commit ebeed77

Browse files
authored
chore: Upgrade gopsutil to v3 (#927)
* Add host collector tests related to gopsutil upgrade * Upgrade gopsutil to v3
1 parent bc65289 commit ebeed77

File tree

14 files changed

+194
-31
lines changed

14 files changed

+194
-31
lines changed

go.mod

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/pkg/errors v0.9.1
2828
github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851
2929
github.com/segmentio/ksuid v1.0.4
30-
github.com/shirou/gopsutil v3.21.11+incompatible
30+
github.com/shirou/gopsutil/v3 v3.22.11
3131
github.com/sirupsen/logrus v1.9.0
3232
github.com/spf13/cobra v1.6.1
3333
github.com/spf13/pflag v1.0.5
@@ -56,7 +56,9 @@ require (
5656
github.com/googleapis/go-type-adapters v1.0.0 // indirect
5757
github.com/jackc/pgpassfile v1.0.0 // indirect
5858
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
59+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
5960
github.com/mistifyio/go-zfs/v3 v3.0.0 // indirect
61+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
6062
github.com/russross/blackfriday/v2 v2.1.0 // indirect
6163
github.com/sylabs/sif/v2 v2.8.1 // indirect
6264
)
@@ -178,8 +180,8 @@ require (
178180
github.com/subosito/gotenv v1.4.1 // indirect
179181
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
180182
github.com/tchap/go-patricia v2.3.0+incompatible // indirect
181-
github.com/tklauser/go-sysconf v0.3.9 // indirect
182-
github.com/tklauser/numcpus v0.3.0 // indirect
183+
github.com/tklauser/go-sysconf v0.3.11 // indirect
184+
github.com/tklauser/numcpus v0.6.0 // indirect
183185
github.com/ulikunitz/xz v0.5.10 // indirect
184186
github.com/vbatts/tar-split v0.11.2 // indirect
185187
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
@@ -190,7 +192,7 @@ require (
190192
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect
191193
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
192194
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
193-
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
195+
golang.org/x/sys v0.2.0 // indirect
194196
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
195197
golang.org/x/text v0.4.0 // indirect
196198
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect

go.sum

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q
724724
github.com/longhorn/go-iscsi-helper v0.0.0-20210330030558-49a327fb024e h1:hz4quJkaJWDo+xW+G6wTF6d6/95QvJ+o2D0+bB/tJ1U=
725725
github.com/longhorn/go-iscsi-helper v0.0.0-20210330030558-49a327fb024e/go.mod h1:9z/y9glKmWEdV50tjlUPxFwi1goQfIrrsoZbnMyIZbY=
726726
github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003/go.mod h1:0CLeXlf59Lg6C0kjLSDf47ft73Dh37CwymYRKWwAn04=
727+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
728+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
727729
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
728730
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
729731
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
@@ -893,6 +895,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
893895
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
894896
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
895897
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
898+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
899+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
896900
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
897901
github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
898902
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
@@ -955,8 +959,8 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod
955959
github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c=
956960
github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=
957961
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
958-
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
959-
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
962+
github.com/shirou/gopsutil/v3 v3.22.11 h1:kxsPKS+Eeo+VnEQ2XCaGJepeP6KY53QoRTETx3+1ndM=
963+
github.com/shirou/gopsutil/v3 v3.22.11/go.mod h1:xl0EeL4vXJ+hQMAGN8B9VFpxukEMA0XdevQOe5MZ1oY=
960964
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
961965
github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
962966
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
@@ -1030,10 +1034,10 @@ github.com/tchap/go-patricia v2.3.0+incompatible h1:GkY4dP3cEfEASBPPkWd+AmjYxhmD
10301034
github.com/tchap/go-patricia v2.3.0+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
10311035
github.com/tj/go-spin v1.1.0 h1:lhdWZsvImxvZ3q1C5OIB7d72DuOwP4O2NdBg9PyzNds=
10321036
github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4=
1033-
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
1034-
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
1035-
github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ=
1036-
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
1037+
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
1038+
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
1039+
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
1040+
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
10371041
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
10381042
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
10391043
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
@@ -1324,6 +1328,7 @@ golang.org/x/sys v0.0.0-20201117170446-d9b008d0a637/go.mod h1:h1NjWce9XRLGQEsW7w
13241328
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
13251329
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
13261330
golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1331+
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
13271332
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
13281333
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
13291334
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1345,7 +1350,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
13451350
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13461351
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13471352
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1348-
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13491353
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13501354
golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13511355
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -1371,8 +1375,8 @@ golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBc
13711375
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13721376
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13731377
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1374-
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
1375-
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1378+
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
1379+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13761380
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
13771381
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
13781382
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM=

pkg/collect/host_cpu.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/pkg/errors"
88
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
9-
"github.com/shirou/gopsutil/cpu"
9+
"github.com/shirou/gopsutil/v3/cpu"
1010
)
1111

1212
type CPUInfo struct {
@@ -52,7 +52,5 @@ func (c *CollectHostCPU) Collect(progressChan chan<- interface{}) (map[string][]
5252
output := NewResult()
5353
output.SaveResult(c.BundlePath, HostCPUPath, bytes.NewBuffer(b))
5454

55-
return map[string][]byte{
56-
HostCPUPath: b,
57-
}, nil
55+
return output, nil
5856
}

pkg/collect/host_cpu_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package collect
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestCollectHostCPU_Collect(t *testing.T) {
13+
c := &CollectHostCPU{
14+
hostCollector: &troubleshootv1beta2.CPU{},
15+
BundlePath: "",
16+
}
17+
got, err := c.Collect(nil)
18+
require.NoError(t, err)
19+
20+
require.Contains(t, got, "host-collectors/system/cpu.json")
21+
values := got["host-collectors/system/cpu.json"]
22+
23+
var m map[string]int
24+
err = json.Unmarshal(values, &m)
25+
require.NoError(t, err)
26+
27+
// Check if values exist. They will be different on different machines.
28+
assert.Equal(t, 2, len(m))
29+
assert.Contains(t, m, "logicalCount")
30+
assert.Contains(t, m, "physicalCount")
31+
}

pkg/collect/host_disk_usage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/pkg/errors"
1111
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
12-
"github.com/shirou/gopsutil/disk"
12+
"github.com/shirou/gopsutil/v3/disk"
1313
)
1414

1515
type DiskUsageInfo struct {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package collect
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"strings"
7+
"testing"
8+
9+
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestCollectHostDiskUsage_Collect(t *testing.T) {
15+
tests := []struct {
16+
name string
17+
collectorName string
18+
path string
19+
wantErr bool
20+
}{
21+
{
22+
name: "valid path with no collector name succeeds",
23+
path: "/",
24+
},
25+
{
26+
name: "valid path with a collector name succeeds",
27+
path: "/",
28+
collectorName: "custome-name",
29+
},
30+
{
31+
name: "extra long path recursion fails",
32+
path: strings.Repeat("/a", 51),
33+
wantErr: true,
34+
},
35+
}
36+
for _, tt := range tests {
37+
t.Run(tt.name, func(t *testing.T) {
38+
c := &CollectHostDiskUsage{
39+
hostCollector: &troubleshootv1beta2.DiskUsage{
40+
Path: tt.path,
41+
HostCollectorMeta: troubleshootv1beta2.HostCollectorMeta{
42+
CollectorName: tt.collectorName,
43+
},
44+
},
45+
BundlePath: "",
46+
}
47+
got, err := c.Collect(nil)
48+
assert.Equal(t, tt.wantErr, err != nil)
49+
50+
if err == nil {
51+
key := "host-collectors/diskUsage/diskUsage.json"
52+
if tt.collectorName != "" {
53+
key = fmt.Sprintf("host-collectors/diskUsage/%s.json", tt.collectorName)
54+
}
55+
require.Contains(t, got, key)
56+
values := got[key]
57+
58+
var m map[string]int
59+
err = json.Unmarshal(values, &m)
60+
require.NoError(t, err)
61+
62+
// Check if values exist. They will be different on different machines.
63+
assert.Equal(t, 2, len(m))
64+
assert.Contains(t, m, "total_bytes")
65+
assert.Contains(t, m, "used_bytes")
66+
}
67+
})
68+
}
69+
}

pkg/collect/host_memory.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/pkg/errors"
88
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
9-
"github.com/shirou/gopsutil/mem"
9+
"github.com/shirou/gopsutil/v3/mem"
1010
)
1111

1212
type MemoryInfo struct {
@@ -45,7 +45,5 @@ func (c *CollectHostMemory) Collect(progressChan chan<- interface{}) (map[string
4545
output := NewResult()
4646
output.SaveResult(c.BundlePath, HostMemoryPath, bytes.NewBuffer(b))
4747

48-
return map[string][]byte{
49-
HostMemoryPath: b,
50-
}, nil
48+
return output, nil
5149
}

pkg/collect/host_memory_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package collect
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestCollectHostMemory_Collect(t *testing.T) {
13+
c := &CollectHostMemory{
14+
hostCollector: &troubleshootv1beta2.Memory{},
15+
BundlePath: "",
16+
}
17+
got, err := c.Collect(nil)
18+
require.NoError(t, err)
19+
20+
require.Contains(t, got, "host-collectors/system/memory.json")
21+
values := got["host-collectors/system/memory.json"]
22+
23+
var m map[string]int
24+
err = json.Unmarshal(values, &m)
25+
require.NoError(t, err)
26+
27+
// Check if values exist. They will be different on different machines.
28+
assert.Equal(t, 1, len(m))
29+
assert.Contains(t, m, "total")
30+
}

pkg/collect/host_os_info.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/pkg/errors"
88
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
9-
osutils "github.com/shirou/gopsutil/host"
9+
osutils "github.com/shirou/gopsutil/v3/host"
1010
)
1111

1212
type HostOSInfo struct {
@@ -50,7 +50,5 @@ func (c *CollectHostOS) Collect(progressChan chan<- interface{}) (map[string][]b
5050
output := NewResult()
5151
output.SaveResult(c.BundlePath, HostOSInfoPath, bytes.NewBuffer(b))
5252

53-
return map[string][]byte{
54-
HostOSInfoPath: b,
55-
}, nil
53+
return output, nil
5654
}

pkg/collect/host_os_info_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package collect
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestCollectHostOS_Collect(t *testing.T) {
13+
c := &CollectHostOS{
14+
hostCollector: &troubleshootv1beta2.HostOS{},
15+
BundlePath: "",
16+
}
17+
got, err := c.Collect(nil)
18+
require.NoError(t, err)
19+
20+
require.Contains(t, got, "host-collectors/system/hostos_info.json")
21+
values := got["host-collectors/system/hostos_info.json"]
22+
23+
var m map[string]string
24+
err = json.Unmarshal(values, &m)
25+
require.NoError(t, err)
26+
27+
// Check if values exist. They will be different on different machines.
28+
assert.Equal(t, 4, len(m))
29+
assert.Contains(t, m, "name")
30+
assert.Contains(t, m, "kernelVersion")
31+
assert.Contains(t, m, "platformVersion")
32+
assert.Contains(t, m, "platformVersion")
33+
}

0 commit comments

Comments
 (0)