Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit testing for indexers - Grid Proxy #1280

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ github.com/machinebox/graphql v0.2.2/go.mod h1:F+kbVMHuwrQ5tYgU9JXlnskM8nOaFxCAE
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mdlayher/netlink v1.4.0/go.mod h1:dRJi5IABcZpBD2A3D0Mv/AiX8I9uDEu5oGkAVrekmf8=
github.com/mimuret/golang-iij-dpf v0.9.1/go.mod h1:sl9KyOkESib9+KRD3HaGpgi1xk7eoN2+d96LCLsME2M=
Expand Down Expand Up @@ -973,9 +974,13 @@ github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzL
github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo=
github.com/pkg/xattr v0.4.1/go.mod h1:W2cGD0TBEus7MkUgv0tNZ9JutLtVO3cXu+IBRuHqnFs=
github.com/pquerna/otp v1.4.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
Expand Down
1 change: 1 addition & 0 deletions grid-proxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/gorilla/websocket v1.5.3 // indirect
Expand Down
10 changes: 10 additions & 0 deletions grid-proxy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,20 @@ github.com/vedhavyas/go-subkey v1.0.3/go.mod h1:CloUaFQSSTdWnINfBRFjVMkWXZANW+nd
github.com/vmihailenco/msgpack v4.0.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
Expand All @@ -209,17 +212,21 @@ golang.org/x/net v0.0.0-20190514140710-3ec191127204/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -242,11 +249,14 @@ golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.15.0 h1:2lYxjRbTYyxkJxlhC+LvJIx3SsANPdRybu1tGj9/OrQ=
gonum.org/v1/gonum v0.15.0/go.mod h1:xzZVBJBtS+Mz4q0Yl2LJTk+OxOg4jiXZ7qBoM0uISGo=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down
4 changes: 2 additions & 2 deletions grid-proxy/internal/indexer/dmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/internal/explorer/db"
"github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/pkg/types"
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go"
zosDmiTypes "github.com/threefoldtech/zos/pkg/capacity/dmi"
)

Expand All @@ -31,7 +31,7 @@ func (w *DMIWork) Finders() map[string]time.Duration {
return w.findersInterval
}

func (w *DMIWork) Get(ctx context.Context, rmb *peer.RpcClient, twinId uint32) ([]types.Dmi, error) {
func (w *DMIWork) Get(ctx context.Context, rmb rmb.Client, twinId uint32) ([]types.Dmi, error) {
var dmi zosDmiTypes.DMI
err := callNode(ctx, rmb, DmiCallCmd, nil, twinId, &dmi)
if err != nil {
Expand Down
138 changes: 138 additions & 0 deletions grid-proxy/internal/indexer/dmi_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package indexer

import (
"context"
"testing"
"time"

gomock "github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
mock_rmb "github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/mocks"
"github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/pkg/types"
zosDmiTypes "github.com/threefoldtech/zos/pkg/capacity/dmi"
)

func TestNewDMIWork(t *testing.T) {
wanted := &DMIWork{
findersInterval: map[string]time.Duration{
"up": 2 * time.Minute,
"new": 5 * time.Minute,
},
}
dmi := NewDMIWork(2)
assert.Exactlyf(t, wanted, dmi, "got: %v , expected: %v", dmi, wanted)
}

func TestDMIGet(t *testing.T) {
dmi := NewDMIWork(2)
ctrl := gomock.NewController(t)
ctx := context.Background()

t.Run("get dmi with valid twin id", func(t *testing.T) {
twinID := uint32(1)
expected := zosDmiTypes.DMI{
Sections: []zosDmiTypes.Section{
{
TypeStr: "BIOS",
SubSections: []zosDmiTypes.SubSection{
{
Title: "BIOS Information",
Properties: map[string]zosDmiTypes.PropertyData{
"Vendor": {Val: "American Megatrends Inc."},
"Version": {Val: "3.2"},
},
},
},
},
{
TypeStr: "Baseboard",
SubSections: []zosDmiTypes.SubSection{
{
Title: "Base Board Information",
Properties: map[string]zosDmiTypes.PropertyData{
"Manufacturer": {Val: "Supermicro"},
"Product Name": {Val: "X9DRi-LN4+/X9DR3-LN4+"},
},
},
},
},
{
TypeStr: "Processor",
SubSections: []zosDmiTypes.SubSection{
{
Title: "Processor Information",
Properties: map[string]zosDmiTypes.PropertyData{
"Version": {Val: "Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz"},
"Thread Count": {Val: "12"},
},
},
{
Title: "Processor Information",
Properties: map[string]zosDmiTypes.PropertyData{
"Version": {Val: "Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz"},
"Thread Count": {Val: "12"},
},
},
},
},
{
TypeStr: "MemoryDevice",
SubSections: []zosDmiTypes.SubSection{
{
Title: "Memory Device",
Properties: map[string]zosDmiTypes.PropertyData{
"Manufacturer": {Val: "Samsung"},
"Type": {Val: "DDR3"},
},
},
{
Title: "Memory Device",
Properties: map[string]zosDmiTypes.PropertyData{
"Manufacturer": {Val: "Samsung"},
"Type": {Val: "DDR3"},
},
},
{
Title: "Memory Device",
Properties: map[string]zosDmiTypes.PropertyData{
"Manufacturer": {Val: "Samsung"},
"Type": {Val: "DDR3"},
},
},
},
},
},
}
client := mock_rmb.NewMockClient(ctrl)
client.EXPECT().Call(gomock.Any(), twinID, DmiCallCmd, nil, &zosDmiTypes.DMI{}).DoAndReturn(
func(ctx context.Context, twin uint32, fn string, data, result interface{}) error {
*(result.(*zosDmiTypes.DMI)) = expected
return nil
},
)
got, err := dmi.Get(ctx, client, twinID)
assert.NoError(t, err)
assert.Len(t, got, 1)
assert.Equal(t, expected.Sections[0].SubSections[0].Properties["Vendor"].Val, got[0].BIOS.Vendor)
assert.Equal(t, expected.Sections[0].SubSections[0].Properties["Version"].Val, got[0].BIOS.Version)
assert.Equal(t, expected.Sections[1].SubSections[0].Properties["Manufacturer"].Val, got[0].Baseboard.Manufacturer)
assert.Equal(t, expected.Sections[1].SubSections[0].Properties["Product Name"].Val, got[0].Baseboard.ProductName)
assert.Equal(t, expected.Sections[2].SubSections[0].Properties["Version"].Val, got[0].Processor[0].Version)
assert.Equal(t, expected.Sections[2].SubSections[0].Properties["Thread Count"].Val, got[0].Processor[0].ThreadCount)
assert.Equal(t, expected.Sections[3].SubSections[0].Properties["Manufacturer"].Val, got[0].Memory[0].Manufacturer)
assert.Equal(t, expected.Sections[3].SubSections[0].Properties["Type"].Val, got[0].Memory[0].Type)
assert.IsTypef(t, got, []types.Dmi{}, "got: %T , expected: %T", got, []types.Dmi{})

})

t.Run("get dmi with invalid twin id", func(t *testing.T) {
twinID := uint32(2)
client := mock_rmb.NewMockClient(ctrl)
client.EXPECT().Call(gomock.Any(), twinID, DmiCallCmd, nil, &zosDmiTypes.DMI{}).Return(
assert.AnError,
)
_, err := dmi.Get(ctx, client, twinID)
assert.Error(t, err)
})

}
4 changes: 2 additions & 2 deletions grid-proxy/internal/indexer/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/internal/explorer/db"
"github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/pkg/types"
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go"
)

const (
Expand All @@ -30,7 +30,7 @@ func (w *FeatureWork) Finders() map[string]time.Duration {
return w.findersInterval
}

func (w *FeatureWork) Get(ctx context.Context, rmb *peer.RpcClient, twinId uint32) ([]types.NodeFeatures, error) {
func (w *FeatureWork) Get(ctx context.Context, rmb rmb.Client, twinId uint32) ([]types.NodeFeatures, error) {
var features []string
err := callNode(ctx, rmb, featuresCallCmd, nil, twinId, &features)
if err != nil {
Expand Down
69 changes: 69 additions & 0 deletions grid-proxy/internal/indexer/features_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package indexer

import (
"context"
"testing"
"time"

gomock "github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
mock_rmb "github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/mocks"
"github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/pkg/types"
)

func TestNewFeatureWork(t *testing.T) {
wanted := &FeatureWork{
findersInterval: map[string]time.Duration{
"up": time.Duration(2) * time.Minute,
"new": newNodesCheckInterval,
},
}
feature := NewFeatureWork(2)
assert.Exactlyf(t, wanted, feature, "got: %v , expected: %v", feature, wanted)
}

func TestFeatureGet(t *testing.T) {
feature := NewFeatureWork(2)
ctrl := gomock.NewController(t)
ctx := context.Background()

t.Run("get feature with valid twin id", func(t *testing.T) {
twinID := uint32(1)
expected := []string{"zmount", "network", "zdb", "zmachine", "volume", "ipv4",
"ip",
"gateway-name-proxy",
"gateway-fqdn-proxy",
"qsfs",
"zlogs",
"yggdrasil",
"mycelium",
"wireguard"}

client := mock_rmb.NewMockClient(ctrl)
client.EXPECT().Call(gomock.Any(), twinID, featuresCallCmd, nil, gomock.Any()).DoAndReturn(
func(ctx context.Context, twinId uint32, fn string, data, result interface{}) error {
*result.(*[]string) = expected
return nil
},
)
features, err := feature.Get(ctx, client, twinID)
assert.NoError(t, err)
assert.Len(t, features, 1)
assert.Equal(t, expected, features[0].Features)
assert.Equal(t, twinID, features[0].NodeTwinId)
assert.IsTypef(t, features, []types.NodeFeatures{}, "got: %T , expected: %T", features, []types.NodeFeatures{})
})

t.Run("get feature with invalid twin id", func(t *testing.T) {
twinID := uint32(1)

client := mock_rmb.NewMockClient(ctrl)
client.EXPECT().Call(gomock.Any(), twinID, featuresCallCmd, nil, gomock.Any()).Return(
assert.AnError,
)
features, err := feature.Get(ctx, client, twinID)
assert.Error(t, err)
assert.Len(t, features, 0)
})

}
Loading
Loading