Add test cases

main
nleiva 2022-04-28 23:55:32 -04:00
parent 0124019fb3
commit d2ddeaaa5e
5 changed files with 44 additions and 36 deletions

View File

@ -3,7 +3,7 @@ HOSTNAME=github.com
NAMESPACE=nleiva
NAME=nautobot
BINARY=terraform-provider-${NAME}
VERSION=0.2.0
VERSION=0.2.1
OS_ARCH=$(shell go env GOOS)_$(shell go env GOARCH)

View File

@ -31,16 +31,16 @@ func dataSourceManufacturers() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"custom_fields": {
Description: "Manufacturer custom fields.",
Type: schema.TypeMap,
Optional: true,
},
"description": {
Description: "Manufacturer's description.",
Type: schema.TypeString,
Optional: true,
},
"custom_fields": {
Description: "Manufacturer custom fields.",
Type: schema.TypeMap,
Optional: true,
},
"devicetype_count": {
Description: "Manufacturer's device count.",
Type: schema.TypeInt,
@ -50,6 +50,7 @@ func dataSourceManufacturers() *schema.Resource {
Description: "Manufacturer's display name.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"id": {
Description: "Manufacturer's UUID.",
@ -80,11 +81,13 @@ func dataSourceManufacturers() *schema.Resource {
Description: "Manufacturer's slug.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"url": {
Description: "Manufacturer's URL.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},

View File

@ -1,13 +1,13 @@
package provider
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
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")
resource.UnitTest(t, resource.TestCase{
@ -17,15 +17,8 @@ func TestAccDataSourceManufacturers(t *testing.T) {
{
Config: testAccDataSourceManufacturer,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.nautobot_manufacturers.juniper", "name", "Juniper"),
),
},
{
Config: testAccDataSourceManufacturer,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.nautobot_manufacturers.juniper", "id", regexp.MustCompile("^4873d752")),
//resource.TestCheckResourceAttr("data.nautobot_manufacturers.list.manufacturers", "", ""),
resource.TestCheckOutput("vendor", "juniper"),
),
},
},
@ -33,17 +26,23 @@ func TestAccDataSourceManufacturers(t *testing.T) {
}
const testAccDataSourceManufacturer = `
resource "nautobot_manufacturer" "juniper" {
id = "4873d752-5dbe-4006-8345-8279a0dfbbda"
url = "https://develop.demo.nautobot.com/api/dcim/manufacturers/4873d752-5dbe-4006-8345-8279a0dfbbda/"
name = "Juniper"
slug = "juniper"
description = "Juniper Networks"
devicetype_count = 0
platform_count = 1
custom_fields = "{}"
created = "2022-03-08"
last_updated = "2022-03-08T14:50:48.492203Z"
display = "Juniper"
provider "nautobot" {
url = "https://demo.nautobot.com/api/"
token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
data "nautobot_manufacturers" "list" {}
variable "filter" {
type = string
default = "Juniper"
}
output "vendor" {
value = [
for manufacturer in data.nautobot_manufacturers.list.manufacturers :
manufacturer.slug
if manufacturer.name == var.filter
]
}
`

View File

@ -29,16 +29,16 @@ func resourceManufacturer() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"custom_fields": {
Description: "Manufacturer custom fields.",
Type: schema.TypeMap,
Optional: true,
},
"description": {
Description: "Manufacturer's description.",
Type: schema.TypeString,
Optional: true,
},
"custom_fields": {
Description: "Manufacturer custom fields.",
Type: schema.TypeMap,
Optional: true,
},
"devicetype_count": {
Description: "Manufacturer's device count.",
Type: schema.TypeInt,

View File

@ -18,15 +18,21 @@ func TestAccResourceManufacturer(t *testing.T) {
Config: testAccResourceManufacturer,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"nautobot_manufacturer.foo", "sample_attribute", regexp.MustCompile("^ba")),
"nautobot_manufacturer.test", "slug", regexp.MustCompile("^juniper$")),
),
},
},
})
}
const testAccResourceManufacturer = `
resource "nautobot_manufacturer" "foo" {
sample_attribute = "bar"
provider "nautobot" {
url = "https://demo.nautobot.com/api/"
token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
resource "nautobot_manufacturer" "test" {
name = "Juniper"
}
`