|
| 1 | +package sumologic |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "regexp" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 9 | +) |
| 10 | + |
| 11 | +func TestAccDataSourceFolder_basic(t *testing.T) { |
| 12 | + resource.Test(t, resource.TestCase{ |
| 13 | + PreCheck: func() { testAccPreCheck(t) }, |
| 14 | + Providers: testAccProviders, |
| 15 | + Steps: []resource.TestStep{ |
| 16 | + { |
| 17 | + Config: folderConfig( "/Library/Users/[email protected]"), |
| 18 | + Check: resource.ComposeTestCheckFunc( |
| 19 | + testAccDataSourceFolderCheck("data.sumologic_folder.personal_folder"), |
| 20 | + ), |
| 21 | + }, |
| 22 | + }, |
| 23 | + }) |
| 24 | +} |
| 25 | + |
| 26 | +func TestAccDataSourceFolder_folder_does_not_exist(t *testing.T) { |
| 27 | + resource.Test(t, resource.TestCase{ |
| 28 | + PreCheck: func() { testAccPreCheck(t) }, |
| 29 | + Providers: testAccProviders, |
| 30 | + Steps: []resource.TestStep{ |
| 31 | + { |
| 32 | + Config: folderConfig( "/Library/Users/[email protected]/doesNotExist"), |
| 33 | + ExpectError: regexp.MustCompile( |
| 34 | + "folder with path '/Library/Users/dgould\\[email protected]/doesNotExist' does not exist"), |
| 35 | + }, |
| 36 | + }, |
| 37 | + }) |
| 38 | +} |
| 39 | + |
| 40 | +func testAccDataSourceFolderCheck(name string) resource.TestCheckFunc { |
| 41 | + return resource.ComposeTestCheckFunc( |
| 42 | + resource.TestCheckResourceAttrSet(name, "id"), |
| 43 | + resource.TestCheckResourceAttrSet(name, "name"), |
| 44 | + ) |
| 45 | +} |
| 46 | + |
| 47 | +func folderConfig(path string) string { |
| 48 | + return fmt.Sprintf(` |
| 49 | + data "sumologic_folder" "personal_folder" { |
| 50 | + path = "%s" |
| 51 | + } |
| 52 | + `, path) |
| 53 | +} |
0 commit comments