Skip to content

Commit 0f4bfbf

Browse files
committed
move sofa table to new osquery interface
1 parent db30e2b commit 0f4bfbf

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

tables/sofa/sofa_info.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/hashicorp/go-version"
10+
"github.com/macadmins/osquery-extension/pkg/utils"
1011
osquery "github.com/osquery/osquery-go"
1112
"github.com/osquery/osquery-go/plugin/table"
1213
)
@@ -113,11 +114,6 @@ type OSVersion struct {
113114

114115
type Option func(*SofaClient)
115116

116-
type OsqueryClient interface {
117-
QueryRow(query string) (map[string]string, error)
118-
Close()
119-
}
120-
121117
func SofaSecurityReleaseInfoColumns() []table.ColumnDefinition {
122118
return []table.ColumnDefinition{
123119
table.TextColumn("update_name"),
@@ -238,7 +234,7 @@ func getSecurityReleaseInfoForOSVersion(root Root, osVersion string) ([]Security
238234
return out, nil
239235
}
240236

241-
func getCurrentOSVersion(client OsqueryClient) (string, error) {
237+
func getCurrentOSVersion(client utils.OsqueryClient) (string, error) {
242238
osVersionQuery := "SELECT * FROM os_version;"
243239

244240
resp, err := client.QueryRow(osVersionQuery)

tables/sofa/sofa_info_test.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ import (
44
_ "embed"
55
"testing"
66

7+
"github.com/macadmins/osquery-extension/pkg/utils"
78
"github.com/osquery/osquery-go/plugin/table"
89
"github.com/stretchr/testify/assert"
910
)
1011

11-
type MockOsqueryClient struct{}
12-
13-
func (m MockOsqueryClient) QueryRow(query string) (map[string]string, error) {
14-
return map[string]string{"version": "1.0.0"}, nil
15-
}
16-
17-
func (m MockOsqueryClient) Close() {}
18-
1912
func TestGetSecurityReleaseInfoForOSVersion(t *testing.T) {
2013
tests := []struct {
2114
name string
@@ -77,7 +70,11 @@ func TestGetSecurityReleaseInfoForOSVersion(t *testing.T) {
7770
}
7871

7972
func TestGetCurrentOSVersion(t *testing.T) {
80-
mockClient := MockOsqueryClient{}
73+
mockClient := &utils.MockOsqueryClient{
74+
Data: map[string][]map[string]string{
75+
"SELECT * FROM os_version;": {{"version": "1.0.0"}},
76+
},
77+
}
8178
version, err := getCurrentOSVersion(mockClient)
8279
assert.NoError(t, err)
8380
assert.Equal(t, "1.0.0", version)

0 commit comments

Comments
 (0)