Skip to content

Commit 68a5044

Browse files
authored
Merge pull request #846 from sapcc/persist_display_name
persists liquid display names and categories
2 parents 55f2f12 + 7a3e0b7 commit 68a5044

24 files changed

+225
-116
lines changed

internal/api/api_test.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ func setupTest(t *testing.T) test.Setup {
110110
// NOTE: For new tests, please try to use a more minimal setup that focuses on the specific needs of the test.
111111
// This test setup is designed to be backwards-compatible with the old start-data.sql fixture.
112112

113-
srvInfoShared := test.DefaultLiquidServiceInfo()
113+
srvInfoShared := test.DefaultLiquidServiceInfo("Shared")
114114
srvInfoShared.Rates = map[liquid.RateName]liquid.RateInfo{
115115
"service/shared/objects:create": {Topology: liquid.FlatTopology, HasUsage: true},
116116
"service/shared/objects:delete": {Unit: liquid.UnitMebibytes, Topology: liquid.FlatTopology, HasUsage: true},
117117
"service/shared/objects:update": {Topology: liquid.FlatTopology, HasUsage: true},
118118
"service/shared/objects:unlimited": {Unit: liquid.UnitKibibytes, Topology: liquid.FlatTopology, HasUsage: true},
119119
}
120-
srvInfoUnshared := test.DefaultLiquidServiceInfo()
120+
srvInfoUnshared := test.DefaultLiquidServiceInfo("Unshared")
121121
srvInfoUnshared.Rates = map[liquid.RateName]liquid.RateInfo{
122122
"service/unshared/instances:create": {Topology: liquid.FlatTopology, HasUsage: true},
123123
"service/unshared/instances:delete": {Topology: liquid.FlatTopology, HasUsage: true},
@@ -329,8 +329,8 @@ func Test_ScrapeErrorOperations(t *testing.T) {
329329
"unshared": {"area": "unshared"}
330330
}
331331
}`),
332-
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo()),
333-
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo()),
332+
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo("Shared")),
333+
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo("Unshared")),
334334
test.WithInitialDiscovery,
335335
test.WithEmptyRecordsAsNeeded,
336336
)
@@ -917,7 +917,7 @@ func Test_EmptyProjectList(t *testing.T) {
917917
"first": {"area": "first"}
918918
}
919919
}`),
920-
test.WithPersistedServiceInfo("first", test.DefaultLiquidServiceInfo()),
920+
test.WithPersistedServiceInfo("first", test.DefaultLiquidServiceInfo("First")),
921921
test.WithInitialDiscovery,
922922
test.WithEmptyRecordsAsNeeded,
923923
)
@@ -973,8 +973,8 @@ func Test_LargeProjectList(t *testing.T) {
973973

974974
s := test.NewSetup(t,
975975
test.WithConfig(configStr),
976-
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo()),
977-
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo()),
976+
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo("Shared")),
977+
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo("Unshared")),
978978
test.WithInitialDiscovery,
979979
test.WithEmptyRecordsAsNeeded,
980980
)
@@ -1098,7 +1098,7 @@ func Test_PutMaxQuotaOnProject(t *testing.T) {
10981098
"shared": {"area": "shared"}
10991099
}
11001100
}`),
1101-
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo()),
1101+
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo("Shared")),
11021102
test.WithInitialDiscovery,
11031103
test.WithEmptyRecordsAsNeeded,
11041104
)
@@ -1230,8 +1230,8 @@ func Test_PutQuotaAutogrowth(t *testing.T) {
12301230
"unshared": {"area": "unshared"}
12311231
}
12321232
}`),
1233-
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo()),
1234-
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo()),
1233+
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo("Shared")),
1234+
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo("Unshared")),
12351235
test.WithInitialDiscovery,
12361236
test.WithEmptyRecordsAsNeeded,
12371237
)
@@ -1406,8 +1406,8 @@ func TestResourceRenaming(t *testing.T) {
14061406
}
14071407
}
14081408
}`),
1409-
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo()),
1410-
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo()),
1409+
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo("Shared")),
1410+
test.WithPersistedServiceInfo("unshared", test.DefaultLiquidServiceInfo("Unshared")),
14111411
test.WithInitialDiscovery,
14121412
test.WithEmptyRecordsAsNeeded,
14131413
)
@@ -1654,12 +1654,20 @@ const testAZSeparatedConfigJSON = `{
16541654

16551655
func Test_SeparatedTopologyOperations(t *testing.T) {
16561656
srvInfo := liquid.ServiceInfo{
1657-
Version: 1,
1657+
Version: 1,
1658+
DisplayName: "Shared",
1659+
Categories: map[liquid.CategoryName]liquid.CategoryInfo{
1660+
"foo_category": {
1661+
DisplayName: "Foo Category",
1662+
},
1663+
},
16581664
Resources: map[liquid.ResourceName]liquid.ResourceInfo{
16591665
"capacity_az_separated": {
1660-
Unit: liquid.UnitBytes,
1661-
Topology: liquid.AZSeparatedTopology,
1662-
HasQuota: true,
1666+
DisplayName: "Capacity AZ Separated",
1667+
Category: Some(liquid.CategoryName("foo_category")),
1668+
Unit: liquid.UnitBytes,
1669+
Topology: liquid.AZSeparatedTopology,
1670+
HasQuota: true,
16631671
},
16641672
},
16651673
}

internal/api/commitment_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,10 @@ const testConvertCommitmentsJSON = `{
204204
func setupCommitmentTest(t *testing.T, configJSON string) test.Setup {
205205
// setup ServiceInfo to mimic the old `fixtures/start-data-commitments.sql`
206206
// as closely as possible
207-
resInfoLikeCapacity := test.DefaultLiquidServiceInfo().Resources["capacity"]
207+
resInfoLikeCapacity := test.DefaultLiquidServiceInfo("").Resources["capacity"]
208208
resInfoLikeCapacity.HandlesCommitments = true
209-
resInfoLikeThings := test.DefaultLiquidServiceInfo().Resources["things"]
209+
resInfoLikeCapacity.Category = None[liquid.CategoryName]()
210+
resInfoLikeThings := test.DefaultLiquidServiceInfo("").Resources["things"]
210211
resInfoLikeThings.HandlesCommitments = true
211212
resInfoConvertible := liquid.ResourceInfo{
212213
Unit: liquid.UnitBytes,
@@ -215,23 +216,26 @@ func setupCommitmentTest(t *testing.T, configJSON string) test.Setup {
215216
}
216217

217218
srvInfoFirst := liquid.ServiceInfo{
218-
Version: 1,
219+
Version: 1,
220+
DisplayName: "First",
219221
Resources: map[liquid.ResourceName]liquid.ResourceInfo{
220222
"capacity": resInfoLikeCapacity,
221223
"things": resInfoLikeThings,
222224
"other": resInfoLikeCapacity,
223225
},
224226
}
225227
srvInfoSecond := liquid.ServiceInfo{
226-
Version: 1,
228+
Version: 1,
229+
DisplayName: "Second",
227230
Resources: map[liquid.ResourceName]liquid.ResourceInfo{
228231
"capacity": resInfoLikeCapacity,
229232
"things": resInfoLikeThings,
230233
"other": resInfoLikeCapacity,
231234
},
232235
}
233236
srvInfoThird := liquid.ServiceInfo{
234-
Version: 1,
237+
Version: 1,
238+
DisplayName: "Third",
235239
Resources: map[liquid.ResourceName]liquid.ResourceInfo{
236240
"capacity_c32": resInfoConvertible,
237241
"capacity_c48": resInfoConvertible,
@@ -241,7 +245,8 @@ func setupCommitmentTest(t *testing.T, configJSON string) test.Setup {
241245
},
242246
}
243247
srvInfoFourth := liquid.ServiceInfo{
244-
Version: 1,
248+
Version: 1,
249+
DisplayName: "Fourth",
245250
Resources: map[liquid.ResourceName]liquid.ResourceInfo{
246251
"capacity_a": resInfoLikeCapacity,
247252
"capacity_b": resInfoLikeCapacity,

internal/api/inconsistencies_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestInconsistencyReport(t *testing.T) {
3333
"shared": {"area": "shared"}
3434
}
3535
}`),
36-
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo()),
36+
test.WithPersistedServiceInfo("shared", test.DefaultLiquidServiceInfo("Shared")),
3737
test.WithInitialDiscovery,
3838
test.WithEmptyRecordsAsNeeded,
3939
)

internal/api/liquid_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func commonLiquidTestSetup(t *testing.T, srvInfo liquid.ServiceInfo) (s test.Set
4747
}
4848

4949
func TestGetServiceCapacityRequest(t *testing.T) {
50-
srvInfo := test.DefaultLiquidServiceInfo()
50+
srvInfo := test.DefaultLiquidServiceInfo("")
5151
resInfo := srvInfo.Resources["capacity"]
5252
resInfo.NeedsResourceDemand = true // must be set to test rendering of ServiceCapacityRequest.DemandForResource
5353
srvInfo.Resources["capacity"] = resInfo
@@ -114,7 +114,7 @@ func TestGetServiceCapacityRequest(t *testing.T) {
114114
}
115115

116116
func TestServiceUsageRequest(t *testing.T) {
117-
srvInfo := test.DefaultLiquidServiceInfo()
117+
srvInfo := test.DefaultLiquidServiceInfo("")
118118
srvInfo.UsageReportNeedsProjectMetadata = true
119119

120120
s := commonLiquidTestSetup(t, srvInfo)

internal/api/removed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestForbidClusterIDHeader(t *testing.T) {
18-
srvInfo := test.DefaultLiquidServiceInfo()
18+
srvInfo := test.DefaultLiquidServiceInfo("Foo")
1919
s := test.NewSetup(t,
2020
test.WithConfig(`{
2121
"availability_zones": ["az-one", "az-two"],

internal/api/translation_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestTranslateManilaSubcapacities(t *testing.T) {
7373
},
7474
}
7575

76-
testSubcapacityTranslation(t, "cinder-manila-capacity", subcapacitiesInLiquidFormat, subcapacitiesInLegacyFormat, test.DefaultLiquidServiceInfo())
76+
testSubcapacityTranslation(t, "cinder-manila-capacity", subcapacitiesInLiquidFormat, subcapacitiesInLegacyFormat, test.DefaultLiquidServiceInfo(""))
7777
}
7878

7979
func TestTranslateIronicSubcapacities(t *testing.T) {
@@ -84,7 +84,7 @@ func TestTranslateIronicSubcapacities(t *testing.T) {
8484
"disk_gib": 42,
8585
}
8686
buf := must.Return(json.Marshal(attrs))
87-
srvInfo := test.DefaultLiquidServiceInfo()
87+
srvInfo := test.DefaultLiquidServiceInfo("")
8888
resInfo := srvInfo.Resources["capacity"]
8989
resInfo.Attributes = json.RawMessage(buf)
9090
srvInfo.Resources["capacity"] = resInfo
@@ -181,7 +181,7 @@ func TestTranslateNovaSubcapacities(t *testing.T) {
181181
},
182182
}
183183

184-
testSubcapacityTranslation(t, "nova-flavors", subcapacitiesInLiquidFormat, subcapacitiesInLegacyFormat, test.DefaultLiquidServiceInfo())
184+
testSubcapacityTranslation(t, "nova-flavors", subcapacitiesInLiquidFormat, subcapacitiesInLegacyFormat, test.DefaultLiquidServiceInfo(""))
185185
}
186186

187187
func testSubcapacityTranslation(t *testing.T, ruleID string, subcapacitiesInLiquidFormat, subcapacitiesInLegacyFormat []assert.JSONObject, srvInfo liquid.ServiceInfo) {
@@ -277,7 +277,7 @@ func TestTranslateCinderVolumeSubresources(t *testing.T) {
277277
},
278278
}
279279

280-
testSubresourceTranslation(t, "cinder-volumes", subresourcesInLiquidFormat, subresourcesInLegacyFormat, test.DefaultLiquidServiceInfo())
280+
testSubresourceTranslation(t, "cinder-volumes", subresourcesInLiquidFormat, subresourcesInLegacyFormat, test.DefaultLiquidServiceInfo(""))
281281
}
282282

283283
func TestTranslateCinderSnapshotSubresources(t *testing.T) {
@@ -303,7 +303,7 @@ func TestTranslateCinderSnapshotSubresources(t *testing.T) {
303303
},
304304
}
305305

306-
testSubresourceTranslation(t, "cinder-snapshots", subresourcesInLiquidFormat, subresourcesInLegacyFormat, test.DefaultLiquidServiceInfo())
306+
testSubresourceTranslation(t, "cinder-snapshots", subresourcesInLiquidFormat, subresourcesInLegacyFormat, test.DefaultLiquidServiceInfo(""))
307307
}
308308

309309
func TestTranslateIronicSubresources(t *testing.T) {
@@ -314,7 +314,7 @@ func TestTranslateIronicSubresources(t *testing.T) {
314314
"disk_gib": 42,
315315
}
316316
buf := must.Return(json.Marshal(attrs))
317-
srvInfo := test.DefaultLiquidServiceInfo()
317+
srvInfo := test.DefaultLiquidServiceInfo("")
318318
resInfo := srvInfo.Resources["capacity"]
319319
resInfo.Attributes = buf
320320
srvInfo.Resources["capacity"] = resInfo
@@ -471,7 +471,7 @@ func TestTranslateNovaSubresources(t *testing.T) {
471471
},
472472
}
473473

474-
testSubresourceTranslation(t, "nova-flavors", subresourcesInLiquidFormat, subresourcesInLegacyFormat, test.DefaultLiquidServiceInfo())
474+
testSubresourceTranslation(t, "nova-flavors", subresourcesInLiquidFormat, subresourcesInLegacyFormat, test.DefaultLiquidServiceInfo(""))
475475
}
476476

477477
func testSubresourceTranslation(t *testing.T, ruleID string, subresourcesInLiquidFormat, subresourcesInLegacyFormat []assert.JSONObject, srvInfo liquid.ServiceInfo) {

0 commit comments

Comments
 (0)