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

more integration test cases

parent 8d84398b
Branches
Tags
1 merge request!90Develop
Pipeline #67029 failed
...@@ -641,36 +641,3 @@ func TestGnmi_set(t *testing.T) { ...@@ -641,36 +641,3 @@ func TestGnmi_set(t *testing.T) {
} }
} }
func TestGnmi_subscribe(t *testing.T) {
type fields struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
Unmarshal func([]byte, []string, interface{}, ...ytypes.UnmarshalOpt) error
RespChan chan *gpb.SubscribeResponse
config *gnmi.Config
client gpb.GNMIClient
}
type args struct {
ctx context.Context
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := &Gnmi{
SetNode: tt.fields.SetNode,
Unmarshal: tt.fields.Unmarshal,
RespChan: tt.fields.RespChan,
client: tt.fields.client,
}
if err := g.subscribe(tt.args.ctx); (err != nil) != tt.wantErr {
t.Errorf("subscribe() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
...@@ -27,6 +27,7 @@ func testSetupIntegration() { ...@@ -27,6 +27,7 @@ func testSetupIntegration() {
Password: "arista", Password: "arista",
Encoding: gpb.Encoding_JSON_IETF, Encoding: gpb.Encoding_JSON_IETF,
}, },
RespChan: make(chan *gpb.SubscribeResponse),
} }
} }
...@@ -94,13 +95,15 @@ func TestGnmi_SetIntegration(t *testing.T) { ...@@ -94,13 +95,15 @@ func TestGnmi_SetIntegration(t *testing.T) {
return return
} }
got, err := g.Set(tt.args.ctx, tt.args.params...) got, err := g.Set(tt.args.ctx, tt.args.params...)
if tt.want != nil {
tt.want.(*gpb.SetResponse).Timestamp = got.(*gpb.SetResponse).Timestamp
}
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("Set() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Set() error = %v, wantErr %v", err, tt.wantErr)
return return
} }
if got != nil {
if tt.want != nil {
tt.want.(*gpb.SetResponse).Timestamp = got.(*gpb.SetResponse).Timestamp
}
}
if err != nil && tt.wantErr { if err != nil && tt.wantErr {
return return
} else if !reflect.DeepEqual(got, tt.want) { } else if !reflect.DeepEqual(got, tt.want) {
...@@ -109,65 +112,179 @@ func TestGnmi_SetIntegration(t *testing.T) { ...@@ -109,65 +112,179 @@ func TestGnmi_SetIntegration(t *testing.T) {
}) })
} }
} }
func TestGnmi_GetIntegration(t *testing.T) { func TestGnmi_GetIntegration(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping integration test") t.Skip("skipping integration test")
} }
t.Run("Test GNMI Get", func(t *testing.T) {
transport, err := NewGnmiTransport(opt)
if err != nil {
t.Error(err)
}
p := []string{"/interfaces/interface"}
resp, err := transport.Get(context.Background(), p...)
if err != nil {
t.Error(err)
}
if resp == nil {
t.Error("resp is nil")
}
})
}
paths := []string{
"/interfaces/interface",
"system/config/hostname",
}
type fields struct {
opt *GnmiTransportOptions
}
type args struct {
ctx context.Context
params []string
}
tests := []struct {
name string
fields fields
args args
want interface{}
wantErr bool
}{
{
name: "default",
fields: fields{opt: opt},
args: args{
ctx: context.Background(),
params: paths[:1],
},
want: gnmiMessages["../test/proto/resp-interfaces-arista-ceos"],
wantErr: false,
},
{
name: "destination unreachable",
fields: fields{opt: &GnmiTransportOptions{
Config: gnmi.Config{
Addr: "203.0.113.10:6030",
},
},
},
args: args{
ctx: context.Background(),
params: paths,
},
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g, err := NewGnmiTransport(tt.fields.opt)
if err != nil {
t.Error(err)
return
}
got, err := g.Get(tt.args.ctx, tt.args.params...)
if (err != nil) != tt.wantErr {
t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Get() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGnmi_SubscribeIntegration(t *testing.T) { func TestGnmi_SubscribeIntegration(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping integration test") t.Skip("skipping integration test")
} }
if os.Getenv("GOSDN_TEST_ENDPOINT") != "" {
t.Skip("skipping locally running integration test")
}
t.Run("Test GNMI Subscribe", func(t *testing.T) {
transport, err := NewGnmiTransport(opt)
if err != nil {
t.Error(err)
}
transport.RespChan = make(chan *gpb.SubscribeResponse)
paths := []string{"/interfaces/interface/name"} type fields struct {
opt *GnmiTransportOptions
opts := &gnmi.SubscribeOptions{ }
UpdatesOnly: false, type args struct {
Prefix: "", ctx context.Context
Mode: "stream", opts *gnmi.SubscribeOptions
StreamMode: "sample", }
SampleInterval: uint64(10 * time.Second.Nanoseconds()), tests := []struct {
SuppressRedundant: false, name string
HeartbeatInterval: uint64(time.Second.Nanoseconds()), fields fields
Paths: gnmi.SplitPaths(paths), args args
Origin: "", wantErr bool
Target: address, }{
} {
ctx := context.WithValue(context.Background(), "opts", opts) name: "default",
go func() { fields: fields{
if err := transport.Subscribe(ctx); err != nil { opt: &GnmiTransportOptions{
Config: opt.Config,
RespChan: make(chan *gpb.SubscribeResponse),
},
},
args: args{
ctx: context.Background(),
opts: &gnmi.SubscribeOptions{
Mode: "stream",
StreamMode: "sample",
SampleInterval: uint64(1 * time.Second),
HeartbeatInterval: uint64(100 * time.Millisecond),
Paths: gnmi.SplitPaths([]string{
"/interfaces/interface/name",
"/system/config/hostname",
}),
Target: address,
},
},
wantErr: false,
},
{
name: "wrong path",
fields: fields{
opt: &GnmiTransportOptions{
Config: opt.Config,
RespChan: make(chan *gpb.SubscribeResponse),
},
},
args: args{
opts: &gnmi.SubscribeOptions{
Mode: "stream",
StreamMode: "sample",
SampleInterval: uint64(1 * time.Second),
HeartbeatInterval: uint64(100 * time.Millisecond),
Paths: gnmi.SplitPaths([]string{
"interfaces/interface/name",
"ystem/config/hostname",
}),
Target: address,
},
},
wantErr: true,
},
{
name: "destination unreachable",
fields: fields{
opt: &GnmiTransportOptions{
Config: gnmi.Config{
Addr: "203.0.113.10:6030",
},
RespChan: make(chan *gpb.SubscribeResponse),
},
},
args: args{
opts: &gnmi.SubscribeOptions{},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g, err := NewGnmiTransport(tt.fields.opt)
if err != nil {
t.Error(err) t.Error(err)
return
} }
}() ctx := context.WithValue(context.Background(), "opts", tt.args.opts)
time.Sleep(time.Second * 30) ctx, cancel := context.WithCancel(ctx)
ctx.Done() go func() {
time.Sleep(time.Second * 5) err = g.Subscribe(ctx)
}) if (err != nil) != tt.wantErr {
if !tt.wantErr{
if err.Error() != "rpc error: code = Canceled desc = context canceled"{
t.Errorf("Subscribe() error = %v, wantErr %v", err, tt.wantErr)
}
}
}
}()
time.Sleep(time.Second * 3)
cancel()
time.Sleep(time.Second * 1)
})
}
} }
func TestGnmi_CapabilitiesIntegration(t *testing.T) { func TestGnmi_CapabilitiesIntegration(t *testing.T) {
...@@ -255,17 +372,3 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) { ...@@ -255,17 +372,3 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
}) })
} }
} }
func TestPndImplementation_RequestAllIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
t.Fail()
}
func TestPndImplementation_RequestIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
t.Fail()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment