Skip to content

Commit

Permalink
do not use pointer for ParentID
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Feb 14, 2024
1 parent c806132 commit 8644210
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions providers-sdk/v1/plugin/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import inventory "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
type Connection interface {
ID() uint32

// ParentID returns the ID of the parent connection. If this returns a value,
// ParentID returns the ID of the parent connection. If this returns >0,
// the connection with that ID will be used to store and get data.
ParentID() *uint32
ParentID() uint32
}

type connection struct {
id uint32
parentId *uint32
parentId uint32
}

func NewConnection(id uint32, asset *inventory.Asset) Connection {
conn := &connection{
id: id,
}
if len(asset.Connections) > 0 && asset.Connections[0].ParentConnectionId > 0 {
conn.parentId = &asset.Connections[0].ParentConnectionId
conn.parentId = asset.Connections[0].ParentConnectionId
}
return conn
}
Expand All @@ -32,6 +32,6 @@ func (c *connection) ID() uint32 {
return c.id
}

func (c *connection) ParentID() *uint32 {
func (c *connection) ParentID() uint32 {
return c.parentId
}
4 changes: 2 additions & 2 deletions providers-sdk/v1/plugin/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestConnection_ID(t *testing.T) {
func TestConnection_ParentID_Nil(t *testing.T) {
c := NewConnection(1, &inventory.Asset{})
require.NotNil(t, c)
assert.Nil(t, c.ParentID())
assert.Equal(t, 0, c.ParentID())
}

func TestConnection_ParentID(t *testing.T) {
Expand All @@ -32,7 +32,7 @@ func TestConnection_ParentID(t *testing.T) {
},
})
require.NotNil(t, c)
assert.Equal(t, uint32(2), *c.ParentID())
assert.Equal(t, uint32(2), c.ParentID())
}

func TestConnection_ParentID_0(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions providers-sdk/v1/plugin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func (s *Service) AddRuntime(createRuntime func(connId uint32) (*Runtime, error)
}

if runtime.Connection != nil {
if parentId := runtime.Connection.ParentID(); parentId != nil {
parentRuntime, err := s.doGetRuntime(*parentId)
if parentId := runtime.Connection.ParentID(); parentId > 0 {
parentRuntime, err := s.doGetRuntime(parentId)
if err != nil {
return nil, errors.New("parent connection " + strconv.FormatUint(uint64(*parentId), 10) + " not found")
return nil, errors.New("parent connection " + strconv.FormatUint(uint64(parentId), 10) + " not found")
}
runtime.Resources = parentRuntime.Resources

Expand Down
8 changes: 4 additions & 4 deletions providers-sdk/v1/plugin/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type TestConnection struct {
id uint32
parentId *uint32
parentId uint32
}

func newTestConnection(id uint32) *TestConnection {
Expand All @@ -25,7 +25,7 @@ func (c *TestConnection) ID() uint32 {
return c.id
}

func (c *TestConnection) ParentID() *uint32 {
func (c *TestConnection) ParentID() uint32 {
return c.parentId
}

Expand Down Expand Up @@ -84,7 +84,7 @@ func TestAddRuntime_ParentNotExist(t *testing.T) {
parentId := uint32(10)
_, err := s.AddRuntime(func(connId uint32) (*Runtime, error) {
c := newTestConnection(connId)
c.parentId = &parentId
c.parentId = parentId
return &Runtime{
Connection: c,
}, nil
Expand All @@ -110,7 +110,7 @@ func TestAddRuntime_Parent(t *testing.T) {
parentId := parent.Connection.ID()
child, err := s.AddRuntime(func(connId uint32) (*Runtime, error) {
c := newTestConnection(connId)
c.parentId = &parentId
c.parentId = parentId
return &Runtime{
Connection: c,
}, nil
Expand Down

0 comments on commit 8644210

Please sign in to comment.