From ac7aece8c82607e0180a98dbb3a5ed5745669113 Mon Sep 17 00:00:00 2001 From: Charles Kenney Date: Wed, 27 May 2020 11:24:54 -0400 Subject: [PATCH] all timestamps should be pointers --- instance_disks.go | 12 ++++-------- test/integration/example_integration_test.go | 6 +++--- test/integration/instance_snapshots_test.go | 2 +- test/integration/instances_test.go | 2 +- test/integration/volumes_test.go | 8 ++++---- volumes.go | 8 ++++---- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/instance_disks.go b/instance_disks.go index 5d8e3cb1c..b7cf54c7a 100644 --- a/instance_disks.go +++ b/instance_disks.go @@ -16,8 +16,8 @@ type InstanceDisk struct { Status DiskStatus `json:"status"` Size int `json:"size"` Filesystem DiskFilesystem `json:"filesystem"` - Created time.Time `json:"-"` - Updated time.Time `json:"-"` + Created *time.Time `json:"-"` + Updated *time.Time `json:"-"` } // DiskFilesystem constants start with Filesystem and include Linode API Filesystems @@ -112,12 +112,8 @@ func (i *InstanceDisk) UnmarshalJSON(b []byte) error { return err } - if p.Created != nil { - i.Created = time.Time(*p.Created) - } - if p.Updated != nil { - i.Updated = time.Time(*p.Updated) - } + i.Created = (*time.Time)(p.Created) + i.Updated = (*time.Time)(p.Updated) return nil } diff --git a/test/integration/example_integration_test.go b/test/integration/example_integration_test.go index a009d26aa..726a49716 100644 --- a/test/integration/example_integration_test.go +++ b/test/integration/example_integration_test.go @@ -104,7 +104,7 @@ func Example() { if errSwap != nil { log.Fatalln("* While creating swap disk:", errSwap) } - eventSwap, errSwapEvent := linodeClient.WaitForEventFinished(context.Background(), linode.ID, linodego.EntityLinode, linodego.ActionDiskCreate, diskSwap.Created, 240) + eventSwap, errSwapEvent := linodeClient.WaitForEventFinished(context.Background(), linode.ID, linodego.EntityLinode, linodego.ActionDiskCreate, *diskSwap.Created, 240) // @TODO it is not sufficient that a disk was created. Which disk was it? // Sounds like we'll need a WaitForEntityStatus function. if errSwapEvent != nil { @@ -118,7 +118,7 @@ func Example() { if errRaw != nil { log.Fatalln("* While creating raw disk:", errRaw) } - eventRaw, errRawEvent := linodeClient.WaitForEventFinished(context.Background(), linode.ID, linodego.EntityLinode, linodego.ActionDiskCreate, diskRaw.Created, 240) + eventRaw, errRawEvent := linodeClient.WaitForEventFinished(context.Background(), linode.ID, linodego.EntityLinode, linodego.ActionDiskCreate, *diskRaw.Created, 240) // @TODO it is not sufficient that a disk was created. Which disk was it? // Sounds like we'll need a WaitForEntityStatus function. if errRawEvent != nil { @@ -142,7 +142,7 @@ func Example() { if errDebian != nil { log.Fatalln("* While creating Debian disk:", errDebian) } - eventDebian, errDebianEvent := linodeClient.WaitForEventFinished(context.Background(), linode.ID, linodego.EntityLinode, linodego.ActionDiskCreate, diskDebian.Created, 240) + eventDebian, errDebianEvent := linodeClient.WaitForEventFinished(context.Background(), linode.ID, linodego.EntityLinode, linodego.ActionDiskCreate, *diskDebian.Created, 240) // @TODO it is not sufficient that a disk was created. Which disk was it? // Sounds like we'll need a WaitForEntityStatus function. if errDebianEvent != nil { diff --git a/test/integration/instance_snapshots_test.go b/test/integration/instance_snapshots_test.go index a8d19e7d2..0c1f0f9ad 100644 --- a/test/integration/instance_snapshots_test.go +++ b/test/integration/instance_snapshots_test.go @@ -81,7 +81,7 @@ func setupInstanceBackup(t *testing.T, fixturesYaml string) (*linodego.Client, * } // wait for disk to finish provisioning - event, err := client.WaitForEventFinished(context.Background(), instance.ID, linodego.EntityLinode, linodego.ActionDiskCreate, disk.Created, 240) + event, err := client.WaitForEventFinished(context.Background(), instance.ID, linodego.EntityLinode, linodego.ActionDiskCreate, *disk.Created, 240) if err != nil { t.Errorf("Error waiting for instance snapshot: %v", err) } diff --git a/test/integration/instances_test.go b/test/integration/instances_test.go index 0d91e6261..c88852e12 100644 --- a/test/integration/instances_test.go +++ b/test/integration/instances_test.go @@ -145,7 +145,7 @@ func TestMultiplePrivateInstanceDisk(t *testing.T) { t.Errorf("Error waiting for instance readiness: %s", err) } - _, err = client.WaitForEventFinished(context.Background(), instance1.ID, linodego.EntityLinode, linodego.ActionDiskImagize, disk.Created, 300) + _, err = client.WaitForEventFinished(context.Background(), instance1.ID, linodego.EntityLinode, linodego.ActionDiskImagize, *disk.Created, 300) if err != nil { t.Errorf("Error waiting for imagize event: %s", err) } diff --git a/test/integration/volumes_test.go b/test/integration/volumes_test.go index 8537f4563..e0ed398bf 100644 --- a/test/integration/volumes_test.go +++ b/test/integration/volumes_test.go @@ -23,8 +23,8 @@ func TestCreateVolume(t *testing.T) { t.Errorf("Expected a volumes id, but got 0") } - assertDateSet(t, &volume.Created) - assertDateSet(t, &volume.Updated) + assertDateSet(t, volume.Created) + assertDateSet(t, volume.Updated) if err := client.DeleteVolume(context.Background(), volume.ID); err != nil { t.Errorf("Expected to delete a volume, but got %v", err) @@ -81,8 +81,8 @@ func TestGetVolume(t *testing.T) { if err != nil { t.Errorf("Error getting volume %d, expected *LinodeVolume, got error %v", volume.ID, err) } - assertDateSet(t, &volume.Created) - assertDateSet(t, &volume.Updated) + assertDateSet(t, volume.Created) + assertDateSet(t, volume.Updated) } func TestWaitForVolumeLinodeID_nil(t *testing.T) { diff --git a/volumes.go b/volumes.go index 03a148ba6..63a940435 100644 --- a/volumes.go +++ b/volumes.go @@ -36,8 +36,8 @@ type Volume struct { LinodeID *int `json:"linode_id"` FilesystemPath string `json:"filesystem_path"` Tags []string `json:"tags"` - Created time.Time `json:"-"` - Updated time.Time `json:"-"` + Created *time.Time `json:"-"` + Updated *time.Time `json:"-"` } // VolumeCreateOptions fields are those accepted by CreateVolume @@ -88,8 +88,8 @@ func (v *Volume) UnmarshalJSON(b []byte) error { return err } - v.Created = time.Time(*p.Created) - v.Updated = time.Time(*p.Updated) + v.Created = (*time.Time)(p.Created) + v.Updated = (*time.Time)(p.Updated) return nil }