Move integration tests

This commit is contained in:
Kalle Carlbark 2021-11-29 11:38:01 +01:00
parent ce9f27913f
commit af589e9fc0
No known key found for this signature in database
14 changed files with 174 additions and 193 deletions

View file

@ -96,10 +96,10 @@ type Circuits struct {
UpstreamSpeed int `json:"upstream_speed"` UpstreamSpeed int `json:"upstream_speed"`
XconnectID string `json:"xconnect_id"` XconnectID string `json:"xconnect_id"`
} `json:"termination_z"` } `json:"termination_z"`
Comments string `json:"comments"` Comments string `json:"comments"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
} `json:"results"` } `json:"results"`
} }

View file

@ -44,11 +44,11 @@ type NewCluster struct {
Slug string `json:"slug"` Slug string `json:"slug"`
Color string `json:"color"` Color string `json:"color"`
} `json:"tags"` } `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
DeviceCount int `json:"device_count"` DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"` VirtualmachineCount int `json:"virtualmachine_count"`
} }
// Clusters is used to list VirtualizationClusters // Clusters is used to list VirtualizationClusters
@ -87,11 +87,11 @@ type Clusters struct {
Slug string `json:"slug"` Slug string `json:"slug"`
Color string `json:"color"` Color string `json:"color"`
} `json:"tags"` } `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
DeviceCount int `json:"device_count"` DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"` VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"results"` } `json:"results"`
} }

View file

@ -138,13 +138,9 @@ type Device struct {
Color string `json:"color"` Color string `json:"color"`
} `json:"tags"` } `json:"tags"`
CustomFields interface{} `json:"custom_fields,omitempty"` CustomFields interface{} `json:"custom_fields,omitempty"`
ConfigContext struct { ConfigContext interface{} `json:"config_context"`
AdditionalProp1 string `json:"additionalProp1"` Created string `json:"created"`
AdditionalProp2 string `json:"additionalProp2"` LastUpdated time.Time `json:"last_updated"`
AdditionalProp3 string `json:"additionalProp3"`
} `json:"config_context"`
Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"`
} }
type NewDevice struct { type NewDevice struct {

View file

@ -0,0 +1,59 @@
//go:build integration
package netboxgo_test
import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
. "git.kcbark.net/kc/netboxgo"
)
func TestListDevices(t *testing.T) {
var err error
var (
apiToken string
apiURL string
)
apiToken = os.Getenv("NETBOX_TOKEN")
apiURL = os.Getenv("NETBOX_URL")
assert(t, true, apiToken)
assert(t, true, apiURL)
var nb *Client
nb, err = NewClient(apiURL, nil)
if err != nil {
ok(t, err)
}
nb.SetToken(apiToken)
ctx := context.Background()
_, err = nb.Devices.List(ctx, nil)
if err != nil {
ok(t, err)
}
}
// ok fails the test if an err is not nil.
func ok(tb testing.TB, err error) {
if err != nil {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
tb.FailNow()
}
}
// assert fails the test if the condition is false.
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
if !condition {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
tb.FailNow()
}
}

View file

@ -1,36 +0,0 @@
package netboxgo
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestListDevices(t *testing.T) {
var err error
var (
apiToken string
apiURL string
)
apiToken = os.Getenv("NETBOX_TOKEN")
apiURL = os.Getenv("NETBOX_URL")
assert.NotEmpty(t, apiToken)
assert.NotEmpty(t, apiURL)
var nb *Client
nb, err = NewClient(apiURL, nil)
if err != nil {
assert.Nil(t, err)
}
nb.SetToken(apiToken)
ctx := context.Background()
_, err = nb.Devices.List(ctx, nil)
if err != nil {
assert.Nil(t, err)
}
}

View file

