ci: fix TF attestation version assertion in integration test (#3237)

This commit is contained in:
Adrian Stobbe 2024-07-10 09:56:36 +02:00 committed by GitHub
parent 5d25eded1d
commit 051cb20b09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,8 @@ SPDX-License-Identifier: AGPL-3.0-only
package provider
import (
"errors"
"strconv"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@ -16,6 +18,30 @@ 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.TestCheckResourceAttrWith(
"data.constellation_attestation.test",
attr,
func(value string) error {
parsedValue, err := strconv.ParseUint(value, 10, 8)
if err == nil && parsedValue == 0 {
return errors.New("expected non-zero value")
}
return err
},
)
}
assertUint8Value := func(attr string) resource.TestCheckFunc {
return resource.TestCheckResourceAttrWith(
"data.constellation_attestation.test",
attr,
func(value string) error {
_, err := strconv.ParseUint(value, 10, 8)
return err
},
)
}
testCases := map[string]resource.TestCase{
"azure sev-snp success": {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
@ -36,12 +62,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"),
assertUint8Value("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 +152,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"),
assertUint8Value("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"),
),