mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-25 23:49:37 -05:00
34bf3ad296
* terraform-provider: init Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * terraform-provider: add basic docgen Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * terraform-provider: fix build steps Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * terraform-provider: extend build process and docgen Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * dev-docs: document provider usage Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * bazel: upload aspect lib mirror Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * terraform-provider: don't try to create lockfiles Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * bazel: fix shellcheck issues * bazel: separate paths to check * terraform-provider: clean up old files * terraform-provider: update provider resource * terraform-provider: add image data source * dev-docs: remove unnecessary init * bazel: adhere to Terraform naming expectations * terraform-provider: fix expected data type * terraform-provider: generate docs * terraform-provider: improve errors * terraform-provider: add acceptance tests for data source * terraform-provider: fix dependencies * bazel: quote var reference * terraform-provider: make region optional * terraform-provider: bind imagefetcher to data source * bazel: tidy * terraform-provider: remove unused parameter * terraform-provider: remove unused parameter * terraform-provider: extend acceptance tests * terraform-provider: allow tests to be ran without Bazel * dev-docs: document testing * terraform-provider: set binary path accordingly * dev-docs: document docgen process for the provider * bazel: run acceptance test in writable environment * bazel: try to write to `$TMPDIR` * terraform-provider: style nits * terraform-provider: leave TODO * bazel: tidy * terraform-provider: regenerate docs * terraform-provider: fix comment --------- Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package provider
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/bazelbuild/rules_go/go/runfiles"
|
|
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
|
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
|
|
)
|
|
|
|
const (
|
|
// testingConfig is a shared configuration to combine with the actual
|
|
// test configuration so the constellation provider is properly configured
|
|
// for acceptance testing.
|
|
testingConfig = `provider "constellation" {}`
|
|
)
|
|
|
|
// testAccProtoV6ProviderFactories are used to instantiate a provider during
|
|
// acceptance testing. The factory function will be invoked for every Terraform
|
|
// CLI command executed to create a provider server to which the CLI can
|
|
// reattach.
|
|
var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
|
"constellation": providerserver.NewProtocol6WithError(New("test")()),
|
|
}
|
|
|
|
// bazelSetTerraformBinaryPath sets the path to the Terraform binary for
|
|
// acceptance testing when running under Bazel.
|
|
func bazelSetTerraformBinaryPath(t *testing.T) {
|
|
if v := os.Getenv("TF_ACC"); v != "1" {
|
|
t.Fatal("TF_ACC must be set to \"1\" for acceptance tests")
|
|
}
|
|
|
|
// If we don't run under Bazel, we need to use the host Terraform binary.
|
|
// Print a warning and return without setting the path.
|
|
if !runsUnderBazel() {
|
|
fmt.Println(
|
|
"Test is not runding under Bazel.\n" +
|
|
"Using Host Terraform binary for acceptance testing.\n" +
|
|
"Tests results may vary from the defaults (which run under Bazel).",
|
|
)
|
|
return
|
|
}
|
|
|
|
tfPath := os.Getenv("TF_ACC_TERRAFORM_PATH")
|
|
if tfPath == "" {
|
|
t.Fatal("TF_ACC_TERRAFORM_PATH must be set for acceptance tests")
|
|
}
|
|
|
|
absTfPath, err := runfiles.Rlocation(tfPath)
|
|
if err != nil {
|
|
panic("could not find path to artifact")
|
|
}
|
|
|
|
// Set the path to the absolute Terraform binary for acceptance testing.
|
|
t.Setenv("TF_ACC_TERRAFORM_PATH", absTfPath)
|
|
}
|
|
|
|
// runsUnderBazel checks whether the test is ran under bazel.
|
|
func runsUnderBazel() bool {
|
|
return runsUnder == "bazel"
|
|
}
|
|
|
|
// runsUnder is redefined only by the Bazel build at link time.
|
|
var runsUnder = "go"
|