@ -16,36 +16,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
type DCIM struct {
Devices *DevicesService
DeviceRoles *DeviceRolesService
DeviceTypes *DeviceTypesService
Interfaces *InterfacesService
InventoryItems *InventoryItemsService
RearPorts *RearPortsService
}
type Virtualization struct {
Clusters *ClustersService
VirtualMachines *VirtualMachinesService
}
type IPAM struct {
VLANs *VLANsService
VRFs *VRFsService
Prefixes *PrefixesService
}
type Secret struct {
Secrets *SecretsService
}
type Tenancy struct {
Tenants *TenantsService
Sites *SitesService
SiteGroups *SiteGroupsService
}
// Client struct is used to create a new NetBox endpoint // Client struct is used to create a new NetBox endpoint
type Client struct { type Client struct {
// DCIM *DCIM // DCIM *DCIM

View file

@ -16,17 +16,17 @@ type PrefixesService service
// NewPrefix is used for the return values from Netbox API ipam_prefixes_create // NewPrefix is used for the return values from Netbox API ipam_prefixes_create
type NewPrefix struct { type NewPrefix struct {
Prefix string `json:"prefix"` Prefix string `json:"prefix"`
Site int `json:"site"` Site int `json:"site"`
Vrf int `json:"vrf"` Vrf int `json:"vrf"`
Tenant int `json:"tenant"` Tenant int `json:"tenant"`
VLAN int `json:"vlan"` VLAN int `json:"vlan"`
Status int `json:"status"` Status int `json:"status"`
Role int `json:"role"` Role int `json:"role"`
IsPool bool `json:"is_pool"` IsPool bool `json:"is_pool"`
Description string `json:"description"` Description string `json:"description"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
} }
// Prefixes is used for the return value from NetBox API ipam_prefixes_list // Prefixes is used for the return value from NetBox API ipam_prefixes_list
@ -88,9 +88,9 @@ type Prefixes struct {
Slug string `json:"slug"` Slug string `json:"slug"`
Color string `json:"color"` Color string `json:"color"`
} `json:"tags"` } `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
} `json:"results"` } `json:"results"`
} }

View file

@ -42,9 +42,9 @@ type Secrets struct {
Slug string `json:"slug"` Slug string `json:"slug"`
Color string `json:"color"` Color string `json:"color"`
} `json:"tags"` } `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
} `json:"results"` } `json:"results"`
} }

View file

@ -34,12 +34,12 @@ type SiteGroup struct {
SiteCount int `json:"site_count"` SiteCount int `json:"site_count"`
Depth int `json:"_depth"` Depth int `json:"_depth"`
} `json:"parent"` } `json:"parent"`
Description string `json:"description"` Description string `json:"description"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
SiteCount int `json:"site_count"` SiteCount int `json:"site_count"`
Depth int `json:"_depth"` Depth int `json:"_depth"`
} }
// SiteFilter is used to filter out returned object from Netbox API tenancy_tenants_list // SiteFilter is used to filter out returned object from Netbox API tenancy_tenants_list

View file

@ -74,15 +74,15 @@ type Site struct {
Slug string `json:"slug"` Slug string `json:"slug"`
Color string `json:"color"` Color string `json:"color"`
} `json:"tags"` } `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
CircuitCount int `json:"circuit_count"` CircuitCount int `json:"circuit_count"`
DeviceCount int `json:"device_count"` DeviceCount int `json:"device_count"`
PrefixCount int `json:"prefix_count"` PrefixCount int `json:"prefix_count"`
RackCount int `json:"rack_count"` RackCount int `json:"rack_count"`
VirtualmachineCount int `json:"virtualmachine_count"` VirtualmachineCount int `json:"virtualmachine_count"`
VlanCount int `json:"vlan_count"` VlanCount int `json:"vlan_count"`
} }
// SiteFilter is used to filter out returned object from Netbox API tenancy_tenants_list // SiteFilter is used to filter out returned object from Netbox API tenancy_tenants_list

View file

@ -14,13 +14,13 @@ type TenantsService service
// NewTenant is used for the return values from Netbox API tenancy_tenants_create // NewTenant is used for the return values from Netbox API tenancy_tenants_create
type NewTenant struct { type NewTenant struct {
Name string `json:"name"` Name string `json:"name"`
Slug string `json:"slug"` Slug string `json:"slug"`
Group int `json:"group"` Group int `json:"group"`
Description string `json:"description"` Description string `json:"description"`
Comments string `json:"comments"` Comments string `json:"comments"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
} }
// Tenants is used for the return value from NetBox API tenancy_tenants_list // Tenants is used for the return value from NetBox API tenancy_tenants_list
@ -38,25 +38,21 @@ type Tenants struct {
Name string `json:"name"` Name string `json:"name"`
Slug string `json:"slug"` Slug string `json:"slug"`
} `json:"group"` } `json:"group"`
Description string `json:"description"` Description string `json:"description"`
Comments string `json:"comments"` Comments string `json:"comments"`
Tags []interface{} `json:"tags"` Tags []interface{} `json:"tags"`
CustomFields struct { CustomFields interface{} `json:"custom_fields"`
AccountNumber string `json:"account_number"` Created string `json:"created"`
AtlasCustNumber interface{} `json:"atlas_cust_number"` LastUpdated time.Time `json:"last_updated"`
TextField interface{} `json:"text_field"` CircuitCount interface{} `json:"circuit_count"`
} `json:"custom_fields"` DeviceCount int `json:"device_count"`
Created string `json:"created"` IpaddressCount interface{} `json:"ipaddress_count"`
LastUpdated time.Time `json:"last_updated"` PrefixCount int `json:"prefix_count"`
CircuitCount interface{} `json:"circuit_count"` RackCount interface{} `json:"rack_count"`
DeviceCount int `json:"device_count"` SiteCount int `json:"site_count"`
IpaddressCount interface{} `json:"ipaddress_count"` VirtualmachineCount interface{} `json:"virtualmachine_count"`
PrefixCount int `json:"prefix_count"` VlanCount int `json:"vlan_count"`
RackCount interface{} `json:"rack_count"` VrfCount interface{} `json:"vrf_count"`
SiteCount int `json:"site_count"`
VirtualmachineCount interface{} `json:"virtualmachine_count"`
VlanCount int `json:"vlan_count"`
VrfCount interface{} `json:"vrf_count"`
} `json:"results"` } `json:"results"`
} }

