fix TF attestation version value assertion

This commit is contained in:
Adrian Stobbe 2024-07-09 10:34:02 +02:00
parent f4a3ae7d27
commit 5698f30a2e

View File

@ -7,6 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only
package provider
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@ -16,6 +17,21 @@ func TestAccAttestationSource(t *testing.T) {
// Set the path to the Terraform binary for acceptance testing when running under Bazel.
bazelPreCheck := func() { bazelSetTerraformBinaryPath(t) }
assertNonZeroValue := func(attr string) resource.TestCheckFunc {
return resource.TestMatchResourceAttr(
"data.constellation_attestation.test",
attr,
regexp.MustCompile(`^[1-9]\d*$`),
)
}
assertAnyDigitValue := func(attr string) resource.TestCheckFunc {
return resource.TestMatchResourceAttr(
"data.constellation_attestation.test",
attr,
regexp.MustCompile(`.*\d.*`),
)
}
testCases := map[string]resource.TestCase{
"azure sev-snp success": {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
@ -36,12 +52,10 @@ func TestAccAttestationSource(t *testing.T) {
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.variant", "azure-sev-snp"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.bootloader_version", "3"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.microcode_version", "115"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.snp_version", "8"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.tee_version", "0"),
assertNonZeroValue("attestation.bootloader_version"),
assertNonZeroValue("attestation.microcode_version"),
assertNonZeroValue("attestation.snp_version"),
assertAnyDigitValue("attestation.tee_version"), // the valid value is 0 at the moment
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.azure_firmware_signer_config.accepted_key_digests.0", "0356215882a825279a85b300b0b742931d113bf7e32dde2e50ffde7ec743ca491ecdd7f336dc28a6e0b2bb57af7a44a3"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.azure_firmware_signer_config.enforcement_policy", "MAAFallback"),
@ -128,7 +142,10 @@ func TestAccAttestationSource(t *testing.T) {
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.variant", "gcp-sev-snp"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.bootloader_version", "3"),
assertNonZeroValue("attestation.bootloader_version"),
assertNonZeroValue("attestation.microcode_version"),
assertNonZeroValue("attestation.snp_version"),
assertAnyDigitValue("attestation.tee_version"), // the valid value is 0 at the moment
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.measurements.1.expected", "3695dcc55e3aa34027c27793c85c723c697d708c42d1f73bd6fa4f26608a5b24"),
resource.TestCheckResourceAttr("data.constellation_attestation.test", "attestation.measurements.1.warn_only", "true"),
),