diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go index 8a2c22f5d59f02b71b76083ed0541f5ec6e26518..784a402513deb35423f1276accc9ba48c3299525 100644 --- a/nucleus/gnmi_transport.go +++ b/nucleus/gnmi_transport.go @@ -203,8 +203,10 @@ func (g *Gnmi) subscribe(ctx context.Context) error { go func() { for { resp := <-g.RespChan - if err := gnmi.LogSubscribeResponse(resp); err != nil { - log.Fatal(err) + if resp != nil { + if err := gnmi.LogSubscribeResponse(resp); err != nil { + log.Fatal(err) + } } } }() diff --git a/nucleus/integration_test.go b/nucleus/integration_test.go index c92ef12fd0d2dd0c13e14314844af46aeb8310af..6d19a85281d2a6fa206bbacf4719e453ab84f51b 100644 --- a/nucleus/integration_test.go +++ b/nucleus/integration_test.go @@ -5,6 +5,7 @@ import ( "code.fbi.h-da.de/cocsn/gosdn/nucleus/util" "context" gpb "github.com/openconfig/gnmi/proto/gnmi" + "reflect" "testing" "time" ) @@ -95,15 +96,14 @@ func TestGnmi_SubscribeIntegration(t *testing.T) { Target: address, } ctx := context.WithValue(context.Background(), "opts", opts) - d := time.Now().Add(60 * time.Second) - ctx, cancel := context.WithDeadline(ctx, d) - defer cancel() go func() { if err := transport.Subscribe(ctx); err != nil { t.Error(err) } }() - time.Sleep(time.Second * 50) + time.Sleep(time.Second * 30) + ctx.Done() + time.Sleep(time.Second * 5) }) } @@ -134,8 +134,8 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) { if err != nil { t.Error(err) } - if resp != v { - t.Error("resp is nil") + if !reflect.DeepEqual(resp, v) { + t.Errorf("Capabilities() = %v, want %v", resp, v) } }) }