diff --git a/go.sum b/go.sum index 29079212..ddf638e1 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/PaloAltoNetworks/pango v0.10.2 h1:Tjn6vIzzAq6Dd7N0mDuiP8w8pz8k5W9zz/TTSUQCsQY= github.com/PaloAltoNetworks/pango v0.10.2/go.mod h1:GztcRnVLur7G+VFG7Z5ZKNFgScLtsycwPMp1qVebE5g= -github.com/bl4ko/go-devicetype-library v0.1.9 h1:MEd7ebDDkLpwvQbiAHBqZWNfsjBqMCEHA/SygOGnQiM= -github.com/bl4ko/go-devicetype-library v0.1.9/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8= github.com/bl4ko/go-devicetype-library v0.1.10 h1:OJtTK1SXNbROn1M9XTmcpCJKkAsgvshX65ba9FiwcB0= github.com/bl4ko/go-devicetype-library v0.1.10/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8= github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY= diff --git a/internal/netbox/inventory/add_items_test.go b/internal/netbox/inventory/add_items_test.go index bdb8167c..9245f2a6 100644 --- a/internal/netbox/inventory/add_items_test.go +++ b/internal/netbox/inventory/add_items_test.go @@ -720,3 +720,157 @@ func TestNetboxInventory_AddPrefix(t *testing.T) { }) } } + +func TestNetboxInventory_AddVirtualDeviceContext(t *testing.T) { + type args struct { + ctx context.Context + newVDC *objects.VirtualDeviceContext + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.VirtualDeviceContext + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddVirtualDeviceContext(tt.args.ctx, tt.args.newVDC) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddVirtualDeviceContext() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddVirtualDeviceContext() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetboxInventory_AddWirelessLAN(t *testing.T) { + type args struct { + ctx context.Context + newWirelessLan *objects.WirelessLAN + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.WirelessLAN + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddWirelessLAN(tt.args.ctx, tt.args.newWirelessLan) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddWirelessLAN() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddWirelessLAN() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetboxInventory_AddWirelessLANGroup(t *testing.T) { + type args struct { + ctx context.Context + newWirelessLANGroup *objects.WirelessLANGroup + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.WirelessLANGroup + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddWirelessLANGroup(tt.args.ctx, tt.args.newWirelessLANGroup) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddWirelessLANGroup() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddWirelessLANGroup() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_addSourceNameCustomField(t *testing.T) { + type args struct { + ctx context.Context + netboxObject *objects.NetboxObject + } + tests := []struct { + name string + args args + want *objects.NetboxObject + }{ + { + name: "Add source custom field to netbox object", + args: args{ + ctx: context.WithValue(context.Background(), constants.CtxSourceKey, "testSource"), + netboxObject: &objects.NetboxObject{}, + }, + want: &objects.NetboxObject{ + CustomFields: map[string]interface{}{ + constants.CustomFieldSourceName: "testSource", + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + addSourceNameCustomField(tt.args.ctx, tt.args.netboxObject) + if !reflect.DeepEqual(tt.want, tt.args.netboxObject) { + t.Errorf("%+v != %+v", tt.want, tt.args.netboxObject) + } + }) + } +} + +func TestNetboxInventory_applyDeviceFieldLengthLimitations(t *testing.T) { + type args struct { + device *objects.Device + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Device + }{ + { + name: "Test applyDeviceFieldLengthLimitations", + nbi: MockInventory, + args: args{ + device: &objects.Device{ + Name: "too_long_name_too_long_name_too_long_name_too_long_name_too_long_name", + SerialNumber: "sjpqnnivlllbehccexqvlsxovizypvqdhyaaqptvaktnscbfjfownkdhwzckdhjzvpvkllaawxocwliaxhc", + AssetTag: "sjpqnnivlllbehccexqvlsxovizypvqdhyaaqptvaktnscbfjfownkdhwzckdhjzvpvkllaawxocwliaxhc", + }, + }, + want: &objects.Device{ + Name: "too_long_name_too_long_name_too_long_name_too_long_name_too_long", + SerialNumber: "sjpqnnivlllbehccexqvlsxovizypvqdhyaaqptvaktnscbfjf", + AssetTag: "sjpqnnivlllbehccexqvlsxovizypvqdhyaaqptvaktnscbfjf", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.nbi.applyDeviceFieldLengthLimitations(tt.args.device) + if !reflect.DeepEqual(tt.want, tt.args.device) { + t.Errorf("%+v != %+v", tt.want, tt.args) + } + }) + } +} diff --git a/internal/netbox/inventory/add_predefined_items_test.go b/internal/netbox/inventory/add_predefined_items_test.go new file mode 100644 index 00000000..5fd77e13 --- /dev/null +++ b/internal/netbox/inventory/add_predefined_items_test.go @@ -0,0 +1,171 @@ +package inventory + +import ( + "context" + "reflect" + "testing" + + "github.com/bl4ko/netbox-ssot/internal/netbox/objects" +) + +func TestNetboxInventory_AddContainerDeviceRole(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.DeviceRole + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddContainerDeviceRole(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddContainerDeviceRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddContainerDeviceRole() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetboxInventory_AddFirewallDeviceRole(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.DeviceRole + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddFirewallDeviceRole(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddFirewallDeviceRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddFirewallDeviceRole() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetboxInventory_AddSwitchDeviceRole(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.DeviceRole + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddSwitchDeviceRole(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddSwitchDeviceRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddSwitchDeviceRole() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetboxInventory_AddServerDeviceRole(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.DeviceRole + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddServerDeviceRole(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddServerDeviceRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddServerDeviceRole() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetboxInventory_AddVMDeviceRole(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.DeviceRole + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddVMDeviceRole(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddVMDeviceRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddVMDeviceRole() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetboxInventory_AddVMTemplateDeviceRole(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.DeviceRole + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.nbi.AddVMTemplateDeviceRole(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.AddVMTemplateDeviceRole() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.AddVMTemplateDeviceRole() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/netbox/inventory/delete_items_test.go b/internal/netbox/inventory/delete_items_test.go new file mode 100644 index 00000000..40d98d79 --- /dev/null +++ b/internal/netbox/inventory/delete_items_test.go @@ -0,0 +1,72 @@ +package inventory + +import ( + "testing" + + "github.com/bl4ko/netbox-ssot/internal/netbox/objects" +) + +func TestNetboxInventory_DeleteOrphans(t *testing.T) { + type args struct { + hard bool + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.DeleteOrphans(tt.args.hard); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.DeleteOrphans() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_hardDelete(t *testing.T) { + type args struct { + apiPath string + orphanItem objects.OrphanItem + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.hardDelete(tt.args.apiPath, tt.args.orphanItem); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.hardDelete() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_softDelete(t *testing.T) { + type args struct { + apiPath string + orphanItem objects.OrphanItem + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.softDelete(tt.args.apiPath, tt.args.orphanItem); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.softDelete() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/netbox/inventory/get_items_test.go b/internal/netbox/inventory/get_items_test.go new file mode 100644 index 00000000..73fc6a4b --- /dev/null +++ b/internal/netbox/inventory/get_items_test.go @@ -0,0 +1,406 @@ +package inventory + +import ( + "reflect" + "testing" + + "github.com/bl4ko/netbox-ssot/internal/constants" + "github.com/bl4ko/netbox-ssot/internal/netbox/objects" +) + +func TestNetboxInventory_GetTag(t *testing.T) { + type args struct { + tagName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Tag + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetTag(tt.args.tagName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetTag() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetTag() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetManufacturer(t *testing.T) { + type args struct { + manufacturerName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Manufacturer + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetManufacturer(tt.args.manufacturerName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetManufacturer() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetManufacturer() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetCustomField(t *testing.T) { + type args struct { + customFieldName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.CustomField + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetCustomField(tt.args.customFieldName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetCustomField() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetCustomField() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetVlan(t *testing.T) { + type args struct { + groupID int + vlanID int + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Vlan + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetVlan(tt.args.groupID, tt.args.vlanID) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetVlan() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetVlan() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetTenant(t *testing.T) { + type args struct { + tenantName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Tenant + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetTenant(tt.args.tenantName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetTenant() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetTenant() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetSite(t *testing.T) { + type args struct { + siteName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Site + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetSite(tt.args.siteName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetSite() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetSite() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetVlanGroup(t *testing.T) { + type args struct { + vlanGroupName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.VlanGroup + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetVlanGroup(tt.args.vlanGroupName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetVlanGroup() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetVlanGroup() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetClusterGroup(t *testing.T) { + type args struct { + clusterGroupName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.ClusterGroup + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetClusterGroup(tt.args.clusterGroupName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetClusterGroup() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetClusterGroup() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetCluster(t *testing.T) { + type args struct { + clusterName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Cluster + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetCluster(tt.args.clusterName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetCluster() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetCluster() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetDevice(t *testing.T) { + type args struct { + deviceName string + siteID int + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Device + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetDevice(tt.args.deviceName, tt.args.siteID) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetDevice() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetDevice() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetDeviceRole(t *testing.T) { + type args struct { + deviceRoleName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.DeviceRole + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetDeviceRole(tt.args.deviceRoleName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetDeviceRole() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetDeviceRole() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetContactRole(t *testing.T) { + type args struct { + contactRoleName string + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.ContactRole + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetContactRole(tt.args.contactRoleName) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetContactRole() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetContactRole() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetVirtualDeviceContext(t *testing.T) { + type args struct { + zoneName string + deviceID int + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.VirtualDeviceContext + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetVirtualDeviceContext(tt.args.zoneName, tt.args.deviceID) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetVirtualDeviceContext() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetVirtualDeviceContext() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetInterface(t *testing.T) { + type args struct { + interfaceName string + deviceID int + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.Interface + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetInterface(tt.args.interfaceName, tt.args.deviceID) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetInterface() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetInterface() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestNetboxInventory_GetContactAssignment(t *testing.T) { + type args struct { + contentType constants.ContentType + objectID int + contactID int + roleID int + } + tests := []struct { + name string + nbi *NetboxInventory + args args + want *objects.ContactAssignment + want1 bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := tt.nbi.GetContactAssignment(tt.args.contentType, tt.args.objectID, tt.args.contactID, tt.args.roleID) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NetboxInventory.GetContactAssignment() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("NetboxInventory.GetContactAssignment() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} diff --git a/internal/netbox/inventory/init_items_test.go b/internal/netbox/inventory/init_items_test.go index 62e888b3..a40cdbdc 100644 --- a/internal/netbox/inventory/init_items_test.go +++ b/internal/netbox/inventory/init_items_test.go @@ -550,3 +550,633 @@ func TestNetboxInventory_InitPrefixes(t *testing.T) { }) } } + +func TestNetboxInventory_initTags(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initTags(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initTags() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initTenants(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initTenants(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initTenants() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initContacts(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initContacts(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initContacts() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initContactRoles(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initContactRoles(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initContactRoles() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initContactAssignments(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initContactAssignments(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initContactAssignments() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initAdminContactRole(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initAdminContactRole(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initAdminContactRole() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initContactGroups(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initContactGroups(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initContactGroups() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initSites(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initSites(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initSites() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initDefaultSite(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initDefaultSite(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initDefaultSite() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initManufacturers(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initManufacturers(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initManufacturers() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initPlatforms(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initPlatforms(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initPlatforms() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initDevices(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initDevices(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initDevices() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initVirtualDeviceContexts(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initVirtualDeviceContexts(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initVirtualDeviceContexts() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initDeviceRoles(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initDeviceRoles(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initDeviceRoles() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initCustomFields(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initCustomFields(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initCustomFields() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initSsotCustomFields(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initSsotCustomFields(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initSsotCustomFields() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initClusterGroups(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initClusterGroups(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initClusterGroups() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initClusterTypes(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initClusterTypes(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initClusterTypes() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initClusters(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initClusters(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initClusters() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initDeviceTypes(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initDeviceTypes(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initDeviceTypes() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initInterfaces(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initInterfaces(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initInterfaces() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initDefaultVlanGroup(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initDefaultVlanGroup(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initDefaultVlanGroup() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initVlanGroups(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initVlanGroups(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initVlanGroups() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initVlans(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initVlans(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initVlans() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initVMs(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initVMs(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initVMs() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initVMInterfaces(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initVMInterfaces(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initVMInterfaces() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initIPAddresses(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initIPAddresses(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initIPAddresses() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initPrefixes(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initPrefixes(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initPrefixes() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initWirelessLANs(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initWirelessLANs(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initWirelessLANs() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNetboxInventory_initWirelessLANGroups(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + nbi *NetboxInventory + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.initWirelessLANGroups(tt.args.ctx); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.initWirelessLANGroups() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/netbox/inventory/inventory_test.go b/internal/netbox/inventory/inventory_test.go index 8bfc8d6f..84ff889b 100644 --- a/internal/netbox/inventory/inventory_test.go +++ b/internal/netbox/inventory/inventory_test.go @@ -64,3 +64,20 @@ func TestNetboxInventory_Init(t *testing.T) { }) } } + +func TestNetboxInventory_checkVersion(t *testing.T) { + tests := []struct { + name string + nbi *NetboxInventory + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.nbi.checkVersion(); (err != nil) != tt.wantErr { + t.Errorf("NetboxInventory.checkVersion() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/netbox/inventory/orphan_manager_test.go b/internal/netbox/inventory/orphan_manager_test.go new file mode 100644 index 00000000..6f60e041 --- /dev/null +++ b/internal/netbox/inventory/orphan_manager_test.go @@ -0,0 +1,67 @@ +package inventory + +import ( + "reflect" + "testing" + + "github.com/bl4ko/netbox-ssot/internal/logger" + "github.com/bl4ko/netbox-ssot/internal/netbox/objects" +) + +func TestNewOrphanManager(t *testing.T) { + type args struct { + logger *logger.Logger + } + tests := []struct { + name string + args args + want *OrphanManager + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewOrphanManager(tt.args.logger); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewOrphanManager() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestOrphanManager_AddItem(t *testing.T) { + type args struct { + itemAPIPath string + orphanItem objects.OrphanItem + } + tests := []struct { + name string + orphanManager *OrphanManager + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(_ *testing.T) { + tt.orphanManager.AddItem(tt.args.itemAPIPath, tt.args.orphanItem) + }) + } +} + +func TestOrphanManager_RemoveItem(t *testing.T) { + type args struct { + itemAPIPath string + obj objects.OrphanItem + } + tests := []struct { + name string + orphanManager *OrphanManager + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(_ *testing.T) { + tt.orphanManager.RemoveItem(tt.args.itemAPIPath, tt.args.obj) + }) + } +} diff --git a/internal/netbox/inventory/test_objects.go b/internal/netbox/inventory/test_objects.go index f723508f..36e65a68 100644 --- a/internal/netbox/inventory/test_objects.go +++ b/internal/netbox/inventory/test_objects.go @@ -1,10 +1,12 @@ package inventory import ( + "context" "log" "os" "sync" + "github.com/bl4ko/netbox-ssot/internal/constants" "github.com/bl4ko/netbox-ssot/internal/logger" "github.com/bl4ko/netbox-ssot/internal/netbox/objects" "github.com/bl4ko/netbox-ssot/internal/netbox/service" @@ -70,6 +72,7 @@ var MockInventory = &NetboxInventory{ sitesIndexByName: MockExistingSites, sitesLock: sync.Mutex{}, NetboxAPI: service.MockNetboxClient, + Ctx: context.WithValue(context.Background(), constants.CustomFieldSourceName, "testInventory"), //nolint SsotTag: &objects.Tag{ ID: 0, Name: "netbox-ssot",