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/structure/test.go
Pavel Boldyrev 1f006aa82b
feat: API client cleanup and refactoring (#323)
* cleanup 1

* continue refactoring

* more refactoring

* move VMs under nodes

* move container and other apis under nodes

* cleanups

* enabled revive.exported linter & add comments to exported stuff

* enable godot linter

* enable wsl linter

* enable thelper linter

* enable govet linter

* cleanup after rebase

* cleanup after rebase

* extract SSH ops into a separate interface

* fix linter error

* move ssh code to its own package

* cleaning up VirtualEnvironmentClient receivers

* on the finish line

* not sure what else I forgot... 🤔

* fix ssh connection and upload

* renaming client interfaces

* final cleanups
2023-05-26 01:32:51 +00:00

71 lines
2.4 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 structure
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// AssertComputedAttributes asserts that the given keys are present in the schema and are computed.
func AssertComputedAttributes(t *testing.T, s map[string]*schema.Schema, keys []string) {
t.Helper()
for _, v := range keys {
require.NotNil(t, s[v], "Error in Schema: Missing definition for \"%s\"", v)
assert.True(t, s[v].Computed, "Error in Schema: Attribute \"%s\" is not computed", v)
}
}
// AssertNestedSchemaExistence asserts that the given key is present in the schema and is a nested schema.
func AssertNestedSchemaExistence(t *testing.T, s map[string]*schema.Schema, key string) *schema.Resource {
t.Helper()
sh, ok := s[key].Elem.(*schema.Resource)
if !ok {
t.Fatalf("Error in Schema: Missing nested schema for \"%s\"", key)
return nil
}
return sh
}
// AssertOptionalArguments asserts that the given keys are present in the schema and are optional.
func AssertOptionalArguments(t *testing.T, s map[string]*schema.Schema, keys []string) {
t.Helper()
for _, v := range keys {
require.NotNil(t, s[v], "Error in Schema: Missing definition for \"%s\"", v)
assert.True(t, s[v].Optional, "Error in Schema: Argument \"%s\" is not optional", v)
}
}
// AssertRequiredArguments asserts that the given keys are present in the schema and are required.
func AssertRequiredArguments(t *testing.T, s map[string]*schema.Schema, keys []string) {
t.Helper()
for _, v := range keys {
require.NotNil(t, s[v], "Error in Schema: Missing definition for \"%s\"", v)
assert.True(t, s[v].Required, "Error in Schema: Argument \"%s\" is not required", v)
}
}
// AssertValueTypes asserts that the given keys are present in the schema and are of the given type.
func AssertValueTypes(t *testing.T, s map[string]*schema.Schema, f map[string]schema.ValueType) {
t.Helper()
for fn, ft := range f {
require.NotNil(t, s[fn], "Error in Schema: Missing definition for \"%s\"", fn)
assert.Equal(t, ft, s[fn].Type, "Error in Schema: Argument or attribute \"%s\" is not of type \"%v\"", fn, ft)
}
}