-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHierarchyService_test.go
79 lines (70 loc) · 1.95 KB
/
HierarchyService_test.go
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
package tm1go_test
import (
"testing"
"github.com/andreyea/tm1go"
)
func TestHierarchyService_Create(t *testing.T) {
tests := []struct {
name string
hierarchy *tm1go.Hierarchy
wantErr bool
}{
{
name: "Create new hierarchy",
hierarchy: &tm1go.Hierarchy{
Name: "TestHierarchy",
Dimension: tm1go.Dimension{
Name: "TestDimension",
},
Elements: []tm1go.Element{
{Name: "Element1", Type: "Numeric"},
{Name: "Element2", Type: "Numeric"},
{Name: "Total", Type: "Consolidated"},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Setup: Create dimension if it doesn't exist
if tt.hierarchy.Dimension.Name != "Account" {
dim := &tm1go.Dimension{
Name: tt.hierarchy.Dimension.Name,
Hierarchies: []tm1go.Hierarchy{
{Name: tt.hierarchy.Dimension.Name},
},
}
err := tm1ServiceT.DimensionService.Create(dim)
if err != nil {
t.Fatalf("Failed to create test dimension: %v", err)
}
}
err := tm1ServiceT.HierarchyService.Create(tt.hierarchy)
if (err != nil) != tt.wantErr {
t.Errorf("HierarchyService.Create() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
// Verify the hierarchy was created
createdHierarchy, err := tm1ServiceT.HierarchyService.Get(tt.hierarchy.Dimension.Name, tt.hierarchy.Name)
if err != nil {
t.Errorf("Failed to get created hierarchy: %v", err)
return
}
if createdHierarchy == nil {
t.Errorf("Created hierarchy not found")
return
}
if createdHierarchy.Name != tt.hierarchy.Name {
t.Errorf("Created hierarchy name = %v, want %v", createdHierarchy.Name, tt.hierarchy.Name)
}
// Clean up: delete the created hierarchy
err = tm1ServiceT.HierarchyService.Delete(tt.hierarchy.Dimension.Name, tt.hierarchy.Name)
if err != nil {
t.Logf("Failed to delete test hierarchy: %v", err)
}
}
})
}
}