From 3038d179ec9e72dfdfdce4ccf678554bd618c6a6 Mon Sep 17 00:00:00 2001 From: Mosen Date: Mon, 18 Jul 2016 16:14:33 +1000 Subject: [PATCH] Add regression test for bundle with size that is too large for int field. Change applications table migration to use bigint field for `bundle_size` --- connect/service.go | 7 ++----- connect/service_test.go | 7 +++++++ migrations/201607110001_applications_up.sql | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/connect/service.go b/connect/service.go index 71df301f..28d2ea6d 100644 --- a/connect/service.go +++ b/connect/service.go @@ -191,7 +191,6 @@ func (svc service) ackInstalledApplicationList(req mdm.Response) error { // TODO: This is a pretty horrible algorithm and I should re-design it at some point. m. removedouter: for _, deviceApp := range deviceApps { - fmt.Printf("Is app removed? %s\n", deviceApp.Name) for _, app := range requestApps { if deviceApp.Version == app.Version && deviceApp.Name == app.Name { deviceNotRemoved = append(deviceNotRemoved, deviceApp) @@ -204,7 +203,7 @@ removedouter: // Any installed applications that are already represented in the `applications` table AND // allocated to the device in `devices_applications` should be skipped. - var updated []apps.Application = make([]apps.Application, len(req.InstalledApplicationList)) + var updated []apps.Application = []apps.Application{} skip: for _, ackApp := range requestApps { for _, app := range deviceNotRemoved { @@ -218,9 +217,7 @@ skip: for _, insertApp := range updated { if err := svc.apps.SaveApplicationByDeviceUUID(device.UUID, &insertApp); err != nil { - fmt.Println(err) - fmt.Printf("could not save application, no valid uuid: %s, %s\n", insertApp.Name, insertApp.UUID) - // return errors.Wrap(err, "saving installed application for a device") + return errors.Wrap(err, "saving installed application for a device") } } diff --git a/connect/service_test.go b/connect/service_test.go index 1fc0718d..eb454a35 100644 --- a/connect/service_test.go +++ b/connect/service_test.go @@ -115,6 +115,10 @@ func TestAckInstalledApplicationList(t *testing.T) { Version: "9.0", BundleSize: 14166172, }, + { + Name: "Bundle Size Regression", + BundleSize: 2463209237, + }, }, } @@ -126,6 +130,8 @@ func TestAckInstalledApplicationList(t *testing.T) { mock.ExpectQuery("INSERT INTO applications").WithArgs("Wireless Network Utility", nil, nil, nil, 2416111, 0, nil).WillReturnRows(wifiAppUuidRow) kcAppUuidRow := sqlmock.NewRows([]string{"application_uuid"}).AddRow("A0000000-1111-2222-3333-444455556666") mock.ExpectQuery("INSERT INTO applications").WithArgs("Keychain Access", "com.apple.keychainaccess", "9.0", "9.0", 14166172, 0, nil).WillReturnRows(kcAppUuidRow) + sizeAppUuidRow := sqlmock.NewRows([]string{"application_uuid"}).AddRow("B0000000-1111-2222-3333-444455556666") + mock.ExpectQuery("INSERT INTO applications").WithArgs("Bundle Size Regression", nil, nil, nil, 2463209237, 0, nil).WillReturnRows(sizeAppUuidRow) // Expect query for device installed apps deviceAppsRow := sqlmock.NewRows([]string{"application_uuid", "name"}).AddRow("APP00000-1111-2222-3333-444455556666", "Mock Application") @@ -133,6 +139,7 @@ func TestAckInstalledApplicationList(t *testing.T) { mock.ExpectExec("INSERT INTO devices_applications").WithArgs("00000000-1111-2222-3333-444455556666", "90000000-1111-2222-3333-444455556666").WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectExec("INSERT INTO devices_applications").WithArgs("00000000-1111-2222-3333-444455556666", "A0000000-1111-2222-3333-444455556666").WillReturnResult(sqlmock.NewResult(1, 1)) + mock.ExpectExec("INSERT INTO devices_applications").WithArgs("00000000-1111-2222-3333-444455556666", "B0000000-1111-2222-3333-444455556666").WillReturnResult(sqlmock.NewResult(1, 1)) svc := NewService(mockDevices, appDs, mockCmd) svc.Acknowledge(ctx, response) diff --git a/migrations/201607110001_applications_up.sql b/migrations/201607110001_applications_up.sql index 00f6f65a..b347bc9c 100644 --- a/migrations/201607110001_applications_up.sql +++ b/migrations/201607110001_applications_up.sql @@ -8,8 +8,8 @@ CREATE TABLE IF NOT EXISTS applications ( identifier text, short_version text, version text, - bundle_size integer, - dynamic_size integer, + bundle_size bigint, + dynamic_size bigint, is_validated bool, install_count integer DEFAULT 1,