0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-02 03:22:59 +00:00
terraform-provider-proxmox/proxmoxtf/utils.go
2019-12-15 16:45:40 +01:00

72 lines
1.8 KiB
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
package proxmoxtf
import (
"testing"
"github.com/hashicorp/terraform/helper/schema"
)
func testComputedAttributes(t *testing.T, s *schema.Resource, keys []string) {
for _, v := range keys {
if s.Schema[v] == nil {
t.Fatalf("Error in Schema: Missing definition for \"%s\"", v)
}
if s.Schema[v].Computed != true {
t.Fatalf("Error in Schema: Attribute \"%s\" is not computed", v)
}
}
}
func testNestedSchemaExistence(t *testing.T, s *schema.Resource, key string) *schema.Resource {
schema, ok := s.Schema[key].Elem.(*schema.Resource)
if !ok {
t.Fatalf("Error in Schema: Missing nested schema for \"%s\"", key)
return nil
}
return schema
}
func testOptionalArguments(t *testing.T, s *schema.Resource, keys []string) {
for _, v := range keys {
if s.Schema[v] == nil {
t.Fatalf("Error in Schema: Missing definition for \"%s\"", v)
}
if s.Schema[v].Optional != true {
t.Fatalf("Error in Schema: Argument \"%s\" is not optional", v)
}
}
}
func testRequiredArguments(t *testing.T, s *schema.Resource, keys []string) {
for _, v := range keys {
if s.Schema[v] == nil {
t.Fatalf("Error in Schema: Missing definition for \"%s\"", v)
}
if s.Schema[v].Required != true {
t.Fatalf("Error in Schema: Argument \"%s\" is not required", v)
}
}
}
func testSchemaValueTypes(t *testing.T, s *schema.Resource, keys []string, types []schema.ValueType) {
for i, v := range keys {
if s.Schema[v] == nil {
t.Fatalf("Error in Schema: Missing definition for \"%s\"", v)
}
if s.Schema[v].Type != types[i] {
t.Fatalf("Error in Schema: Argument \"%s\" is not of type \"%v\"", v, types[i])
}
}
}