Skip to content

Commit

Permalink
test(workspace): using obs resource to upload app file (#6107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lance52259 authored Dec 26, 2024
1 parent 53ad2ae commit 6f17a55
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
8 changes: 4 additions & 4 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ var (
HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_PRODUCT_ID = os.Getenv("HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_PRODUCT_ID")
HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_SPEC_CODE = os.Getenv("HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_SPEC_CODE")
HW_WORKSPACE_OU_NAME = os.Getenv("HW_WORKSPACE_OU_NAME")
HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH = os.Getenv("HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH")
HW_WORKSPACE_APP_FILE_NAME = os.Getenv("HW_WORKSPACE_APP_FILE_NAME")
HW_WORKSPACE_USER_NAMES = os.Getenv("HW_WORKSPACE_USER_NAMES")

HW_FGS_AGENCY_NAME = os.Getenv("HW_FGS_AGENCY_NAME")
Expand Down Expand Up @@ -1581,9 +1581,9 @@ func TestAccPreCheckWorkspaceOUName(t *testing.T) {
}

// lintignore:AT003
func TestAccPreCheckWorkspaceFileStorePath(t *testing.T) {
if HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH == "" {
t.Skip("HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH must be set for Workspace service acceptance tests.")
func TestAccPreCheckWorkspaceAppFileName(t *testing.T) {
if HW_WORKSPACE_APP_FILE_NAME == "" {
t.Skip("HW_WORKSPACE_APP_FILE_NAME must be set for Workspace service acceptance tests.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ func TestAccAppWarehouseApp_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceFileStorePath(t)
acceptance.TestAccPreCheckWorkspaceAppFileName(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
ExternalProviders: map[string]resource.ExternalProvider{
"null": {
Source: "hashicorp/null",
VersionConstraint: "3.2.1",
},
},
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccWarehouseApp_basic_step1(name),
Expand All @@ -50,7 +56,7 @@ func TestAccAppWarehouseApp_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "os_type", "Windows"),
resource.TestCheckResourceAttr(resourceName, "version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "version_name", "terraform"),
resource.TestCheckResourceAttr(resourceName, "file_store_path", acceptance.HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH),
resource.TestCheckResourceAttr(resourceName, "file_store_path", acceptance.HW_WORKSPACE_APP_FILE_NAME),
resource.TestCheckResourceAttr(resourceName, "description", "Created by script"),
),
},
Expand Down Expand Up @@ -78,30 +84,77 @@ func TestAccAppWarehouseApp_basic(t *testing.T) {
})
}

func executionFileUploadResourcesConfig() string {
return fmt.Sprintf(`
variable "script_content" {
type = string
default = <<EOT
def main():
print("Hello, World!")
if __name__ == "__main__":
main()
EOT
}
data "huaweicloud_identity_projects" "test" {
name = "%[1]s"
}
data "huaweicloud_obs_buckets" "test" {
bucket = format("wks-app-%%s", data.huaweicloud_identity_projects.test.projects[0].id)
}
resource "null_resource" "test" {
depends_on = [data.huaweicloud_obs_buckets.test]
provisioner "local-exec" {
command = "echo '${var.script_content}' >> %[2]s"
}
provisioner "local-exec" {
command = "rm %[2]s"
when = destroy
}
}
resource "huaweicloud_obs_bucket_object" "test" {
depends_on = [null_resource.test]
bucket = data.huaweicloud_obs_buckets.test.buckets[0].bucket
key = "%[2]s"
source = abspath("%[2]s")
content_type = "application/x-msdownload"
}`, acceptance.HW_REGION_NAME, acceptance.HW_WORKSPACE_APP_FILE_NAME)
}

func testAccWarehouseApp_basic_step1(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_workspace_app_warehouse_app" "test" {
name = "%[1]s"
name = "%[2]s"
category = "OTHER"
os_type = "Windows"
version = "1.0"
version_name = "terraform"
file_store_path = "%[2]s"
file_store_path = "%[3]s"
description = "Created by script"
}
`, name, acceptance.HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH)
`, executionFileUploadResourcesConfig(), name, acceptance.HW_WORKSPACE_APP_FILE_NAME)
}

func testAccWarehouseApp_basic_step2(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_workspace_app_warehouse_app" "test" {
name = "%[1]s"
name = "%[2]s"
category = "PRODUCTIVITY_AND_COLLABORATION"
os_type = "Linux"
version = "2.0"
version_name = "terraform_update"
file_store_path = "%[2]s"
file_store_path = "%[3]s"
description = "Updated by script"
}
`, name, acceptance.HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH)
`, executionFileUploadResourcesConfig(), name, acceptance.HW_WORKSPACE_APP_FILE_NAME)
}

0 comments on commit 6f17a55

Please sign in to comment.