Skip to content
Snippets Groups Projects
Commit 8607de0e authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

updated interface signature. first set integration test

parent 4f06883e
No related branches found
No related tags found
2 merge requests!114WIP: Complete testing,!90Develop
Pipeline #66769 failed
......@@ -60,18 +60,14 @@ func (_m *Transport) ProcessResponse(resp interface{}, root interface{}, models
}
// Set provides a mock function with given fields: ctx, params
func (_m *Transport) Set(ctx context.Context, params ...string) (interface{}, error) {
_va := make([]interface{}, len(params))
for _i := range params {
_va[_i] = params[_i]
}
func (_m *Transport) Set(ctx context.Context, params ...interface{}) (interface{}, error) {
var _ca []interface{}
_ca = append(_ca, ctx)
_ca = append(_ca, _va...)
_ca = append(_ca, params...)
ret := _m.Called(_ca...)
var r0 interface{}
if rf, ok := ret.Get(0).(func(context.Context, ...string) interface{}); ok {
if rf, ok := ret.Get(0).(func(context.Context, ...interface{}) interface{}); ok {
r0 = rf(ctx, params...)
} else {
if ret.Get(0) != nil {
......@@ -80,7 +76,7 @@ func (_m *Transport) Set(ctx context.Context, params ...string) (interface{}, er
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, ...string) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, ...interface{}) error); ok {
r1 = rf(ctx, params...)
} else {
r1 = ret.Error(1)
......
......@@ -47,3 +47,12 @@ type ErrNotYetImplemented struct{}
func (e ErrNotYetImplemented) Error() string {
return fmt.Sprintf("function not yet implemented")
}
type ErrInvalidParameters struct {
f interface{}
r interface{}
}
func (e ErrInvalidParameters) Error() string {
return fmt.Sprintf("invalid parameters for %v: %v", e.f, e.r)
}
\ No newline at end of file
......@@ -47,11 +47,44 @@ func (g *Gnmi) Get(ctx context.Context, params ...string) (interface{}, error) {
paths := gnmi.SplitPaths(params)
return g.get(ctx, paths, "")
}
func (g *Gnmi) Set(ctx context.Context, params ...string) (interface{}, error) {
// Set takes a slice of params. This slice must contain at least one operation.
// It can contain an additional arbitrary amount of operations and extensions.
func (g *Gnmi) Set(ctx context.Context, params ...interface{}) (interface{}, error) {
if g.client == nil {
return nil, &ErrNilClient{}
}
return nil, nil
if len(params) == 0 {
return nil, &ErrInvalidParameters{
f: "gnmi.Set()",
r: "no parameters provided",
}
}
// Loop over params and create ops and exts
// Invalid params cause unhealable error
ops := make([]*gnmi.Operation, 0)
exts := make([]*gnmi_ext.Extension, 0)
for _,p := range params{
switch p.(type) {
case *gnmi.Operation:
ops = append(ops, p.(*gnmi.Operation))
case *gnmi_ext.Extension:
exts = append(exts, p.(*gnmi_ext.Extension))
default:
return nil, &ErrInvalidParameters{
f: "gnmi.Set()",
r: "params contain invalid type",
}
}
}
if len(ops) == 0 {
return nil, &ErrInvalidParameters{
f: "gnmi.Set()",
r: "no operations provided",
}
}
return g.set(ctx, ops, exts...)
}
func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error {
......
......@@ -353,7 +353,7 @@ func TestGnmi_Set(t *testing.T) {
transport *Gnmi
}
type args struct {
params []string
params []interface{}
runEndpoint bool
}
tests := []struct {
......
......@@ -31,22 +31,73 @@ func TestGnmi_SetIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
t.Run("Test GNMI Set", func(t *testing.T) {
transport, err := NewGnmiTransport(cfg)
if err != nil {
t.Error(err)
}
p := []string{"/interfaces/interface"}
resp, err := transport.Set(context.Background(), p...)
if err != nil {
t.Error(err)
}
if resp == nil {
t.Error("resp is nil")
}
})
type fields struct {
config *gnmi.Config
}
type args struct {
ctx context.Context
params []interface{}
}
tests := []struct {
name string
fields fields
args args
want interface{}
wantErr bool
}{
{
name: "destination unreachable",
fields: fields{config: &gnmi.Config{
Addr: "203.0.113.10:6030",
},
},
args: args{
ctx: context.Background(),
params: []interface{}{&gnmi.Operation{}},
},
want: nil,
wantErr: true,
},
{
name: "valid update",
fields: fields{config: cfg},
args: args{
ctx: context.Background(),
params: []interface{}{
&gnmi.Operation{
Type: "update",
Origin: "",
Target: "",
Path: []string{
"system",
"config",
"hostname",
},
Val: "ceos3000",
},
},
},
want: &gpb.SetResponse{},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g, err := NewGnmiTransport(cfg)
if err != nil {
t.Error(err)
}
got, err := g.Set(tt.args.ctx, tt.args.params...)
if (err != nil) != tt.wantErr {
t.Errorf("Set() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Set() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGnmi_GetIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
......@@ -147,10 +198,10 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
wantErr: false,
},
{
name: "destination unreachable",
fields: fields{config: &gnmi.Config{
name: "destination unreachable",
fields: fields{config: &gnmi.Config{
Addr: "203.0.113.10:6030",
},
},
},
args: args{ctx: context.Background()},
want: nil,
......
......@@ -12,7 +12,7 @@ import (
// or gnmi
type Transport interface {
Get(ctx context.Context, params ...string) (interface{}, error)
Set(ctx context.Context, params ...string) (interface{}, error)
Set(ctx context.Context, params ...interface{}) (interface{}, error)
Subscribe(ctx context.Context, params ...string) error
Type() string
ProcessResponse(resp interface{}, root interface{}, models *ytypes.Schema) error
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment