/* 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 main 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]) } } }