Move integration tests
This commit is contained in:
parent
ce9f27913f
commit
af589e9fc0
14 changed files with 174 additions and 193 deletions
10
circuits.go
10
circuits.go
|
@ -96,10 +96,10 @@ type Circuits struct {
|
|||
UpstreamSpeed int `json:"upstream_speed"`
|
||||
XconnectID string `json:"xconnect_id"`
|
||||
} `json:"termination_z"`
|
||||
Comments string `json:"comments"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
Comments string `json:"comments"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
|
20
clusters.go
20
clusters.go
|
@ -44,11 +44,11 @@ type NewCluster struct {
|
|||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
}
|
||||
|
||||
// Clusters is used to list VirtualizationClusters
|
||||
|
@ -87,11 +87,11 @@ type Clusters struct {
|
|||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
|
|
10
devices.go
10
devices.go
|
@ -138,13 +138,9 @@ type Device struct {
|
|||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields,omitempty"`
|
||||
ConfigContext struct {
|
||||
AdditionalProp1 string `json:"additionalProp1"`
|
||||
AdditionalProp2 string `json:"additionalProp2"`
|
||||
AdditionalProp3 string `json:"additionalProp3"`
|
||||
} `json:"config_context"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
ConfigContext interface{} `json:"config_context"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
}
|
||||
|
||||
type NewDevice struct {
|
||||
|
|
59
devices_integration_test.go
Normal file
59
devices_integration_test.go
Normal 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()
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
30
netbox.go
30
netbox.go
|
@ -16,36 +16,6 @@ import (
|
|||
"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
|
||||
type Client struct {
|
||||
// DCIM *DCIM
|
||||
|
|
28
prefixes.go
28
prefixes.go
|
@ -16,17 +16,17 @@ type PrefixesService service
|
|||
|
||||
// NewPrefix is used for the return values from Netbox API ipam_prefixes_create
|
||||
type NewPrefix struct {
|
||||
Prefix string `json:"prefix"`
|
||||
Site int `json:"site"`
|
||||
Vrf int `json:"vrf"`
|
||||
Tenant int `json:"tenant"`
|
||||
VLAN int `json:"vlan"`
|
||||
Status int `json:"status"`
|
||||
Role int `json:"role"`
|
||||
IsPool bool `json:"is_pool"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Prefix string `json:"prefix"`
|
||||
Site int `json:"site"`
|
||||
Vrf int `json:"vrf"`
|
||||
Tenant int `json:"tenant"`
|
||||
VLAN int `json:"vlan"`
|
||||
Status int `json:"status"`
|
||||
Role int `json:"role"`
|
||||
IsPool bool `json:"is_pool"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
}
|
||||
|
||||
// Prefixes is used for the return value from NetBox API ipam_prefixes_list
|
||||
|
@ -88,9 +88,9 @@ type Prefixes struct {
|
|||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ type Secrets struct {
|
|||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,12 @@ type SiteGroup struct {
|
|||
SiteCount int `json:"site_count"`
|
||||
Depth int `json:"_depth"`
|
||||
} `json:"parent"`
|
||||
Description string `json:"description"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
SiteCount int `json:"site_count"`
|
||||
Depth int `json:"_depth"`
|
||||
Description string `json:"description"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
SiteCount int `json:"site_count"`
|
||||
Depth int `json:"_depth"`
|
||||
}
|
||||
|
||||
// SiteFilter is used to filter out returned object from Netbox API tenancy_tenants_list
|
||||
|
|
18
sites.go
18
sites.go
|
@ -74,15 +74,15 @@ type Site struct {
|
|||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CircuitCount int `json:"circuit_count"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
RackCount int `json:"rack_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
VlanCount int `json:"vlan_count"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CircuitCount int `json:"circuit_count"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
RackCount int `json:"rack_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
VlanCount int `json:"vlan_count"`
|
||||
}
|
||||
|
||||
// SiteFilter is used to filter out returned object from Netbox API tenancy_tenants_list
|
||||
|
|
48
tenants.go
48
tenants.go
|
@ -14,13 +14,13 @@ type TenantsService service
|
|||
|
||||
// NewTenant is used for the return values from Netbox API tenancy_tenants_create
|
||||
type NewTenant struct {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Group int `json:"group"`
|
||||
Description string `json:"description"`
|
||||
Comments string `json:"comments"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Group int `json:"group"`
|
||||
Description string `json:"description"`
|
||||
Comments string `json:"comments"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
}
|
||||
|
||||
// Tenants is used for the return value from NetBox API tenancy_tenants_list
|
||||
|
@ -38,25 +38,21 @@ type Tenants struct {
|
|||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
} `json:"group"`
|
||||
Description string `json:"description"`
|
||||
Comments string `json:"comments"`
|
||||
Tags []interface{} `json:"tags"`
|
||||
CustomFields struct {
|
||||
AccountNumber string `json:"account_number"`
|
||||
AtlasCustNumber interface{} `json:"atlas_cust_number"`
|
||||
TextField interface{} `json:"text_field"`
|
||||
} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CircuitCount interface{} `json:"circuit_count"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
IpaddressCount interface{} `json:"ipaddress_count"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
RackCount interface{} `json:"rack_count"`
|
||||
SiteCount int `json:"site_count"`
|
||||
VirtualmachineCount interface{} `json:"virtualmachine_count"`
|
||||
VlanCount int `json:"vlan_count"`
|
||||
VrfCount interface{} `json:"vrf_count"`
|
||||
Description string `json:"description"`
|
||||
Comments string `json:"comments"`
|
||||
Tags []interface{} `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CircuitCount interface{} `json:"circuit_count"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
IpaddressCount interface{} `json:"ipaddress_count"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
RackCount interface{} `json:"rack_count"`
|
||||
SiteCount int `json:"site_count"`
|
||||
VirtualmachineCount interface{} `json:"virtualmachine_count"`
|
||||
VlanCount int `json:"vlan_count"`
|
||||
VrfCount interface{} `json:"vrf_count"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
|
|
|
@ -69,20 +69,16 @@ type NewVirtualMachine struct {
|
|||
Family int `json:"family"`
|
||||
Address string `json:"address"`
|
||||
} `json:"primary_ip6"`
|
||||
Vcpus int `json:"vcpus"`
|
||||
Memory int `json:"memory"`
|
||||
Disk int `json:"disk"`
|
||||
Comments string `json:"comments"`
|
||||
LocalContextData string `json:"local_context_data"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
ConfigContext struct {
|
||||
AdditionalProp1 string `json:"additionalProp1"`
|
||||
AdditionalProp2 string `json:"additionalProp2"`
|
||||
AdditionalProp3 string `json:"additionalProp3"`
|
||||
} `json:"config_context"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
Vcpus int `json:"vcpus"`
|
||||
Memory int `json:"memory"`
|
||||
Disk int `json:"disk"`
|
||||
Comments string `json:"comments"`
|
||||
LocalContextData string `json:"local_context_data"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
ConfigContext interface{} `json:"config_context"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
}
|
||||
|
||||
const virtualMachinesPath = virtualizationPath + "/virtual-machines"
|
||||
|
|
34
vlans.go
34
vlans.go
|
@ -14,16 +14,16 @@ type VLANsService service
|
|||
|
||||
// NewVLAN is used for the return values from Netbox API ipam_vlans_create
|
||||
type NewVLAN struct {
|
||||
Site int `json:"site"`
|
||||
Group int `json:"group"`
|
||||
Vid int `json:"vid"`
|
||||
Name string `json:"name"`
|
||||
Tenant int `json:"tenant"`
|
||||
Status int `json:"status"`
|
||||
Role int `json:"role"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Site int `json:"site"`
|
||||
Group int `json:"group"`
|
||||
Vid int `json:"vid"`
|
||||
Name string `json:"name"`
|
||||
Tenant int `json:"tenant"`
|
||||
Status int `json:"status"`
|
||||
Role int `json:"role"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
}
|
||||
|
||||
type VLAN struct {
|
||||
|
@ -61,13 +61,13 @@ type VLAN struct {
|
|||
PrefixCount int `json:"prefix_count"`
|
||||
VLANCount int `json:"vlan_count"`
|
||||
} `json:"role"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
DisplayName string `json:"display_name"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
DisplayName string `json:"display_name"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
}
|
||||
|
||||
// IpamVLANsList is used for the return value from NetBox API ipam_vlans_list
|
||||
|
|
32
vrfs.go
32
vrfs.go
|
@ -14,13 +14,13 @@ type VRFsService service
|
|||
|
||||
// NewVRF is used for the return values from Netbox API ipam_vrfs_create
|
||||
type NewVRF struct {
|
||||
Name string `json:"name"`
|
||||
Rd string `json:"rd"`
|
||||
Tenant int `json:"tenant"`
|
||||
EnforceUnique bool `json:"enforce_unique"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Name string `json:"name"`
|
||||
Rd string `json:"rd"`
|
||||
Tenant int `json:"tenant"`
|
||||
EnforceUnique bool `json:"enforce_unique"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
}
|
||||
|
||||
// VRFs is used for the return value from NetBox API ipam_vrfs_list
|
||||
|
@ -38,15 +38,15 @@ type VRFs struct {
|
|||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
} `json:"tenant"`
|
||||
EnforceUnique bool `json:"enforce_unique"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
DisplayName string `json:"display_name"`
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
IpaddressCount int `json:"ipaddress_count"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
EnforceUnique bool `json:"enforce_unique"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
DisplayName string `json:"display_name"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
IpaddressCount int `json:"ipaddress_count"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue