Skip to content

Commit

Permalink
Fix instance dashboard url serialization (#398)
Browse files Browse the repository at this point in the history
* fix instances dashboard url

* add test
  • Loading branch information
georgifarashev authored and dzahariev committed Jan 17, 2020
1 parent dbd9323 commit e64b053
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion storage/postgres/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = Describe("Secured Storage", func() {
mock.ExpectQuery(`SELECT CURRENT_DATABASE()`).WillReturnRows(sqlmock.NewRows([]string{"mock"}).FromCSVString("mock"))
mock.ExpectQuery(`SELECT COUNT(1)*`).WillReturnRows(sqlmock.NewRows([]string{"mock"}).FromCSVString("1"))
mock.ExpectExec("SELECT pg_advisory_lock*").WithArgs(sqlmock.AnyArg()).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectQuery(`SELECT version, dirty FROM "schema_migrations" LIMIT 1`).WillReturnRows(sqlmock.NewRows([]string{"version", "dirty"}).FromCSVString("20200114101000,false"))
mock.ExpectQuery(`SELECT version, dirty FROM "schema_migrations" LIMIT 1`).WillReturnRows(sqlmock.NewRows([]string{"version", "dirty"}).FromCSVString("20200116204800,false"))
mock.ExpectExec("SELECT pg_advisory_unlock*").WithArgs(sqlmock.AnyArg()).WillReturnResult(sqlmock.NewResult(1, 1))
options := storage.DefaultSettings()
options.EncryptionKey = string(envEncryptionKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE service_instances ALTER COLUMN dashboard_url TYPE varchar(16000);

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE service_instances ALTER COLUMN dashboard_url TYPE text;

COMMIT;
8 changes: 5 additions & 3 deletions storage/postgres/service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package postgres

import (
"database/sql"

"github.com/Peripli/service-manager/storage"
sqlxtypes "github.com/jmoiron/sqlx/types"

Expand All @@ -30,7 +32,7 @@ type ServiceInstance struct {
Name string `db:"name"`
ServicePlanID string `db:"service_plan_id"`
PlatformID string `db:"platform_id"`
DashboardURL string `db:"dashboard_url"`
DashboardURL sql.NullString `db:"dashboard_url"`
MaintenanceInfo sqlxtypes.JSONText `db:"maintenance_info"`
Context sqlxtypes.JSONText `db:"context"`
PreviousValues sqlxtypes.JSONText `db:"previous_values"`
Expand All @@ -50,7 +52,7 @@ func (si *ServiceInstance) ToObject() types.Object {
Name: si.Name,
ServicePlanID: si.ServicePlanID,
PlatformID: si.PlatformID,
DashboardURL: si.DashboardURL,
DashboardURL: si.DashboardURL.String,
MaintenanceInfo: getJSONRawMessage(si.MaintenanceInfo),
Context: getJSONRawMessage(si.Context),
PreviousValues: getJSONRawMessage(si.PreviousValues),
Expand All @@ -75,7 +77,7 @@ func (*ServiceInstance) FromObject(object types.Object) (storage.Entity, bool) {
Name: serviceInstance.Name,
ServicePlanID: serviceInstance.ServicePlanID,
PlatformID: serviceInstance.PlatformID,
DashboardURL: serviceInstance.DashboardURL,
DashboardURL: toNullString(serviceInstance.DashboardURL),
MaintenanceInfo: getJSONText(serviceInstance.MaintenanceInfo),
Context: getJSONText(serviceInstance.Context),
PreviousValues: getJSONText(serviceInstance.PreviousValues),
Expand Down
14 changes: 14 additions & 0 deletions test/service_instance_test/service_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package service_test
import (
"context"
"fmt"

"github.com/Peripli/service-manager/test/testutil/service_instance"

"net/http"
Expand Down Expand Up @@ -122,6 +123,19 @@ var _ = test.DescribeTestsFor(test.TestCase{
}
})
})
When("service instance dashboard_url is not set", func() {
BeforeEach(func() {
_, serviceInstance = service_instance.Prepare(ctx, ctx.TestPlatform.ID, "", fmt.Sprintf(`{"%s":"%s"}`, TenantIdentifier, TenantValue))
serviceInstance.DashboardURL = ""
_, err := ctx.SMRepository.Create(context.Background(), serviceInstance)
Expect(err).ToNot(HaveOccurred())
})

It("doesn't return dashboard_url", func() {
ctx.SMWithOAuth.GET(web.ServiceInstancesURL + "/" + serviceInstance.ID).Expect().
Status(http.StatusOK).JSON().Object().NotContainsKey("dashboard_url")
})
})
})
})
},
Expand Down

0 comments on commit e64b053

Please sign in to comment.