Skip to content

Commit

Permalink
Merge pull request #150 from Charliekenney23/safer-date-parsing
Browse files Browse the repository at this point in the history
all timestamps should be pointers
  • Loading branch information
0xch4z committed May 27, 2020
2 parents aade60c + e83cc28 commit fc2aea6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
12 changes: 4 additions & 8 deletions instance_disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/example_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/instance_snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions test/integration/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fc2aea6

Please sign in to comment.