-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdatasource_test.go
More file actions
75 lines (72 loc) · 1.68 KB
/
datasource_test.go
File metadata and controls
75 lines (72 loc) · 1.68 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
package enable
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
)
func TestDataMapFields(t *testing.T) {
const testRegion = "eu01"
id := fmt.Sprintf("%s,%s,%s", "pid", "sid", testRegion)
tests := []struct {
description string
input *serverupdate.GetUpdateServiceResponse
expected DataModel
isValid bool
}{
{
"default_values",
&serverupdate.GetUpdateServiceResponse{},
DataModel{
Id: types.StringValue(id),
ProjectId: types.StringValue("pid"),
ServerId: types.StringValue("sid"),
Region: types.StringValue("eu01"),
},
true,
},
{
"simple_values",
&serverupdate.GetUpdateServiceResponse{
Enabled: utils.Ptr(true),
},
DataModel{
Id: types.StringValue(id),
ProjectId: types.StringValue("pid"),
ServerId: types.StringValue("sid"),
Region: types.StringValue("eu01"),
Enabled: types.BoolValue(true),
},
true,
},
{
"nil_response",
nil,
DataModel{},
false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
model := &DataModel{
ProjectId: tt.expected.ProjectId,
ServerId: tt.expected.ServerId,
}
err := mapDataFields(tt.input, model, "eu01")
if !tt.isValid && err == nil {
t.Fatalf("Should have failed")
}
if tt.isValid && err != nil {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(model, &tt.expected)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
}
})
}
}