From c01d6b1e630dab27c646408f26d5a7131449d527 Mon Sep 17 00:00:00 2001 From: Dave Cameron <dcameron@digitalocean.com> Date: Thu, 8 Mar 2018 19:21:56 -0500 Subject: [PATCH] device_face is an integer enum, not boolean --- .travis.yml | 2 +- examples/simple/simple.go | 10 +++- examples/simple/simple_test.go | 83 ++++++++++++++++++++++++++++++++++ netbox/models/device_face.go | 2 +- swagger.json | 2 +- 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 examples/simple/simple_test.go diff --git a/.travis.yml b/.travis.yml index 28d4108..7d38f87 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 c2584ef..f43463e 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 0000000..7fdfd72 --- /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 d1f2a73..5b87c77 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 5cb7eba..3ab436e 100644 --- a/swagger.json +++ b/swagger.json @@ -13985,7 +13985,7 @@ "type": "string" }, "value": { - "type": "boolean", + "type": "integer", "x-nullable": true } } -- GitLab