Skip to content

Commit

Permalink
azurerm_storage_share_file: test coverage for files in directories
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Mar 26, 2024
1 parent 16ea673 commit adef9c7
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 4 deletions.
35 changes: 35 additions & 0 deletions internal/services/storage/storage_share_directory_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ func TestAccStorageShareDirectory_nested(t *testing.T) {
})
}

func TestAccStorageShareDirectory_nestedWithBackslashes(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "dos")
r := StorageShareDirectoryResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.nestedWithBackslashes(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That("azurerm_storage_share_directory.c").ExistsInAzure(r),
check.That("azurerm_storage_share_directory.dos").ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r StorageShareDirectoryResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := directories.ParseDirectoryID(state.ID, client.Storage.StorageDomainSuffix)
if err != nil {
Expand Down Expand Up @@ -348,6 +365,24 @@ resource "azurerm_storage_share_directory" "multiple_child_one" {
`, template)
}

func (r StorageShareDirectoryResource) nestedWithBackslashes(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_storage_share_directory" "c" {
name = "c"
storage_share_id = azurerm_storage_share.test.id
}
resource "azurerm_storage_share_directory" "dos" {
name = "c\\dos"
storage_share_id = azurerm_storage_share.test.id
depends_on = [azurerm_storage_share_directory.c]
}
`, template)
}

func (r StorageShareDirectoryResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
95 changes: 91 additions & 4 deletions internal/services/storage/storage_share_file_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,51 @@ func TestAccAzureRMStorageShareFile_withEmptyFile(t *testing.T) {
})
}

func TestAccAzureRMStorageShareFile_withPath(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_share_file", "test")
r := StorageShareFileResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withPath(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccAzureRMStorageShareFile_withPathUsingBackslashes(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_share_file", "test")
r := StorageShareFileResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withPathUsingBackslashes(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccAzureRMStorageShareFile_withPathInNameUsingBackslashes(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_share_file", "test")
r := StorageShareFileResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withPathInNameUsingBackslashes(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (StorageShareFileResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := files.ParseFileID(state.ID, clients.Storage.StorageDomainSuffix)
if err != nil {
Expand Down Expand Up @@ -213,7 +258,7 @@ func (r StorageShareFileResource) basic(data acceptance.TestData) string {
%s
resource "azurerm_storage_share_file" "test" {
name = "dir"
name = "file"
storage_share_id = azurerm_storage_share.test.id
metadata = {
Expand Down Expand Up @@ -250,7 +295,7 @@ resource "azurerm_storage_share" "test" {
}
resource "azurerm_storage_share_file" "test" {
name = "dir"
name = "file"
storage_share_id = azurerm_storage_share.test.id
metadata = {
Expand Down Expand Up @@ -280,7 +325,7 @@ func (r StorageShareFileResource) complete(data acceptance.TestData) string {
%s
resource "azurerm_storage_share_file" "test" {
name = "dir"
name = "test"
storage_share_id = azurerm_storage_share.test.id
Expand All @@ -301,7 +346,7 @@ func (r StorageShareFileResource) withFile(data acceptance.TestData, fileName st
%s
resource "azurerm_storage_share_file" "test" {
name = "dir"
name = "test"
storage_share_id = azurerm_storage_share.test.id
source = "%s"
Expand All @@ -312,3 +357,45 @@ resource "azurerm_storage_share_file" "test" {
}
`, r.template(data), fileName)
}

func (r StorageShareFileResource) withPath(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_storage_share_directory" "parent" {
name = "parent"
storage_share_id = azurerm_storage_share.test.id
}
resource "azurerm_storage_share_file" "test" {
name = "test"
path = azurerm_storage_share_directory.parent.name
storage_share_id = azurerm_storage_share.test.id
}
`, r.template(data))
}

func (r StorageShareFileResource) withPathUsingBackslashes(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_storage_share_file" "test" {
name = "command.com"
path = "c\\dos"
storage_share_id = azurerm_storage_share.test.id
depends_on = [azurerm_storage_share_directory.dos]
}
`, StorageShareDirectoryResource{}.nestedWithBackslashes(data))
}

func (r StorageShareFileResource) withPathInNameUsingBackslashes(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_storage_share_file" "test" {
name = "c\\dos\\command.com"
storage_share_id = azurerm_storage_share.test.id
depends_on = [azurerm_storage_share_directory.dos]
}
`, StorageShareDirectoryResource{}.nestedWithBackslashes(data))
}

0 comments on commit adef9c7

Please sign in to comment.