forked from DavidKrau/terraform-provider-simplemdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagedConfig_resource_test.go
More file actions
94 lines (82 loc) · 3.42 KB
/
managedConfig_resource_test.go
File metadata and controls
94 lines (82 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package provider
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)
func testAccCheckManagedConfigDestroy(s *terraform.State) error {
client, err := getTestClient()
if err != nil {
return fmt.Errorf("failed to create test client: %w", err)
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "simplemdm_managed_config" {
continue
}
appID, configID, err := parseManagedConfigID(rs.Primary.ID)
if err != nil {
return fmt.Errorf("failed to parse managed config ID %s: %w", rs.Primary.ID, err)
}
_, err = fetchManagedConfig(context.Background(), client, appID, configID)
if err == nil {
return fmt.Errorf("managed config %s still exists after destroy", rs.Primary.ID)
}
if err != errManagedConfigNotFound && !isNotFoundError(err) {
return fmt.Errorf("unexpected error checking managed config %s: %w", rs.Primary.ID, err)
}
}
return nil
}
func TestAccManagedConfigResource_basic(t *testing.T) {
testAccPreCheck(t)
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
CheckDestroy: testAccCheckManagedConfigDestroy,
Steps: []resource.TestStep{
{
Config: providerConfig + `
resource "simplemdm_app" "testapp" {
app_store_id = "586447913"
}
resource "simplemdm_managed_config" "config" {
app_id = simplemdm_app.testapp.id
key = "serverURL"
value = "https://example.com"
value_type = "string"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("simplemdm_managed_config.config", "key", "serverURL"),
resource.TestCheckResourceAttr("simplemdm_managed_config.config", "value", "https://example.com"),
resource.TestCheckResourceAttr("simplemdm_managed_config.config", "value_type", "string"),
resource.TestCheckResourceAttrSet("simplemdm_managed_config.config", "id"),
resource.TestCheckResourceAttrPair("simplemdm_managed_config.config", "app_id", "simplemdm_app.testapp", "id"),
),
},
{
ResourceName: "simplemdm_managed_config.config",
ImportState: true,
ImportStateVerify: true,
},
{
Config: providerConfig + `
resource "simplemdm_app" "testapp" {
app_store_id = "586447913"
}
resource "simplemdm_managed_config" "config" {
app_id = simplemdm_app.testapp.id
key = "serverURL"
value = "https://terraform.example.com"
value_type = "string"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("simplemdm_managed_config.config", "value", "https://terraform.example.com"),
resource.TestCheckResourceAttrSet("simplemdm_managed_config.config", "id"),
),
},
},
})
}