Skip to content

Commit

Permalink
Handle testing json errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hedge-sparrow committed Oct 28, 2024
1 parent 6f01832 commit 21cb127
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/analyze/host_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"github.com/stretchr/testify/require"
)

func collectorToBytes(collector any) []byte {
jsonData, _ := json.Marshal(collector)
func collectorToBytes(t *testing.T, collector any) []byte {
jsonData, err := json.Marshal(collector)
require.NoError(t, err)
return jsonData
}

Expand All @@ -28,7 +29,7 @@ func TestAnalyzeHostCollectorResults(t *testing.T) {
collectedContent: []collectedContent{
{
NodeName: "node1",
Data: collectorToBytes(collect.HostOSInfo{
Data: collectorToBytes(t, collect.HostOSInfo{
Name: "myhost",
KernelVersion: "5.4.0-1034-gcp",
PlatformVersion: "00.1.2",
Expand Down Expand Up @@ -62,7 +63,7 @@ func TestAnalyzeHostCollectorResults(t *testing.T) {
collectedContent: []collectedContent{
{
NodeName: "node1",
Data: collectorToBytes(collect.HostOSInfo{
Data: collectorToBytes(t, collect.HostOSInfo{
Name: "myhost",
KernelVersion: "5.4.0-1034-gcp",
PlatformVersion: "11.04",
Expand All @@ -71,7 +72,7 @@ func TestAnalyzeHostCollectorResults(t *testing.T) {
},
{
NodeName: "node2",
Data: collectorToBytes(collect.HostOSInfo{
Data: collectorToBytes(t, collect.HostOSInfo{
Name: "myhost",
KernelVersion: "5.4.0-1034-gcp",
PlatformVersion: "11.04",
Expand Down Expand Up @@ -110,7 +111,7 @@ func TestAnalyzeHostCollectorResults(t *testing.T) {
collectedContent: []collectedContent{
{
NodeName: "",
Data: collectorToBytes(collect.HostOSInfo{
Data: collectorToBytes(t, collect.HostOSInfo{
Name: "myhost",
KernelVersion: "5.4.0-1034-gcp",
PlatformVersion: "20.04",
Expand Down

0 comments on commit 21cb127

Please sign in to comment.