mirror of
https://github.com/hashicorp/terraform.git
synced 2026-03-22 18:33:08 -04:00
* Add the ability to make a hash of state store config * Add test demonstrating that the provider block doesn't impact the hash of a state_store block * Make sure test asserts what would happen if the schema DID include the provider block * Update the Hash method to return diagnostics, ignore nested provider blocks, and validate incoming schema and config * Update tests to use more representative config, fix code under test as a result * Update Hash method to return hashes for both the state_store and provider blocks * Add test cases to cover how required fields are tolerated when making the hash This is because ENVs may supply those values. * Fix inaccurate comments * Add test to show that hashes are consistent and exclude the provider block * Update backend state file to contain hash of provider block's config * Fix test to expect a hash for the provider config block. * Fix bug in DeepCopy method, update test to have better error messages when diffs are detected * Update test to explicitly check hash values * Try make test intention clearer * Improve user feedback when state store schema contains the protected word "provider" * Update tests * Update test to test the Hash method in a more true-to-life way Copy of 04a1201878cd1f6f117c43c43c1ee9d0fc17cec1 by Radek Simko * Update test to use new approach * Fix `TestInit_stateStoreBlockIsExperimental` test failure
35 lines
937 B
Go
35 lines
937 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package workdir
|
|
|
|
import (
|
|
"testing"
|
|
|
|
version "github.com/hashicorp/go-version"
|
|
tfaddr "github.com/hashicorp/terraform-registry-address"
|
|
svchost "github.com/hashicorp/terraform-svchost"
|
|
)
|
|
|
|
// getTestProviderState is a test helper that returns a state representation
|
|
// of a provider used for managing state via pluggable state storage.
|
|
// The Hash is always hardcoded at 12345.
|
|
func getTestProviderState(t *testing.T, semVer, hostname, namespace, typeName, config string) *ProviderConfigState {
|
|
t.Helper()
|
|
|
|
ver, err := version.NewSemver(semVer)
|
|
if err != nil {
|
|
t.Fatalf("test setup failed when creating version.Version: %s", err)
|
|
}
|
|
|
|
return &ProviderConfigState{
|
|
Version: ver,
|
|
Source: &tfaddr.Provider{
|
|
Hostname: svchost.Hostname(hostname),
|
|
Namespace: namespace,
|
|
Type: typeName,
|
|
},
|
|
ConfigRaw: []byte(config),
|
|
Hash: 12345,
|
|
}
|
|
}
|