|
| 1 | +package file_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 9 | + fileSDK "github.com/scaleway/scaleway-sdk-go/api/file/v1alpha1" |
| 10 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest" |
| 11 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/file" |
| 12 | + filetestfuncs "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/file/testfuncs" |
| 13 | +) |
| 14 | + |
| 15 | +func TestAccFileSystem_Basic(t *testing.T) { |
| 16 | + tt := acctest.NewTestTools(t) |
| 17 | + defer tt.Cleanup() |
| 18 | + |
| 19 | + fileSystemName := "TestAccFileSystem_Basic" |
| 20 | + fileSystemNameUpdated := "TestAccFileSystem_BasicUpdate" |
| 21 | + |
| 22 | + resource.ParallelTest(t, resource.TestCase{ |
| 23 | + PreCheck: func() { acctest.PreCheck(t) }, |
| 24 | + ProviderFactories: tt.ProviderFactories, |
| 25 | + CheckDestroy: filetestfuncs.CheckFileDestroy(tt), |
| 26 | + Steps: []resource.TestStep{ |
| 27 | + { |
| 28 | + Config: fmt.Sprintf(` |
| 29 | + resource "scaleway_file_filesysten" "fs" { |
| 30 | + name = "%s" |
| 31 | + size = 10000000000 |
| 32 | + } |
| 33 | +
|
| 34 | + |
| 35 | + `, fileSystemName), |
| 36 | + Check: resource.ComposeTestCheckFunc( |
| 37 | + testAccCheckFileSystemExists(tt, "scaleway_file_filesystem.fs"), |
| 38 | + resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "name", fileSystemName), |
| 39 | + resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "size", "10000000000"), |
| 40 | + ), |
| 41 | + }, |
| 42 | + { |
| 43 | + Config: fmt.Sprintf(` |
| 44 | + resource "scaleway_file_filesysten" "fs" { |
| 45 | + name = "%s" |
| 46 | + size = 10000000000 |
| 47 | + } |
| 48 | +
|
| 49 | + |
| 50 | + `, fileSystemNameUpdated), |
| 51 | + Check: resource.ComposeTestCheckFunc( |
| 52 | + testAccCheckFileSystemExists(tt, "scaleway_file_filesystem.fs"), |
| 53 | + resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "size", "10000000000"), |
| 54 | + ), |
| 55 | + }, |
| 56 | + }, |
| 57 | + }) |
| 58 | +} |
| 59 | + |
| 60 | +func testAccCheckFileSystemExists(tt *acctest.TestTools, n string) resource.TestCheckFunc { |
| 61 | + return func(s *terraform.State) error { |
| 62 | + rs, ok := s.RootModule().Resources[n] |
| 63 | + if !ok { |
| 64 | + return fmt.Errorf("resource not found: %s", n) |
| 65 | + } |
| 66 | + |
| 67 | + fileAPI, region, id, err := file.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID) |
| 68 | + if err != nil { |
| 69 | + return err |
| 70 | + } |
| 71 | + |
| 72 | + _, err = fileAPI.GetFileSystem(&fileSDK.GetFileSystemRequest{ |
| 73 | + Region: region, |
| 74 | + FilesystemID: id, |
| 75 | + }) |
| 76 | + if err != nil { |
| 77 | + return err |
| 78 | + } |
| 79 | + |
| 80 | + return nil |
| 81 | + } |
| 82 | +} |
0 commit comments