From 5e187d370b27183c93e4d005b10bc1d9a662d0b1 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Wed, 10 Feb 2021 19:26:21 +0100 Subject: [PATCH] adapted the testcase blueprints --- nucleus/device_test.go | 4 +- nucleus/principalNetworkDomain_test.go | 114 +++++++++++++++++-------- nucleus/southbound_test.go | 4 +- 3 files changed, 83 insertions(+), 39 deletions(-) diff --git a/nucleus/device_test.go b/nucleus/device_test.go index a452c7912..d98401ba9 100644 --- a/nucleus/device_test.go +++ b/nucleus/device_test.go @@ -8,7 +8,7 @@ import ( func TestDevice_Add(t *testing.T) { type fields struct { - Device ygot.GoStruct + ygot.GoStruct SBI SouthboundInterface Config DeviceConfig Transport Transport @@ -26,7 +26,7 @@ func TestDevice_Add(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { d := Device{ - Device: tt.fields.Device, + GoStruct: tt.fields.SBI.Schema().Root, SBI: tt.fields.SBI, Config: tt.fields.Config, Transport: tt.fields.Transport, diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index fab425652..a5712e995 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -9,6 +9,7 @@ import ( func TestNewPND(t *testing.T) { type args struct { name string + desc string sbi SouthboundInterface } tests := []struct { @@ -20,7 +21,7 @@ func TestNewPND(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := NewPND(tt.args.name, tt.args.sbi); !reflect.DeepEqual(got, tt.want) { + if got := NewPND(tt.args.name, tt.args.desc, tt.args.sbi); !reflect.DeepEqual(got, tt.want) { t.Errorf("NewPND() = %v, want %v", got, tt.want) } }) @@ -28,15 +29,32 @@ func TestNewPND(t *testing.T) { } func Test_addSbi(t *testing.T) { + type fields struct { + name string + desc string + sbi map[string]SouthboundInterface + devices map[uuid.UUID]*Device + } + type args struct { + sbi SouthboundInterface + } 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) { - if err := addSbi(); (err != nil) != tt.wantErr { + pnd := &pndImplementation{ + name: tt.fields.name, + description: tt.fields.desc, + sbi: tt.fields.sbi, + devices: tt.fields.devices, + } + if err := pnd.addSbi(tt.args.sbi); (err != nil) != tt.wantErr { t.Errorf("addSbi() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -62,8 +80,9 @@ func Test_destroy(t *testing.T) { func Test_pndImplementation_AddDevice(t *testing.T) { type fields struct { name string + desc string sbi map[string]SouthboundInterface - devices map[uuid.UUID]Device + devices map[uuid.UUID]*Device } type args struct { device Device @@ -79,11 +98,12 @@ func Test_pndImplementation_AddDevice(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pnd := &pndImplementation{ - Name: tt.fields.name, - Sbi: tt.fields.sbi, - Devices: tt.fields.devices, + name: tt.fields.name, + description: tt.fields.desc, + sbi: tt.fields.sbi, + devices: tt.fields.devices, } - if err := pnd.AddDevice(tt.args.device); (err != nil) != tt.wantErr { + if err := pnd.AddDevice(&tt.args.device); (err != nil) != tt.wantErr { t.Errorf("AddDevice() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -94,11 +114,15 @@ func Test_pndImplementation_AddSbi(t *testing.T) { type fields struct { name string sbi map[string]SouthboundInterface - devices map[uuid.UUID]Device + devices map[uuid.UUID]*Device + } + type args struct { + sbi SouthboundInterface } tests := []struct { name string fields fields + args args wantErr bool }{ // TODO: Add test cases. @@ -106,11 +130,11 @@ func Test_pndImplementation_AddSbi(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pnd := &pndImplementation{ - Name: tt.fields.name, - Sbi: tt.fields.sbi, - Devices: tt.fields.devices, + name: tt.fields.name, + sbi: tt.fields.sbi, + devices: tt.fields.devices, } - if err := pnd.AddSbi(); (err != nil) != tt.wantErr { + if err := pnd.AddSbi(tt.args.sbi); (err != nil) != tt.wantErr { t.Errorf("AddSbi() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -121,7 +145,7 @@ func Test_pndImplementation_Destroy(t *testing.T) { type fields struct { name string sbi map[string]SouthboundInterface - devices map[uuid.UUID]Device + devices map[uuid.UUID]*Device } tests := []struct { name string @@ -133,9 +157,9 @@ func Test_pndImplementation_Destroy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pnd := &pndImplementation{ - Name: tt.fields.name, - Sbi: tt.fields.sbi, - Devices: tt.fields.devices, + name: tt.fields.name, + sbi: tt.fields.sbi, + devices: tt.fields.devices, } if err := pnd.Destroy(); (err != nil) != tt.wantErr { t.Errorf("Destroy() error = %v, wantErr %v", err, tt.wantErr) @@ -148,7 +172,7 @@ func Test_pndImplementation_RemoveDevice(t *testing.T) { type fields struct { name string sbi map[string]SouthboundInterface - devices map[uuid.UUID]Device + devices map[uuid.UUID]*Device } type args struct { uuid uuid.UUID @@ -164,9 +188,9 @@ func Test_pndImplementation_RemoveDevice(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pnd := &pndImplementation{ - Name: tt.fields.name, - Sbi: tt.fields.sbi, - Devices: tt.fields.devices, + name: tt.fields.name, + sbi: tt.fields.sbi, + devices: tt.fields.devices, } if err := pnd.RemoveDevice(tt.args.uuid); (err != nil) != tt.wantErr { t.Errorf("RemoveDevice() error = %v, wantErr %v", err, tt.wantErr) @@ -179,11 +203,15 @@ func Test_pndImplementation_RemoveSbi(t *testing.T) { type fields struct { name string sbi map[string]SouthboundInterface - devices map[uuid.UUID]Device + devices map[uuid.UUID]*Device + } + type args struct { + sbi SouthboundInterface } tests := []struct { name string fields fields + args args wantErr bool }{ // TODO: Add test cases. @@ -191,11 +219,11 @@ func Test_pndImplementation_RemoveSbi(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pnd := &pndImplementation{ - Name: tt.fields.name, - Sbi: tt.fields.sbi, - Devices: tt.fields.devices, + name: tt.fields.name, + sbi: tt.fields.sbi, + devices: tt.fields.devices, } - if err := pnd.RemoveSbi(); (err != nil) != tt.wantErr { + if err := pnd.RemoveSbi(tt.args.sbi.SbiIdentifier()); (err != nil) != tt.wantErr { t.Errorf("RemoveSbi() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -206,7 +234,7 @@ func Test_pndImplementation_addDevice(t *testing.T) { type fields struct { name string sbi map[string]SouthboundInterface - devices map[uuid.UUID]Device + devices map[uuid.UUID]*Device } type args struct { device Device @@ -222,11 +250,11 @@ func Test_pndImplementation_addDevice(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pnd := &pndImplementation{ - Name: tt.fields.name, - Sbi: tt.fields.sbi, - Devices: tt.fields.devices, + name: tt.fields.name, + sbi: tt.fields.sbi, + devices: tt.fields.devices, } - if err := pnd.addDevice(tt.args.device); (err != nil) != tt.wantErr { + if err := pnd.addDevice(&tt.args.device); (err != nil) != tt.wantErr { t.Errorf("addDevice() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -237,7 +265,7 @@ func Test_pndImplementation_removeDevice(t *testing.T) { type fields struct { name string sbi map[string]SouthboundInterface - devices map[uuid.UUID]Device + devices map[uuid.UUID]*Device } type args struct { uuid uuid.UUID @@ -253,9 +281,9 @@ func Test_pndImplementation_removeDevice(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pnd := &pndImplementation{ - Name: tt.fields.name, - Sbi: tt.fields.sbi, - Devices: tt.fields.devices, + name: tt.fields.name, + sbi: tt.fields.sbi, + devices: tt.fields.devices, } if err := pnd.removeDevice(tt.args.uuid); (err != nil) != tt.wantErr { t.Errorf("removeDevice() error = %v, wantErr %v", err, tt.wantErr) @@ -265,15 +293,31 @@ func Test_pndImplementation_removeDevice(t *testing.T) { } func Test_removeSbi(t *testing.T) { + type fields struct { + name string + sbi map[string]SouthboundInterface + devices map[uuid.UUID]*Device + } + type args struct { + uuid uuid.UUID + sbi SouthboundInterface + } 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) { - if err := removeSbi(); (err != nil) != tt.wantErr { + pnd := &pndImplementation{ + name: tt.fields.name, + sbi: tt.fields.sbi, + devices: tt.fields.devices, + } + if err := pnd.removeSbi(tt.args.sbi.SbiIdentifier()); (err != nil) != tt.wantErr { t.Errorf("removeSbi() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/nucleus/southbound_test.go b/nucleus/southbound_test.go index 04b7456fb..72536cbbb 100644 --- a/nucleus/southbound_test.go +++ b/nucleus/southbound_test.go @@ -16,7 +16,7 @@ func TestOpenConfig_SbiIdentifier(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { oc := &OpenConfig{ - Transport: tt.fields.transport, + transport: tt.fields.transport, } if got := oc.SbiIdentifier(); got != tt.want { t.Errorf("SbiIdentifier() = %v, want %v", got, tt.want) @@ -42,7 +42,7 @@ func TestOpenConfig_OpenconfigInterfaces(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { oc := &OpenConfig{ - Transport: tt.fields.transport, + transport: tt.fields.transport, } oc.OpenconfigInterfaces(tt.args.device) }) -- GitLab