Skip to content

Commit

Permalink
test: adding tests for inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed Nov 27, 2024
1 parent d72c34a commit ba4eac8
Show file tree
Hide file tree
Showing 9 changed files with 1,520 additions and 2 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
154 changes: 154 additions & 0 deletions internal/netbox/inventory/add_items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
171 changes: 171 additions & 0 deletions internal/netbox/inventory/add_predefined_items_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading

0 comments on commit ba4eac8

Please sign in to comment.