Ft/rework acceptance tests follow up (#684)

* Enable CI

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Add default local file for IaaS image test

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Opensearch acceptance test typo

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Postgresflex acceptance test fix ignore

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Redis acceptance test remove mid uuid

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Objectstorage acceptance test ignore region for import

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Add more environment variables for CI build

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

---------

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
Alexander Dahmen 2025-02-20 13:36:31 +01:00 committed by GitHub
parent e2995347ec
commit a0c2c30ced
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 71 additions and 26 deletions

View file

@ -3,6 +3,8 @@ package iaas_test
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
@ -124,6 +126,9 @@ var imageResource = map[string]string{
"boot_menu": "true",
}
// if no local file is provided the test should create a default file and work with this instead of failing
var localFileForIaasImage os.File
func networkResourceConfig(name, nameservers string) string {
return fmt.Sprintf(`
resource "stackit_network" "network" {
@ -331,6 +336,14 @@ func serviceAccountAttachmentResourceConfig() string {
}
func imageResourceConfig(name string) string {
if imageResource["local_file_path"] == "default" {
localFileForIaasImage = testutil.CreateDefaultLocalFile()
filePath, err := filepath.Abs(localFileForIaasImage.Name())
if err != nil {
fmt.Println("Absolute path for localFileForIaasImage could not be retrieved.")
}
imageResource["local_file_path"] = filePath
}
return fmt.Sprintf(`
resource "stackit_image" "image" {
project_id = "%s"
@ -1866,6 +1879,15 @@ func testAccCheckIaaSImageDestroy(s *terraform.State) error {
ctx := context.Background()
var client *iaas.APIClient
var err error
if _, err := os.Stat(localFileForIaasImage.Name()); err == nil {
// file exists, delete it
err := os.Remove(localFileForIaasImage.Name())
if err != nil {
return fmt.Errorf("Error deleting localFileForIaasImage file: %w", err)
}
}
if testutil.IaaSCustomEndpoint == "" {
client, err = iaas.NewAPIClient(
config.WithRegion("eu01"),

View file

@ -192,8 +192,9 @@ func TestAccObjectStorageResource(t *testing.T) {
return fmt.Sprintf("%s,%s", testutil.ProjectId, credentialsGroupId), nil
},
ImportState: true,
ImportStateVerify: true,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
{
ResourceName: "stackit_objectstorage_credential.credential",
@ -214,7 +215,7 @@ func TestAccObjectStorageResource(t *testing.T) {
},
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"access_key", "secret_access_key"},
ImportStateVerifyIgnore: []string{"access_key", "secret_access_key", "region"},
},
// Deletion is done by the framework implicitly
},

View file

@ -102,7 +102,7 @@ func TestAccOpenSearchResource(t *testing.T) {
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "plan_name", instanceResource["plan_name"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "version", instanceResource["version"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "name", instanceResource["name"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.sgw_acl", instanceResource["sqw_acl-1"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl-1"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.max_disk_threshold", instanceResource["max_disk_threshold"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.enable_monitoring", instanceResource["enable_monitoring"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.syslog.#", "1"),
@ -153,7 +153,7 @@ func TestAccOpenSearchResource(t *testing.T) {
"data.stackit_opensearch_credential.credential", "credential_id"),
resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "plan_id", instanceResource["plan_id"]),
resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "name", instanceResource["name"]),
resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "parameters.sgw_acl", instanceResource["sqw_acl-1"]),
resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl-1"]),
resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "parameters.max_disk_threshold", instanceResource["max_disk_threshold"]),
resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "parameters.enable_monitoring", instanceResource["enable_monitoring"]),
resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "parameters.syslog.#", "1"),
@ -223,7 +223,7 @@ func TestAccOpenSearchResource(t *testing.T) {
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "plan_name", instanceResource["plan_name"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "version", instanceResource["version"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "name", instanceResource["name"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.sgw_acl", instanceResource["sqw_acl-2"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl-2"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.max_disk_threshold", instanceResource["max_disk_threshold"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.enable_monitoring", instanceResource["enable_monitoring"]),
resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "parameters.syslog.#", "1"),

View file

@ -239,8 +239,9 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
return fmt.Sprintf("%s,%s", testutil.ProjectId, instanceId), nil
},
ImportState: true,
ImportStateVerify: true,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"password"},
},
{
ResourceName: "stackit_postgresflex_user.user",
@ -262,7 +263,7 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
},
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"password"},
ImportStateVerifyIgnore: []string{"password", "uri"},
},
{
ResourceName: "stackit_postgresflex_database.database",

View file

@ -116,7 +116,6 @@ func TestAccRedisResource(t *testing.T) {
"metrics_frequency": "10",
"metrics_prefix": "prefix",
"min_replicas_max_lag": "15",
"monitoring_instance_id": "mid",
"notify_keyspace_events": "Ex",
"syslog": `["syslog.example.com:123"]`,
"tls_protocols": "TLSv1.2",
@ -146,7 +145,6 @@ func TestAccRedisResource(t *testing.T) {
resource.TestCheckResourceAttr("stackit_redis_instance.instance", "parameters.metrics_frequency", "10"),
resource.TestCheckResourceAttr("stackit_redis_instance.instance", "parameters.metrics_prefix", "prefix"),
resource.TestCheckResourceAttr("stackit_redis_instance.instance", "parameters.min_replicas_max_lag", "15"),
resource.TestCheckResourceAttr("stackit_redis_instance.instance", "parameters.monitoring_instance_id", "mid"),
resource.TestCheckResourceAttr("stackit_redis_instance.instance", "parameters.notify_keyspace_events", "Ex"),
resource.TestCheckResourceAttr("stackit_redis_instance.instance", "parameters.syslog.#", "1"),
resource.TestCheckResourceAttr("stackit_redis_instance.instance", "parameters.syslog.0", "syslog.example.com:123"),

View file

@ -48,7 +48,7 @@ var (
// Default email: acc-test@sa.stackit.cloud
TestProjectUserEmail = getenv("TF_ACC_TEST_PROJECT_USER_EMAIL", "acc-test@sa.stackit.cloud")
// TestImageLocalFilePath is the local path to an image file used for image acceptance tests
TestImageLocalFilePath = os.Getenv("TF_ACC_TEST_IMAGE_LOCAL_FILE_PATH")
TestImageLocalFilePath = getenv("TF_ACC_TEST_IMAGE_LOCAL_FILE_PATH", "default")
ArgusCustomEndpoint = os.Getenv("TF_ACC_ARGUS_CUSTOM_ENDPOINT")
DnsCustomEndpoint = os.Getenv("TF_ACC_DNS_CUSTOM_ENDPOINT")
@ -432,3 +432,25 @@ func getenv(key, defaultValue string) string {
}
return val
}
// helper for local_file_path
// no real data is created
func CreateDefaultLocalFile() os.File {
// Define the file name and size
fileName := "test-512k.img"
size := 512 * 1024 // 512 KB
// Create the file
file, err := os.Create(fileName)
if err != nil {
panic(err)
}
// Seek to the desired position (512 KB)
_, err = file.Seek(int64(size), 0)
if err != nil {
panic(err)
}
return *file
}