Skip to content
Merged
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
12 changes: 8 additions & 4 deletions internal/provider/cisco/gnmiext/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ type Capabilities struct {
}

type Client interface {
GetState(ctx context.Context, conf ...Configurable) error
Capabilities() *Capabilities
GetConfig(ctx context.Context, conf ...Configurable) error
GetState(ctx context.Context, conf ...Configurable) error
Patch(ctx context.Context, conf ...Configurable) error
Update(ctx context.Context, conf ...Configurable) error
Delete(ctx context.Context, conf ...Configurable) error
Expand All @@ -73,9 +74,7 @@ type client struct {
logger logr.Logger
}

var (
_ Client = &client{}
)
var _ Client = &client{}

// New creates a new Client by negotiating capabilities with the gNMI server by
// carrying out a Capabilities RPC.
Expand Down Expand Up @@ -128,6 +127,11 @@ func WithLogger(logger logr.Logger) Option {
// ErrNil indicates that the value for a xpath is not defined.
var ErrNil = errors.New("gnmiext: nil")

// Capabilities returns the capabilities supported by the gNMI server.
func (c *client) Capabilities() *Capabilities {
return c.capabilities
}

// GetConfig retrieves config and unmarshals it into the provided targets.
// If some of the values for the given xpaths are not defined, [ErrNil] is returned.
func (c *client) GetConfig(ctx context.Context, conf ...Configurable) error {
Expand Down
52 changes: 33 additions & 19 deletions internal/provider/cisco/iosxr/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,55 +91,69 @@ func Test_Payload(t *testing.T) {
// MockClient provides a mock implementation of gnmiext.Client for testing.
type MockClient struct {
// Function fields for mocking different methods
GetConfigFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
PatchFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
UpdateFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
DeleteFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
GetStateFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
CapabilitiesFunc func() *gnmiext.Capabilities
GetConfigFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
PatchFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
UpdateFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
DeleteFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
GetStateFunc func(ctx context.Context, conf ...gnmiext.Configurable) error
}

var _ gnmiext.Client = (*MockClient)(nil)

// Implement the methods that Provider uses
func (m *MockClient) Capabilities() *gnmiext.Capabilities {
if m.CapabilitiesFunc != nil {
return m.CapabilitiesFunc()
}
return nil
}

func (m *MockClient) GetConfig(ctx context.Context, conf ...gnmiext.Configurable) error {
if m.GetConfigFunc != nil {
return m.GetConfigFunc(ctx, conf...)
}
return nil
}

func (m *MockClient) Patch(ctx context.Context, conf ...gnmiext.Configurable) error {
func (m *MockClient) GetState(ctx context.Context, conf ...gnmiext.Configurable) error {
if m.GetStateFunc != nil {
return m.GetStateFunc(ctx, conf...)
}
return nil
}

func (m *MockClient) Update(ctx context.Context, conf ...gnmiext.Configurable) error {
func (m *MockClient) Patch(ctx context.Context, conf ...gnmiext.Configurable) error {
if m.PatchFunc != nil {
return m.PatchFunc(ctx, conf...)
}
return nil
}

func (m *MockClient) Delete(ctx context.Context, conf ...gnmiext.Configurable) error {
func (m *MockClient) Update(ctx context.Context, conf ...gnmiext.Configurable) error {
if m.UpdateFunc != nil {
return m.UpdateFunc(ctx, conf...)
}
return nil
}

func (m *MockClient) GetState(ctx context.Context, conf ...gnmiext.Configurable) error {
if m.GetStateFunc != nil {
return m.GetStateFunc(ctx, conf...)
func (m *MockClient) Delete(ctx context.Context, conf ...gnmiext.Configurable) error {
if m.DeleteFunc != nil {
return m.DeleteFunc(ctx, conf...)
}
return nil
}

func Test_EnsureInterface(t *testing.T) {
m := &MockClient{}

p := &Provider{
client: m,
conn: nil,
}
p := &Provider{client: m}

ctx := context.Background()

var name = "TwentyFiveGigE0/0/0/14"
name := "TwentyFiveGigE0/0/0/14"
var prefix netip.Prefix

prefix, err := netip.ParsePrefix("192.168.1.0/24")

if err != nil {
t.Fatalf("Failed to parse prefix: %v", err)
}
Expand Down Expand Up @@ -186,7 +200,7 @@ func Test_GetState(t *testing.T) {

ctx := context.Background()

var name = "TwentyFiveGigE0/0/0/14"
name := "TwentyFiveGigE0/0/0/14"

req := &provider.InterfaceRequest{
Interface: &v1alpha1.Interface{
Expand Down
Loading