mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Riley Karson](/assets/img/avatar_default.png)
* Vendor GCP Compute Beta client library. * Refactor resource_compute_instance_group_manager for multi version support (#129) * Refactor resource_compute_instance_group_manager for multi version support. * Minor changes based on review. * Removed type-specific API version conversion functions. * Add support for Beta operations. * Add v0beta support to google_compute_instance_group_manager. * Renamed Key to Feature, added comments & updated some parameter names. * Fix code and tests for version finder to match fields that don't have a change. * Store non-v1 resources' self links as v1 so that dependent single-version resources don't see diffs. * Fix weird change to vendor.json from merge. * Add a note that Convert loses ForceSendFields, fix failing test. * Moved nil type to a switch case in compute_shared_operation.go. * Move base api version declaration above schema.
106 lines
3.3 KiB
Go
106 lines
3.3 KiB
Go
package google
|
|
|
|
import "testing"
|
|
|
|
func TestResourceWithOnlyBaseVersionFields(t *testing.T) {
|
|
d := &ResourceDataMock{
|
|
FieldsInSchema: []string{"normal_field"},
|
|
}
|
|
|
|
resourceVersion := v1
|
|
computeApiVersion := getComputeApiVersion(d, resourceVersion, []Feature{})
|
|
if computeApiVersion != resourceVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", resourceVersion, computeApiVersion)
|
|
}
|
|
|
|
computeApiVersion = getComputeApiVersionUpdate(d, resourceVersion, []Feature{}, []Feature{})
|
|
if computeApiVersion != resourceVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", resourceVersion, computeApiVersion)
|
|
}
|
|
}
|
|
|
|
func TestResourceWithBetaFields(t *testing.T) {
|
|
resourceVersion := v1
|
|
d := &ResourceDataMock{
|
|
FieldsInSchema: []string{"normal_field", "beta_field"},
|
|
}
|
|
|
|
expectedVersion := v0beta
|
|
computeApiVersion := getComputeApiVersion(d, resourceVersion, []Feature{{Version: expectedVersion, Item: "beta_field"}})
|
|
if computeApiVersion != expectedVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", expectedVersion, computeApiVersion)
|
|
}
|
|
|
|
computeApiVersion = getComputeApiVersionUpdate(d, resourceVersion, []Feature{{Version: expectedVersion, Item: "beta_field"}}, []Feature{})
|
|
if computeApiVersion != expectedVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", expectedVersion, computeApiVersion)
|
|
}
|
|
}
|
|
|
|
func TestResourceWithBetaFieldsNotInSchema(t *testing.T) {
|
|
resourceVersion := v1
|
|
d := &ResourceDataMock{
|
|
FieldsInSchema: []string{"normal_field"},
|
|
}
|
|
|
|
expectedVersion := v1
|
|
computeApiVersion := getComputeApiVersion(d, resourceVersion, []Feature{{Version: expectedVersion, Item: "beta_field"}})
|
|
if computeApiVersion != expectedVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", expectedVersion, computeApiVersion)
|
|
}
|
|
|
|
computeApiVersion = getComputeApiVersionUpdate(d, resourceVersion, []Feature{{Version: expectedVersion, Item: "beta_field"}}, []Feature{})
|
|
if computeApiVersion != expectedVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", expectedVersion, computeApiVersion)
|
|
}
|
|
}
|
|
|
|
func TestResourceWithBetaUpdateFields(t *testing.T) {
|
|
resourceVersion := v1
|
|
d := &ResourceDataMock{
|
|
FieldsInSchema: []string{"normal_field", "beta_update_field"},
|
|
FieldsWithHasChange: []string{"beta_update_field"},
|
|
}
|
|
|
|
expectedVersion := v1
|
|
computeApiVersion := getComputeApiVersion(d, resourceVersion, []Feature{})
|
|
if computeApiVersion != expectedVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", expectedVersion, computeApiVersion)
|
|
}
|
|
|
|
expectedVersion = v0beta
|
|
computeApiVersion = getComputeApiVersionUpdate(d, resourceVersion, []Feature{}, []Feature{{Version: expectedVersion, Item: "beta_update_field"}})
|
|
if computeApiVersion != expectedVersion {
|
|
t.Errorf("Expected to see version: %v. Saw version: %v.", expectedVersion, computeApiVersion)
|
|
}
|
|
|
|
}
|
|
|
|
type ResourceDataMock struct {
|
|
FieldsInSchema []string
|
|
FieldsWithHasChange []string
|
|
}
|
|
|
|
func (d *ResourceDataMock) HasChange(key string) bool {
|
|
exists := false
|
|
for _, val := range d.FieldsWithHasChange {
|
|
if key == val {
|
|
exists = true
|
|
}
|
|
}
|
|
|
|
return exists
|
|
}
|
|
|
|
func (d *ResourceDataMock) GetOk(key string) (interface{}, bool) {
|
|
exists := false
|
|
for _, val := range d.FieldsInSchema {
|
|
if key == val {
|
|
exists = true
|
|
}
|
|
|
|
}
|
|
|
|
return nil, exists
|
|
}
|