Skip to content

Commit f8bd1e1

Browse files
Changing the order of output for state.
WIP: Changing the order of output for state.
1 parent 51a745d commit f8bd1e1

2 files changed

Lines changed: 51 additions & 54 deletions

File tree

api/expiring_license_service.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (a Api) ListExpiringLicenses(expiresWithin string, staged bool, deployed bo
5454
expiredLicense = append(expiredLicense, ExpiringLicenseOutput{
5555
ProductName: expiredProduct.Type,
5656
GUID: expiredProduct.GUID,
57-
ProductState: []string{expiredProduct.ProductState, "requires license"},
57+
ProductState: []string{expiredProduct.ProductState},
5858
ProductVersion: expiredProduct.ProductVersion,
5959
})
6060
}
@@ -92,9 +92,13 @@ func (a Api) getProductsLicenseInfo(staged bool, deployed bool) ([]licenseInfoPr
9292

9393
noModifiersSelected := !staged && !deployed
9494

95-
// deployed products should come first and then staged. this order is important for removing the duplicates.
96-
// This keeps the deployed and deletes staged from the list if the product is both staged and deployed
97-
// The append function in Go adds elements to the end of a slice, maintaining the order in which they are appended.
95+
if staged || noModifiersSelected {
96+
stagedProducts, err := a.getStagedProducts()
97+
if err != nil {
98+
return nil, fmt.Errorf("could not get staged products: %w", err)
99+
}
100+
allProducts = append(allProducts, stagedProducts...)
101+
}
98102

99103
if deployed || noModifiersSelected {
100104
deployedProducts, err := a.getDeployedProducts()
@@ -104,14 +108,6 @@ func (a Api) getProductsLicenseInfo(staged bool, deployed bool) ([]licenseInfoPr
104108
allProducts = append(allProducts, deployedProducts...)
105109
}
106110

107-
if staged || noModifiersSelected {
108-
stagedProducts, err := a.getStagedProducts()
109-
if err != nil {
110-
return nil, fmt.Errorf("could not get staged products: %w", err)
111-
}
112-
allProducts = append(allProducts, stagedProducts...)
113-
}
114-
115111
return allProducts, nil
116112
}
117113

api/expiring_license_service_test.go

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,15 @@ var _ = Describe("ExpiringLicenseService", func() {
173173

174174
client.AppendHandlers(
175175
ghttp.CombineHandlers(
176-
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
177-
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(deployedGUID, deployedExpiryDate, deployedLabel)),
176+
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
177+
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(stagedGUID, stagedExpiryDate, stagedLabel)),
178178
),
179179
)
180+
180181
client.AppendHandlers(
181182
ghttp.CombineHandlers(
182-
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
183-
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(stagedGUID, stagedExpiryDate, stagedLabel)),
183+
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
184+
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(deployedGUID, deployedExpiryDate, deployedLabel)),
184185
),
185186
)
186187

@@ -201,14 +202,15 @@ var _ = Describe("ExpiringLicenseService", func() {
201202

202203
client.AppendHandlers(
203204
ghttp.CombineHandlers(
204-
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
205-
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(deployedGUID, deployedExpiryDate, deployedLabel)),
205+
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
206+
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(stagedGUID, stagedExpiryDate, stagedLabel)),
206207
),
207208
)
209+
208210
client.AppendHandlers(
209211
ghttp.CombineHandlers(
210-
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
211-
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(stagedGUID, stagedExpiryDate, stagedLabel)),
212+
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
213+
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(deployedGUID, deployedExpiryDate, deployedLabel)),
212214
),
213215
)
214216

@@ -366,6 +368,30 @@ var _ = Describe("ExpiringLicenseService", func() {
366368
})
367369

