diff --git a/.travis.yml b/.travis.yml index 28d41082267ceefa2ab179666d9389d6640015a3..7d38f8783aae1164c7ee368f63e1c37ada23a3a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: go go: - 1.x before_install: - - go get github.com/golang/lint/golint + - go get github.com/golang/lint/golint github.com/stretchr/testify/assert before_script: - go get -d ./... script: diff --git a/examples/simple/simple.go b/examples/simple/simple.go index c2584ef21ef79e3b537579599918156943a7925b..f43463efaf28f0992b89d76492c0c38d9e88f761 100644 --- a/examples/simple/simple.go +++ b/examples/simple/simple.go @@ -22,8 +22,7 @@ import ( ) func main() { - // Passing nil to this method results in all default values - c := client.NewHTTPClient(nil) + c := defaultClient() rs, err := c.Dcim.DcimRacksList(nil, nil) if err != nil { @@ -33,3 +32,10 @@ func main() { fmt.Printf("%v\n", *(rs.Payload.Count)) } + +func defaultClient() *client.NetBox { + // Passing nil to this method results in all default configuration for the client. + // That is, a client that connects to http://localhost:8000, and using default + // field formats. (e.g. remove '-' from json field names) + return client.NewHTTPClient(nil) +} \ No newline at end of file diff --git a/examples/simple/simple_test.go b/examples/simple/simple_test.go new file mode 100644 index 0000000000000000000000000000000000000000..7fdfd72817918c208f8a3e6cdce4f58a1e816417 --- /dev/null +++ b/examples/simple/simple_test.go @@ -0,0 +1,83 @@ +// +build integration + +// Copyright 2018 The go-netbox Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "testing" + "fmt" + + "github.com/digitalocean/go-netbox/netbox/client/dcim" + "github.com/digitalocean/go-netbox/netbox/models" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/runtime" + "github.com/stretchr/testify/assert" +) + +// These tests assume a netbox running locally, with the netbox test fixtures loaded. +// This is achievable with the following netbox management commands, after install: +// python3 netbox/manage.py loaddata dcim extras ipam +// python3 netbox/manage.py runserver 0.0.0.0:8000 --insecure + +func TestRetrieveDeviceList(t *testing.T) { + c := defaultClient() + + list, err := c.Dcim.DcimDevicesList(nil, nil) + + assert.NoError(t, err) + assert.EqualValues(t, 11, *list.Payload.Count) +} + +func TestSubdeviceRole(t *testing.T) { + c := defaultClient() + + role := true + manufacturerID := int64(1) + model := "Test model" + slug := "test-slug" + newDeviceType := &models.WritableDeviceType{ + SubdeviceRole: &role, + Comments: "Test device type", + Manufacturer: &manufacturerID, + Model: &model, + Slug: &slug, + } + err := newDeviceType.Validate(strfmt.Default) + assert.NoError(t, err) + + createRequest := dcim.NewDcimDeviceTypesCreateParams().WithData(newDeviceType) + createResponse, err := c.Dcim.DcimDeviceTypesCreate(createRequest, runtime.ClientAuthInfoWriterFunc(SetAuthenticationHeader)) + assert.NoError(t, err) + + newID := float64(createResponse.Payload.ID) + assert.NotEqual(t, 0, newID) + + retrieveResponse, err := c.Dcim.DcimDeviceTypesList(dcim.NewDcimDeviceTypesListParams().WithIDIn(&newID), nil) + assert.NoError(t, err) + assert.EqualValues(t, 1, *retrieveResponse.Payload.Count) + assert.EqualValues(t, "Test device type", retrieveResponse.Payload.Results[0].Comments) + + deleteRequest := dcim.NewDcimDeviceTypesDeleteParams().WithID(int64(newID)) + _, err = c.Dcim.DcimDeviceTypesDelete(deleteRequest, runtime.ClientAuthInfoWriterFunc(SetAuthenticationHeader)) + assert.NoError(t, err) +} + +const apiToken = "7b4e1ceaaf93528a41e64d048090f7fe13ed16f4" +const authHeaderFormat = "Token %v" +func SetAuthenticationHeader(req runtime.ClientRequest, _ strfmt.Registry) error { + req.SetHeaderParam("Authorization", fmt.Sprintf(authHeaderFormat, apiToken)) + return nil +} diff --git a/netbox/models/device_face.go b/netbox/models/device_face.go index d1f2a7377bf458ae83c32272139ab5798c323356..5b87c7726cfa2d12276b2f5eb51e77c7878a15eb 100644 --- a/netbox/models/device_face.go +++ b/netbox/models/device_face.go @@ -37,7 +37,7 @@ type DeviceFace struct { // value // Required: true - Value *bool `json:"value"` + Value *int64 `json:"value"` } // Validate validates this device face diff --git a/swagger.json b/swagger.json index 5cb7eba3afb11273cfc498769fef3db1203d8ea5..3ab436e29dea42be12a5ba1815694459d6ca2aa3 100644 --- a/swagger.json +++ b/swagger.json @@ -13985,7 +13985,7 @@ "type": "string" }, "value": { - "type": "boolean", + "type": "integer", "x-nullable": true } }