forked from DavidKrau/terraform-provider-simplemdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_resource_model_test.go
More file actions
102 lines (94 loc) · 3.42 KB
/
app_resource_model_test.go
File metadata and controls
102 lines (94 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
95
96
97
98
99
100
101
102
package provider
import (
"context"
"testing"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func TestNewAppResourceModelFromAPI_AllFields(t *testing.T) {
ctx := context.Background()
response := &appAPIResponse{}
response.Data.ID = 42
response.Data.Attributes.Name = "Marketing App"
response.Data.Attributes.BundleIdentifier = "com.example.marketing"
response.Data.Attributes.ITunesStoreID = 123456789
response.Data.Attributes.AppType = "app store"
response.Data.Attributes.InstallationChannels = []string{"assignment_groups"}
response.Data.Attributes.PlatformSupport = "ios"
response.Data.Attributes.ProcessingStatus = "ready"
response.Data.Attributes.Version = "7.1"
response.Data.Attributes.CreatedAt = "2025-01-02T03:04:05Z"
response.Data.Attributes.UpdatedAt = "2025-02-03T04:05:06Z"
model, diags := newAppResourceModelFromAPI(ctx, response)
if diags.HasError() {
t.Fatalf("unexpected diagnostics: %v", diags)
}
if model.ID.IsNull() || model.ID.ValueString() != "42" {
t.Fatalf("expected ID to be set, got %v", model.ID)
}
if model.Name.ValueString() != "Marketing App" {
t.Fatalf("expected Name to be set")
}
if model.AppStoreId.ValueString() != "123456789" {
t.Fatalf("expected AppStoreId to be set")
}
if model.BundleId.ValueString() != "com.example.marketing" {
t.Fatalf("expected BundleId to be set")
}
// DeployTo and Status are write-only fields not returned by API
// They should have their default/null values
if model.DeployTo.ValueString() != "none" {
t.Fatalf("expected DeployTo to have default value 'none', got %q", model.DeployTo.ValueString())
}
if !model.Status.IsNull() {
t.Fatalf("expected Status to be null (not returned by API), got %q", model.Status.ValueString())
}
if model.AppType.ValueString() != "app store" {
t.Fatalf("expected AppType to be set")
}
if model.Version.ValueString() != "7.1" {
t.Fatalf("expected Version to be set")
}
if model.PlatformSupport.ValueString() != "ios" {
t.Fatalf("expected PlatformSupport to be set")
}
if model.ProcessingStatus.ValueString() != "ready" {
t.Fatalf("expected ProcessingStatus to be set")
}
if model.CreatedAt.ValueString() != "2025-01-02T03:04:05Z" {
t.Fatalf("expected CreatedAt to be set")
}
if model.UpdatedAt.ValueString() != "2025-02-03T04:05:06Z" {
t.Fatalf("expected UpdatedAt to be set")
}
if model.InstallationChannels.IsNull() {
t.Fatalf("expected InstallationChannels to be set")
}
values := model.InstallationChannels.Elements()
if len(values) != 1 || values[0].(types.String).ValueString() != "assignment_groups" {
t.Fatalf("unexpected installation channels: %v", values)
}
}
func TestNewAppResourceModelFromAPI_PartialData(t *testing.T) {
ctx := context.Background()
response := &appAPIResponse{}
response.Data.ID = 99
model, diags := newAppResourceModelFromAPI(ctx, response)
if diags.HasError() {
t.Fatalf("unexpected diagnostics: %v", diags)
}
if !model.Name.IsNull() {
t.Fatalf("expected Name to remain null when not provided")
}
if !model.AppStoreId.IsNull() {
t.Fatalf("expected AppStoreId to remain null when not provided")
}
if !model.BundleId.IsNull() {
t.Fatalf("expected BundleId to remain null when not provided")
}
if model.DeployTo.ValueString() != "none" {
t.Fatalf("expected DeployTo to default to none, got %q", model.DeployTo.ValueString())
}
if !model.InstallationChannels.IsNull() {
t.Fatalf("expected InstallationChannels to remain null when not provided")
}
}