feat: testing (#34)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #34
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
parent
c22e758b2c
commit
32e41d8b44
24 changed files with 858 additions and 2431 deletions
11
stackit/internal/testutil/assert.go
Normal file
11
stackit/internal/testutil/assert.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package testutil
|
||||
|
||||
import "testing"
|
||||
|
||||
func Equal[V comparable](t *testing.T, got, expected V) {
|
||||
t.Helper()
|
||||
|
||||
if expected != got {
|
||||
t.Errorf("assert equal failed:\ngot: %v \nexpected: %v", got, expected)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
package testutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -20,7 +19,8 @@ import (
|
|||
|
||||
const (
|
||||
// Default location of credentials JSON
|
||||
credentialsFilePath = ".stackit/credentials.json" //nolint:gosec // linter false positive
|
||||
// credentialsFilePath = ".stackit/credentials.json" //nolint:gosec // linter false positive
|
||||
serviceAccountFilePath = ".stackit/service_account.json"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -29,7 +29,7 @@ var (
|
|||
// CLI command executed to create a provider server to which the CLI can
|
||||
// reattach.
|
||||
TestAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
||||
"stackit": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
"stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
}
|
||||
|
||||
// TestEphemeralAccProtoV6ProviderFactories is used to instantiate a provider during
|
||||
|
|
@ -40,8 +40,8 @@ var (
|
|||
// See the Terraform acceptance test documentation on ephemeral resources for more information:
|
||||
// https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/ephemeral-resources
|
||||
TestEphemeralAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
||||
"stackit": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
"echo": echoprovider.NewProviderServer(),
|
||||
"stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
"echo": echoprovider.NewProviderServer(),
|
||||
}
|
||||
|
||||
// E2ETestsEnabled checks if end-to-end tests should be run.
|
||||
|
|
@ -52,6 +52,8 @@ var (
|
|||
// ProjectId is the id of project used for tests
|
||||
ProjectId = os.Getenv("TF_ACC_PROJECT_ID")
|
||||
Region = os.Getenv("TF_ACC_REGION")
|
||||
// ServiceAccountFile is the json file of the service account
|
||||
ServiceAccountFile = os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE")
|
||||
// ServerId is the id of a server used for some tests
|
||||
ServerId = getenv("TF_ACC_SERVER_ID", "")
|
||||
// TestProjectParentContainerID is the container id of the parent resource under which projects are created as part of the resource-manager acceptance tests
|
||||
|
|
@ -97,26 +99,27 @@ var (
|
|||
|
||||
func ObservabilityProviderConfig() string {
|
||||
if ObservabilityCustomEndpoint == "" {
|
||||
return `provider "stackit" {
|
||||
return `provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
observability_custom_endpoint = "%s"
|
||||
}`,
|
||||
ObservabilityCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
func CdnProviderConfig() string {
|
||||
if CdnCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
cdn_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -126,10 +129,10 @@ func CdnProviderConfig() string {
|
|||
|
||||
func DnsProviderConfig() string {
|
||||
if DnsCustomEndpoint == "" {
|
||||
return `provider "stackit" {}`
|
||||
return `provider "stackitprivatepreview" {}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
dns_custom_endpoint = "%s"
|
||||
}`,
|
||||
DnsCustomEndpoint,
|
||||
|
|
@ -139,12 +142,12 @@ func DnsProviderConfig() string {
|
|||
func IaaSProviderConfig() string {
|
||||
if IaaSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
iaas_custom_endpoint = "%s"
|
||||
}`,
|
||||
IaaSCustomEndpoint,
|
||||
|
|
@ -154,13 +157,13 @@ func IaaSProviderConfig() string {
|
|||
func IaaSProviderConfigWithBetaResourcesEnabled() string {
|
||||
if IaaSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
enable_beta_resources = true
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
enable_beta_resources = true
|
||||
iaas_custom_endpoint = "%s"
|
||||
}`,
|
||||
|
|
@ -171,13 +174,13 @@ func IaaSProviderConfigWithBetaResourcesEnabled() string {
|
|||
func IaaSProviderConfigWithExperiments() string {
|
||||
if IaaSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
experiments = [ "routing-tables", "network" ]
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
iaas_custom_endpoint = "%s"
|
||||
experiments = [ "routing-tables", "network" ]
|
||||
}`,
|
||||
|
|
@ -188,12 +191,12 @@ func IaaSProviderConfigWithExperiments() string {
|
|||
func KMSProviderConfig() string {
|
||||
if KMSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
kms_custom_endpoint = "%s"
|
||||
}`,
|
||||
KMSCustomEndpoint,
|
||||
|
|
@ -203,12 +206,12 @@ func KMSProviderConfig() string {
|
|||
func LoadBalancerProviderConfig() string {
|
||||
if LoadBalancerCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
loadbalancer_custom_endpoint = "%s"
|
||||
}`,
|
||||
LoadBalancerCustomEndpoint,
|
||||
|
|
@ -218,12 +221,12 @@ func LoadBalancerProviderConfig() string {
|
|||
func LogMeProviderConfig() string {
|
||||
if LogMeCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
logme_custom_endpoint = "%s"
|
||||
}`,
|
||||
LogMeCustomEndpoint,
|
||||
|
|
@ -233,12 +236,12 @@ func LogMeProviderConfig() string {
|
|||
func MariaDBProviderConfig() string {
|
||||
if MariaDBCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
mariadb_custom_endpoint = "%s"
|
||||
}`,
|
||||
MariaDBCustomEndpoint,
|
||||
|
|
@ -248,13 +251,13 @@ func MariaDBProviderConfig() string {
|
|||
func ModelServingProviderConfig() string {
|
||||
if ModelServingCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}
|
||||
`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
modelserving_custom_endpoint = "%s"
|
||||
}`,
|
||||
ModelServingCustomEndpoint,
|
||||
|
|
@ -264,12 +267,12 @@ func ModelServingProviderConfig() string {
|
|||
func MongoDBFlexProviderConfig() string {
|
||||
if MongoDBFlexCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
mongodbflex_custom_endpoint = "%s"
|
||||
}`,
|
||||
MongoDBFlexCustomEndpoint,
|
||||
|
|
@ -279,12 +282,12 @@ func MongoDBFlexProviderConfig() string {
|
|||
func ObjectStorageProviderConfig() string {
|
||||
if ObjectStorageCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
objectstorage_custom_endpoint = "%s"
|
||||
}`,
|
||||
ObjectStorageCustomEndpoint,
|
||||
|
|
@ -294,29 +297,32 @@ func ObjectStorageProviderConfig() string {
|
|||
func OpenSearchProviderConfig() string {
|
||||
if OpenSearchCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
opensearch_custom_endpoint = "%s"
|
||||
}`,
|
||||
OpenSearchCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
func PostgresFlexProviderConfig() string {
|
||||
func PostgresFlexProviderConfig(saFile string) string {
|
||||
if PostgresFlexCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
return fmt.Sprintf(`
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
service_account_key_path = "%s"
|
||||
}`, saFile)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_key_path = "%s"
|
||||
postgresflex_custom_endpoint = "%s"
|
||||
}`,
|
||||
saFile,
|
||||
PostgresFlexCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
|
@ -324,12 +330,12 @@ func PostgresFlexProviderConfig() string {
|
|||
func RabbitMQProviderConfig() string {
|
||||
if RabbitMQCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
rabbitmq_custom_endpoint = "%s"
|
||||
}`,
|
||||
RabbitMQCustomEndpoint,
|
||||
|
|
@ -339,12 +345,12 @@ func RabbitMQProviderConfig() string {
|
|||
func RedisProviderConfig() string {
|
||||
if RedisCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
redis_custom_endpoint = "%s"
|
||||
}`,
|
||||
RedisCustomEndpoint,
|
||||
|
|
@ -352,53 +358,56 @@ func RedisProviderConfig() string {
|
|||
}
|
||||
|
||||
func ResourceManagerProviderConfig() string {
|
||||
token := GetTestProjectServiceAccountToken("")
|
||||
key := GetTestProjectServiceAccountJson("")
|
||||
if ResourceManagerCustomEndpoint == "" || AuthorizationCustomEndpoint == "" {
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
service_account_token = "%s"
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_key = "%s"
|
||||
}`,
|
||||
token,
|
||||
key,
|
||||
)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
resourcemanager_custom_endpoint = "%s"
|
||||
authorization_custom_endpoint = "%s"
|
||||
service_account_token = "%s"
|
||||
}`,
|
||||
ResourceManagerCustomEndpoint,
|
||||
AuthorizationCustomEndpoint,
|
||||
token,
|
||||
key,
|
||||
)
|
||||
}
|
||||
|
||||
func SecretsManagerProviderConfig() string {
|
||||
if SecretsManagerCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
secretsmanager_custom_endpoint = "%s"
|
||||
}`,
|
||||
SecretsManagerCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
func SQLServerFlexProviderConfig() string {
|
||||
func SQLServerFlexProviderConfig(saFile string) string {
|
||||
if SQLServerFlexCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
return fmt.Sprintf(`
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
service_account_key_path = "%s"
|
||||
}`, saFile)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_key_path = "%s"
|
||||
sqlserverflex_custom_endpoint = "%s"
|
||||
}`,
|
||||
saFile,
|
||||
SQLServerFlexCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
|
@ -406,13 +415,13 @@ func SQLServerFlexProviderConfig() string {
|
|||
func ServerBackupProviderConfig() string {
|
||||
if ServerBackupCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
server_backup_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -423,13 +432,13 @@ func ServerBackupProviderConfig() string {
|
|||
func ServerUpdateProviderConfig() string {
|
||||
if ServerUpdateCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
server_update_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -440,12 +449,12 @@ func ServerUpdateProviderConfig() string {
|
|||
func SKEProviderConfig() string {
|
||||
if SKECustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
ske_custom_endpoint = "%s"
|
||||
}`,
|
||||
SKECustomEndpoint,
|
||||
|
|
@ -455,13 +464,13 @@ func SKEProviderConfig() string {
|
|||
func AuthorizationProviderConfig() string {
|
||||
if AuthorizationCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
experiments = ["iam"]
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
authorization_custom_endpoint = "%s"
|
||||
experiments = ["iam"]
|
||||
}`,
|
||||
|
|
@ -472,13 +481,13 @@ func AuthorizationProviderConfig() string {
|
|||
func ServiceAccountProviderConfig() string {
|
||||
if ServiceAccountCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -489,13 +498,13 @@ func ServiceAccountProviderConfig() string {
|
|||
func GitProviderConfig() string {
|
||||
if GitCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
git_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -506,12 +515,12 @@ func GitProviderConfig() string {
|
|||
func ScfProviderConfig() string {
|
||||
if ScfCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
scf_custom_endpoint = "%s"
|
||||
}`,
|
||||
|
|
@ -526,11 +535,11 @@ func ResourceNameWithDateTime(name string) string {
|
|||
return fmt.Sprintf("tf-acc-%s-%s", name, dateTimeTrimmed)
|
||||
}
|
||||
|
||||
func GetTestProjectServiceAccountToken(path string) string {
|
||||
func GetTestProjectServiceAccountJson(path string) string {
|
||||
var err error
|
||||
token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN")
|
||||
token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_JSON")
|
||||
if !tokenSet || token == "" {
|
||||
token, err = readTestTokenFromCredentialsFile(path)
|
||||
token, err = readTestServiceAccountJsonFromFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -538,11 +547,53 @@ func GetTestProjectServiceAccountToken(path string) string {
|
|||
return token
|
||||
}
|
||||
|
||||
func readTestTokenFromCredentialsFile(path string) (string, error) {
|
||||
//func GetTestProjectServiceAccountToken(path string) string {
|
||||
// var err error
|
||||
// token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN")
|
||||
// if !tokenSet || token == "" {
|
||||
// token, err = readTestTokenFromCredentialsFile(path)
|
||||
// if err != nil {
|
||||
// return ""
|
||||
// }
|
||||
// }
|
||||
// return token
|
||||
//}
|
||||
//
|
||||
//func readTestTokenFromCredentialsFile(path string) (string, error) {
|
||||
// if path == "" {
|
||||
// customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH")
|
||||
// if !customPathSet || customPath == "" {
|
||||
// path = credentialsFilePath
|
||||
// home, err := os.UserHomeDir()
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("getting home directory: %w", err)
|
||||
// }
|
||||
// path = filepath.Join(home, path)
|
||||
// } else {
|
||||
// path = customPath
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// credentialsRaw, err := os.ReadFile(path)
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("opening file: %w", err)
|
||||
// }
|
||||
//
|
||||
// var credentials struct {
|
||||
// TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN string `json:"TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN"`
|
||||
// }
|
||||
// err = json.Unmarshal(credentialsRaw, &credentials)
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("unmarshalling credentials: %w", err)
|
||||
// }
|
||||
// return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil
|
||||
//}
|
||||
|
||||
func readTestServiceAccountJsonFromFile(path string) (string, error) {
|
||||
if path == "" {
|
||||
customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH")
|
||||
customPath, customPathSet := os.LookupEnv("STACKIT_SERVICE_ACCOUNT_PATH")
|
||||
if !customPathSet || customPath == "" {
|
||||
path = credentialsFilePath
|
||||
path = serviceAccountFilePath
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("getting home directory: %w", err)
|
||||
|
|
@ -557,15 +608,7 @@ func readTestTokenFromCredentialsFile(path string) (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("opening file: %w", err)
|
||||
}
|
||||
|
||||
var credentials struct {
|
||||
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN string `json:"TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN"`
|
||||
}
|
||||
err = json.Unmarshal(credentialsRaw, &credentials)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unmarshalling credentials: %w", err)
|
||||
}
|
||||
return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil
|
||||
return string(credentialsRaw), nil
|
||||
}
|
||||
|
||||
func getenv(key, defaultValue string) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue