forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathproject_property_test.go
More file actions
155 lines (132 loc) · 4.43 KB
/
Copy pathproject_property_test.go
File metadata and controls
155 lines (132 loc) · 4.43 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package dtrack
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestProjectPropertyService_GetAll(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionPortfolioManagement,
},
})
project, err := client.Project.Create(context.Background(), Project{
Name: "acme-app",
Version: "1.0.0",
})
require.NoError(t, err)
po := PageOptions{PageSize: 10}
// Baseline: no properties yet
properties, err := client.ProjectProperty.GetAll(context.Background(), project.UUID, po)
require.NoError(t, err)
// The api does not return TotalCount as it seems not to be paginated (although we can supply page options)
//require.Equal(t, 0, properties.TotalCount)
require.Empty(t, properties.Items)
// Create a property
_, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{
Group: "test-group",
Name: "test-property",
Value: "test-value",
Type: "STRING",
})
require.NoError(t, err)
// Verify it appears in GetAll
properties, err = client.ProjectProperty.GetAll(context.Background(), project.UUID, po)
require.NoError(t, err)
// The api does not return TotalCount as it seems not to be paginated (although we can supply page options)
//require.Equal(t, 1, properties.TotalCount)
require.Len(t, properties.Items, 1)
require.Equal(t, "test-group", properties.Items[0].Group)
require.Equal(t, "test-property", properties.Items[0].Name)
require.Equal(t, "test-value", properties.Items[0].Value)
require.Equal(t, "STRING", properties.Items[0].Type)
}
func TestProjectPropertyService_Create(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionPortfolioManagement,
},
})
project, err := client.Project.Create(context.Background(), Project{
Name: "acme-app",
Version: "1.0.0",
})
require.NoError(t, err)
property, err := client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{
Group: "test-group",
Name: "test-property",
Value: "test-value",
Type: "STRING",
Description: "a test property",
})
require.NoError(t, err)
require.Equal(t, "test-group", property.Group)
require.Equal(t, "test-property", property.Name)
require.Equal(t, "test-value", property.Value)
require.Equal(t, "STRING", property.Type)
require.Equal(t, "a test property", property.Description)
}
func TestProjectPropertyService_Update(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionPortfolioManagement,
},
})
project, err := client.Project.Create(context.Background(), Project{
Name: "acme-app",
Version: "1.0.0",
})
require.NoError(t, err)
// Create a property first
_, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{
Group: "test-group",
Name: "test-property",
Value: "original-value",
Type: "STRING",
})
require.NoError(t, err)
// Update the property
updated, err := client.ProjectProperty.Update(context.Background(), project.UUID, ProjectProperty{
Group: "test-group",
Name: "test-property",
Value: "updated-value",
Type: "STRING",
})
require.NoError(t, err)
require.Equal(t, "test-group", updated.Group)
require.Equal(t, "test-property", updated.Name)
require.Equal(t, "updated-value", updated.Value)
require.Equal(t, "STRING", updated.Type)
}
func TestProjectPropertyService_Delete(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionPortfolioManagement,
},
})
po := PageOptions{PageSize: 10}
project, err := client.Project.Create(context.Background(), Project{
Name: "acme-app",
Version: "1.0.0",
})
require.NoError(t, err)
// Create a property
_, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{
Group: "test-group",
Name: "test-property",
Value: "test-value",
Type: "STRING",
})
require.NoError(t, err)
// Verify presence
properties, err := client.ProjectProperty.GetAll(context.Background(), project.UUID, po)
require.NoError(t, err)
require.Len(t, properties.Items, 1)
// Delete the property
err = client.ProjectProperty.Delete(context.Background(), project.UUID, "test-group", "test-property")
require.NoError(t, err)
// Verify absence
properties, err = client.ProjectProperty.GetAll(context.Background(), project.UUID, po)
require.NoError(t, err)
require.Len(t, properties.Items, 0)
}