View file

@ -69,20 +69,16 @@ type NewVirtualMachine struct {
Family int `json:"family"` Family int `json:"family"`
Address string `json:"address"` Address string `json:"address"`
} `json:"primary_ip6"` } `json:"primary_ip6"`
Vcpus int `json:"vcpus"` Vcpus int `json:"vcpus"`
Memory int `json:"memory"` Memory int `json:"memory"`
Disk int `json:"disk"` Disk int `json:"disk"`
Comments string `json:"comments"` Comments string `json:"comments"`
LocalContextData string `json:"local_context_data"` LocalContextData string `json:"local_context_data"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
ConfigContext struct { ConfigContext interface{} `json:"config_context"`
AdditionalProp1 string `json:"additionalProp1"` Created string `json:"created"`
AdditionalProp2 string `json:"additionalProp2"` LastUpdated time.Time `json:"last_updated"`
AdditionalProp3 string `json:"additionalProp3"`
} `json:"config_context"`
Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"`
} }
const virtualMachinesPath = virtualizationPath + "/virtual-machines" const virtualMachinesPath = virtualizationPath + "/virtual-machines"

View file

@ -14,16 +14,16 @@ type VLANsService service
// NewVLAN is used for the return values from Netbox API ipam_vlans_create // NewVLAN is used for the return values from Netbox API ipam_vlans_create
type NewVLAN struct { type NewVLAN struct {
Site int `json:"site"` Site int `json:"site"`
Group int `json:"group"` Group int `json:"group"`
Vid int `json:"vid"` Vid int `json:"vid"`
Name string `json:"name"` Name string `json:"name"`
Tenant int `json:"tenant"` Tenant int `json:"tenant"`
Status int `json:"status"` Status int `json:"status"`
Role int `json:"role"` Role int `json:"role"`
Description string `json:"description"` Description string `json:"description"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
} }
type VLAN struct { type VLAN struct {
@ -61,13 +61,13 @@ type VLAN struct {
PrefixCount int `json:"prefix_count"` PrefixCount int `json:"prefix_count"`
VLANCount int `json:"vlan_count"` VLANCount int `json:"vlan_count"`
} `json:"role"` } `json:"role"`
Description string `json:"description"` Description string `json:"description"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
DisplayName string `json:"display_name"` DisplayName string `json:"display_name"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
PrefixCount int `json:"prefix_count"` PrefixCount int `json:"prefix_count"`
} }
// IpamVLANsList is used for the return value from NetBox API ipam_vlans_list // IpamVLANsList is used for the return value from NetBox API ipam_vlans_list

32
vrfs.go
View file

@ -14,13 +14,13 @@ type VRFsService service
// NewVRF is used for the return values from Netbox API ipam_vrfs_create // NewVRF is used for the return values from Netbox API ipam_vrfs_create
type NewVRF struct { type NewVRF struct {
Name string `json:"name"` Name string `json:"name"`
Rd string `json:"rd"` Rd string `json:"rd"`
Tenant int `json:"tenant"` Tenant int `json:"tenant"`
EnforceUnique bool `json:"enforce_unique"` EnforceUnique bool `json:"enforce_unique"`
Description string `json:"description"` Description string `json:"description"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
} }
// VRFs is used for the return value from NetBox API ipam_vrfs_list // VRFs is used for the return value from NetBox API ipam_vrfs_list
@ -38,15 +38,15 @@ type VRFs struct {
Name string `json:"name"` Name string `json:"name"`
Slug string `json:"slug"` Slug string `json:"slug"`
} `json:"tenant"` } `json:"tenant"`
EnforceUnique bool `json:"enforce_unique"` EnforceUnique bool `json:"enforce_unique"`
Description string `json:"description"` Description string `json:"description"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
DisplayName string `json:"display_name"` DisplayName string `json:"display_name"`
CustomFields struct{} `json:"custom_fields"` CustomFields interface{} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
IpaddressCount int `json:"ipaddress_count"` IpaddressCount int `json:"ipaddress_count"`
PrefixCount int `json:"prefix_count"` PrefixCount int `json:"prefix_count"`
} `json:"results"` } `json:"results"`
} }