Add test cases
parent
0124019fb3
commit
d2ddeaaa5e
|
|
@ -3,7 +3,7 @@ HOSTNAME=github.com
|
||||||
NAMESPACE=nleiva
|
NAMESPACE=nleiva
|
||||||
NAME=nautobot
|
NAME=nautobot
|
||||||
BINARY=terraform-provider-${NAME}
|
BINARY=terraform-provider-${NAME}
|
||||||
VERSION=0.2.0
|
VERSION=0.2.1
|
||||||
OS_ARCH=$(shell go env GOOS)_$(shell go env GOARCH)
|
OS_ARCH=$(shell go env GOOS)_$(shell go env GOARCH)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,16 @@ func dataSourceManufacturers() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
"custom_fields": {
|
|
||||||
Description: "Manufacturer custom fields.",
|
|
||||||
Type: schema.TypeMap,
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"description": {
|
"description": {
|
||||||
Description: "Manufacturer's description.",
|
Description: "Manufacturer's description.",
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
"custom_fields": {
|
||||||
|
Description: "Manufacturer custom fields.",
|
||||||
|
Type: schema.TypeMap,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
"devicetype_count": {
|
"devicetype_count": {
|
||||||
Description: "Manufacturer's device count.",
|
Description: "Manufacturer's device count.",
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
|
|
@ -50,6 +50,7 @@ func dataSourceManufacturers() *schema.Resource {
|
||||||
Description: "Manufacturer's display name.",
|
Description: "Manufacturer's display name.",
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
},
|
},
|
||||||
"id": {
|
"id": {
|
||||||
Description: "Manufacturer's UUID.",
|
Description: "Manufacturer's UUID.",
|
||||||
|
|
@ -80,11 +81,13 @@ func dataSourceManufacturers() *schema.Resource {
|
||||||
Description: "Manufacturer's slug.",
|
Description: "Manufacturer's slug.",
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
},
|
},
|
||||||
"url": {
|
"url": {
|
||||||
Description: "Manufacturer's URL.",
|
Description: "Manufacturer's URL.",
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
package provider
|
package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccDataSourceManufacturers(t *testing.T) {
|
func TestAccDataSourceManufacturers(t *testing.T) {
|
||||||
|
// https://github.com/hashicorp/terraform-plugin-sdk/issues/952
|
||||||
t.Skip("resource not yet implemented, remove this once you add your own code")
|
t.Skip("resource not yet implemented, remove this once you add your own code")
|
||||||
|
|
||||||
resource.UnitTest(t, resource.TestCase{
|
resource.UnitTest(t, resource.TestCase{
|
||||||
|
|
@ -17,15 +17,8 @@ func TestAccDataSourceManufacturers(t *testing.T) {
|
||||||
{
|
{
|
||||||
Config: testAccDataSourceManufacturer,
|
Config: testAccDataSourceManufacturer,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
//resource.TestCheckResourceAttr("data.nautobot_manufacturers.list.manufacturers", "", ""),
|
||||||
"data.nautobot_manufacturers.juniper", "name", "Juniper"),
|
resource.TestCheckOutput("vendor", "juniper"),
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Config: testAccDataSourceManufacturer,
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
|
||||||
resource.TestMatchResourceAttr(
|
|
||||||
"data.nautobot_manufacturers.juniper", "id", regexp.MustCompile("^4873d752")),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -33,17 +26,23 @@ func TestAccDataSourceManufacturers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccDataSourceManufacturer = `
|
const testAccDataSourceManufacturer = `
|
||||||
resource "nautobot_manufacturer" "juniper" {
|
provider "nautobot" {
|
||||||
id = "4873d752-5dbe-4006-8345-8279a0dfbbda"
|
url = "https://demo.nautobot.com/api/"
|
||||||
url = "https://develop.demo.nautobot.com/api/dcim/manufacturers/4873d752-5dbe-4006-8345-8279a0dfbbda/"
|
token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||||
name = "Juniper"
|
}
|
||||||
slug = "juniper"
|
|
||||||
description = "Juniper Networks"
|
data "nautobot_manufacturers" "list" {}
|
||||||
devicetype_count = 0
|
|
||||||
platform_count = 1
|
variable "filter" {
|
||||||
custom_fields = "{}"
|
type = string
|
||||||
created = "2022-03-08"
|
default = "Juniper"
|
||||||
last_updated = "2022-03-08T14:50:48.492203Z"
|
}
|
||||||
display = "Juniper"
|
|
||||||
|
output "vendor" {
|
||||||
|
value = [
|
||||||
|
for manufacturer in data.nautobot_manufacturers.list.manufacturers :
|
||||||
|
manufacturer.slug
|
||||||
|
if manufacturer.name == var.filter
|
||||||
|
]
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
|
|
@ -29,16 +29,16 @@ func resourceManufacturer() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
"custom_fields": {
|
|
||||||
Description: "Manufacturer custom fields.",
|
|
||||||
Type: schema.TypeMap,
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"description": {
|
"description": {
|
||||||
Description: "Manufacturer's description.",
|
Description: "Manufacturer's description.",
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
"custom_fields": {
|
||||||
|
Description: "Manufacturer custom fields.",
|
||||||
|
Type: schema.TypeMap,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
"devicetype_count": {
|
"devicetype_count": {
|
||||||
Description: "Manufacturer's device count.",
|
Description: "Manufacturer's device count.",
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,21 @@ func TestAccResourceManufacturer(t *testing.T) {
|
||||||
Config: testAccResourceManufacturer,
|
Config: testAccResourceManufacturer,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestMatchResourceAttr(
|
resource.TestMatchResourceAttr(
|
||||||
"nautobot_manufacturer.foo", "sample_attribute", regexp.MustCompile("^ba")),
|
"nautobot_manufacturer.test", "slug", regexp.MustCompile("^juniper$")),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccResourceManufacturer = `
|
const testAccResourceManufacturer = `
|
||||||
resource "nautobot_manufacturer" "foo" {
|
provider "nautobot" {
|
||||||
sample_attribute = "bar"
|
url = "https://demo.nautobot.com/api/"
|
||||||
|
token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "nautobot_manufacturer" "test" {
|
||||||
|
name = "Juniper"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue