Skip to content
Snippets Groups Projects
Select Git revision
  • d9e61f710aacd5aa1772a325cda8ed66393cfce9
  • master default
  • ui-handover
  • ui-update-yang
  • inventory-manager-netbox
  • heiss_bachelor_thesis
  • proto-getters
  • 392-remove-renovate
  • renovate/go.mongodb.org-mongo-driver-2.x
  • renovate/github.com-bufbuild-protovalidate-go-0.x
  • renovate/google.golang.org-genproto-googleapis-api-digest
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/eslint-9.x-lockfile
  • renovate/eslint-plugin-react-7.x-lockfile
  • renovate/dompurify-3.x-lockfile
  • renovate/testing-library-react-16.x-lockfile
  • renovate/eslint-plugin-prettier-5.x-lockfile
  • renovate/react-dom-18.x-lockfile
  • renovate/eslint-plugin-react-hooks-5.x-lockfile
  • renovate/testing-library-user-event-14.x-lockfile
  • renovate/reduxjs-toolkit-2.x-lockfile
  • renovate/github.com-openconfig-gnmi-0.x
  • 0.1.0
23 results

southbound_test.go

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    southbound_test.go 4.41 KiB
    package nucleus
    
    import (
    	"reflect"
    	"testing"
    
    	spb "code.fbi.h-da.de/danet/api/go/gosdn/southbound"
    
    	"code.fbi.h-da.de/danet/gosdn/nucleus/util/path"
    	"code.fbi.h-da.de/danet/gosdn/nucleus/util/proto"
    	"code.fbi.h-da.de/danet/yang-models/generated/openconfig"
    	"github.com/google/uuid"
    	gpb "github.com/openconfig/gnmi/proto/gnmi"
    	"github.com/openconfig/ygot/ygot"
    	"github.com/openconfig/ygot/ytypes"
    )
    
    func TestOpenConfig_Id(t *testing.T) {
    	type fields struct {
    		schema *ytypes.Schema
    		id     uuid.UUID
    	}
    	tests := []struct {
    		name   string
    		fields fields
    		want   uuid.UUID
    	}{
    		{
    			name: "default",
    			fields: fields{
    				schema: nil,
    				id:     ocUUID,
    			},
    			want: ocUUID,
    		},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			oc := &OpenConfig{
    				schema: tt.fields.schema,
    				id:     tt.fields.id,
    			}
    			if got := oc.ID(); !reflect.DeepEqual(got, tt.want) {
    				t.Errorf("ID() = %v, want %v", got, tt.want)
    			}
    		})
    	}
    }
    
    func TestOpenConfig_SbiIdentifier(t *testing.T) {
    	type fields struct {
    		schema *ytypes.Schema
    		id     uuid.UUID
    	}
    	tests := []struct {
    		name   string
    		fields fields
    		want   string
    	}{
    		{name: "default", fields: fields{}, want: "openconfig"},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			oc := &OpenConfig{
    				schema: tt.fields.schema,
    				id:     tt.fields.id,
    			}
    			if got := oc.SbiIdentifier(); got != tt.want {
    				t.Errorf("SbiIdentifier() = %v, want %v", got, tt.want)
    			}
    		})
    	}
    }
    
    func TestOpenConfig_Schema(t *testing.T) {
    	schema, err := openconfig.Schema()
    	if err != nil {
    		t.Error(err)
    	}
    	type fields struct {
    		schema *ytypes.Schema
    		id     uuid.UUID
    	}
    	tests := []struct {
    		name   string
    		fields fields
    		want   *ytypes.Schema
    	}{
    		{name: "default", fields: fields{}, want: schema},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			oc := &OpenConfig{
    				schema: tt.fields.schema,
    				id:     tt.fields.id,
    			}
    			got := oc.Schema().SchemaTree
    			if !reflect.DeepEqual(got, tt.want.SchemaTree) {
    				t.Errorf("Schema() = %v, want %v", got, tt.want)
    			}
    		})
    	}
    }
    
    func Test_unmarshal(t *testing.T) {
    	type args struct {
    		path     string
    		goStruct ygot.ValidatedGoStruct
    		opt      []ytypes.UnmarshalOpt
    	}
    	tests := []struct {
    		name    string
    		args    args
    		wantErr bool
    	}{
    		{
    			name: "interfaces-interface w/o opts",
    			args: args{
    				goStruct: &openconfig.Device{},
    				path:     "../test/proto/resp-interfaces-interface-arista-ceos",
    			},
    			wantErr: true,
    		},
    		{
    			name: "interfaces w/opts",
    			args: args{
    				path:     "../test/proto/resp-interfaces-arista-ceos",
    				goStruct: &openconfig.Device{},
    				opt:      []ytypes.UnmarshalOpt{&ytypes.IgnoreExtraFields{}},
    			},
    			wantErr: false,
    		},
    		{
    			name: "interfaces w/o opts",
    			args: args{
    				path:     "../test/proto/resp-interfaces-arista-ceos",
    				goStruct: &openconfig.Device{},
    				opt:      nil,
    			},
    			wantErr: true,
    		},
    		{
    			name: "root w/opts",
    			args: args{
    				path:     "../test/proto/resp-full-node-arista-ceos",
    				goStruct: &openconfig.Device{},
    				opt:      []ytypes.UnmarshalOpt{&ytypes.IgnoreExtraFields{}},
    			},
    			wantErr: false,
    		},
    		{
    			name: "root w/o opts",
    			args: args{
    				path:     "../test/proto/resp-full-node-arista-ceos",
    				goStruct: &openconfig.Device{},
    				opt:      nil,
    			},
    			wantErr: true,
    		},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			resp := &gpb.GetResponse{}
    			err := proto.Read(tt.args.path, resp)
    			if err != nil {
    				t.Error(err)
    			}
    			fields := path.ToStrings(resp.Notification[0].Update[0].Path)
    			bytes := resp.Notification[0].Update[0].Val.GetJsonIetfVal()
    			oc := NewSBI(spb.Type_OPENCONFIG)
    			if err := unmarshal(oc.Schema(), bytes, fields, tt.args.goStruct, tt.args.opt...); err != nil {
    				if !tt.wantErr {
    					t.Errorf("unmarshal() error = %v, wantErr %v", err, tt.wantErr)
    				}
    				return
    			}
    			if tt.args.goStruct.(*openconfig.Device).Interfaces == nil && tt.args.opt != nil {
    				t.Errorf("unmarshal() error: field Interfaces must not be nil")
    			}
    		})
    	}
    }
    
    func Test_CreateNewUUID(t *testing.T) {
    	sbi := NewSBI(spb.Type_OPENCONFIG)
    
    	if sbi.ID().String() == "" {
    		t.Errorf("sbi.ID().String() is not set.")
    	}
    }
    
    func Test_UseProvidedUUID(t *testing.T) {
    	providedSBIId := uuid.New()
    	sbi := NewSBI(spb.Type_OPENCONFIG, providedSBIId)
    
    	if sbi.ID() != providedSBIId {
    		t.Errorf("sbi.ID() is not %s. got=%s", providedSBIId.String(), sbi.ID().String())
    	}
    }