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

@ -98,7 +98,7 @@ type Circuits struct {
} `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,7 +44,7 @@ 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"`
@ -87,7 +87,7 @@ 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"`

View file

@ -138,11 +138,7 @@ 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"`
AdditionalProp2 string `json:"additionalProp2"`
AdditionalProp3 string `json:"additionalProp3"`
} `json:"config_context"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
} }

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

@ -26,7 +26,7 @@ type NewPrefix struct {
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,7 +88,7 @@ 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,7 +42,7 @@ 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

@ -35,7 +35,7 @@ type SiteGroup struct {
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"`

View file

@ -74,7 +74,7 @@ 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"`

View file

@ -20,7 +20,7 @@ type NewTenant struct {
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
@ -41,11 +41,7 @@ type Tenants struct {
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"`
AtlasCustNumber interface{} `json:"atlas_cust_number"`
TextField interface{} `json:"text_field"`
} `json:"custom_fields"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
CircuitCount interface{} `json:"circuit_count"` CircuitCount interface{} `json:"circuit_count"`

View file

@ -75,12 +75,8 @@ type NewVirtualMachine struct {
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"`
AdditionalProp2 string `json:"additionalProp2"`
AdditionalProp3 string `json:"additionalProp3"`
} `json:"config_context"`
Created string `json:"created"` Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"` LastUpdated time.Time `json:"last_updated"`
} }

View file

@ -23,7 +23,7 @@ type NewVLAN struct {
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 {
@ -64,7 +64,7 @@ type VLAN struct {
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"`

View file

@ -20,7 +20,7 @@ type NewVRF struct {
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
@ -42,7 +42,7 @@ type VRFs struct {
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"`