368370
Describe("edge cases", func() {
371+
It("correctly handles products with no license metadata", func() {
372+
client.AppendHandlers(
373+
ghttp.CombineHandlers(
374+
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
375+
ghttp.RespondWith(http.StatusOK, `[
376+
{
377+
"installation_name": "cf-no-license",
378+
"guid": "cf-no-license",
379+
"type": "cf",
380+
"product_version": "1.0-build.0",
381+
"label": "Product without license",
382+
"service_broker": false,
383+
"bosh_read_creds": false,
384+
"license_metadata": []
385+
}
386+
]`),
387+
),
388+
)
389+
390+
licenses, err := service.ListExpiringLicenses("30d", true, false)
391+
Expect(err).NotTo(HaveOccurred())
392+
Expect(licenses).To(HaveLen(0))
393+
})
394+
369395
It("correctly handles products with multiple licenses (some expiring, some not)", func() {
370396
expiringDate := formatDate(daysFromNow(20))
371397
futureDate := formatDate(daysFromNow(60))
@@ -406,30 +432,6 @@ var _ = Describe("ExpiringLicenseService", func() {
406432
expectSingleLicense(licenses, "cf-multiple-licenses", expiringDate, "staged")
407433
})
408434

409-
It("correctly handles products with no license metadata", func() {
410-
client.AppendHandlers(
411-
ghttp.CombineHandlers(
412-
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
413-
ghttp.RespondWith(http.StatusOK, `[
414-
{
415-
"installation_name": "cf-no-license",
416-
"guid": "cf-no-license",
417-
"type": "cf",
418-
"product_version": "1.0-build.0",
419-
"label": "Product without license",
420-
"service_broker": false,
421-
"bosh_read_creds": false,
422-
"license_metadata": []
423-
}
424-
]`),
425-
),
426-
)
427-
428-
licenses, err := service.ListExpiringLicenses("30d", true, false)
429-
Expect(err).NotTo(HaveOccurred())
430-
Expect(licenses).To(HaveLen(0))
431-
})
432-
433435
It("correctly handles licenses that have already expired", func() {
434436
expiredDate := formatDate(daysFromNow(-5))
435437
guid := "cf-expired-test"
@@ -471,15 +473,14 @@ var _ = Describe("ExpiringLicenseService", func() {
471473

472474
client.AppendHandlers(
473475
ghttp.CombineHandlers(
474-
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
475-
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(guid, deployedExpiryDate, label)),
476+
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
477+
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(guid, stagedExpiryDate, label)),
476478
),
477479
)
478-
479480
client.AppendHandlers(
480481
ghttp.CombineHandlers(
481-
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
482-
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(guid, stagedExpiryDate, label)),
482+
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
483+
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(guid, deployedExpiryDate, label)),
483484
),
484485
)
485486

@@ -517,15 +518,15 @@ var _ = Describe("ExpiringLicenseService", func() {
517518

518519
client.AppendHandlers(
519520
ghttp.CombineHandlers(
520-
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
521-
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(guid, expiryDate, label)),
521+
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
522+
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(guid, expiryDate, label)),
522523
),
523524
)
524525

525526
client.AppendHandlers(
526527
ghttp.CombineHandlers(
527-
ghttp.VerifyRequest("GET", "/api/v0/staged/products"),
528-
ghttp.RespondWith(http.StatusOK, createStagedProductResponse(guid, expiryDate, label)),
528+
ghttp.VerifyRequest("GET", "/api/v0/deployed/products"),
529+
ghttp.RespondWith(http.StatusOK, createDeployedProductResponse(guid, expiryDate, label)),
529530
),
530531
)
531532

@@ -536,7 +537,7 @@ var _ = Describe("ExpiringLicenseService", func() {
536537

537538
Expect(combinedLicense).NotTo(BeNil())
538539
Expect(combinedLicense.GUID).To(Equal(guid))
539-
Expect(combinedLicense.ProductState).To(Equal([]string{"deployed", "staged"}))
540+
Expect(combinedLicense.ProductState).To(Equal([]string{"staged", "deployed"}))
540541
expectedStagedTime, _ := time.Parse("2006-01-02", expiryDate)
541542
Expect(combinedLicense.ExpiresAt).To(Equal(expectedStagedTime))
542543
})

0 commit comments

Comments
 (0)