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) } }) } diff --git a/nucleus/southbound_test.go b/nucleus/southbound_test.go index 8063b8120a583ea1e547146225a0f7f431319f1d..ccd0d298a5aacbdc857db743cbf1ddb8f624ee9a 100644 --- a/nucleus/southbound_test.go +++ b/nucleus/southbound_test.go @@ -114,7 +114,8 @@ func TestOpenConfig_Schema(t *testing.T) { schema: tt.fields.schema, id: tt.fields.id, } - if got := oc.Schema(); !reflect.DeepEqual(got, tt.want) { + got := oc.Schema().SchemaTree + if !reflect.DeepEqual(got, tt.want.SchemaTree) { t.Errorf("Schema() = %v, want %v", got, tt.want) } }) diff --git a/nucleus/store_test.go b/nucleus/store_test.go index 8a393efd6b93204de7a993affc5ca1bd0b3ca42a..8a5f505093a312daf59602c0854a52917cd225c3 100644 --- a/nucleus/store_test.go +++ b/nucleus/store_test.go @@ -5,6 +5,7 @@ import ( "github.com/google/uuid" log "github.com/sirupsen/logrus" "reflect" + "sort" "testing" ) @@ -221,7 +222,14 @@ func Test_store_UUIDs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.s.UUIDs(); !reflect.DeepEqual(got, tt.want) { + sort.Slice(tt.want, func(i, j int) bool { + return tt.want[i].String() < tt.want[j].String() + }) + got := tt.s.UUIDs() + sort.Slice(got, func(i, j int) bool { + return got[i].String() < got[j].String() + }) + if !reflect.DeepEqual(got, tt.want) { t.Errorf("UUIDs() = %v, want %v", got, tt.want) } })