Skip to content

Commit

Permalink
fix: Add logic to parse created field for MongoDatabaseBackup (#258)
Browse files Browse the repository at this point in the history
* Add logic to parse created field for MongoDatabaseBackup

* Wait for update in tests

* Update fixtures
  • Loading branch information
LBGarber authored Jun 9, 2022
1 parent 39546fb commit 67c6105
Show file tree
Hide file tree
Showing 6 changed files with 3,526 additions and 2,202 deletions.
18 changes: 18 additions & 0 deletions mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ type MongoDatabaseBackup struct {
Created *time.Time `json:"-"`
}

func (d *MongoDatabaseBackup) UnmarshalJSON(b []byte) error {
type Mask MongoDatabaseBackup

p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
}{
Mask: (*Mask)(d),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

d.Created = (*time.Time)(p.Created)
return nil
}

// MongoBackupCreateOptions are options used for CreateMongoDatabaseBackup(...)
type MongoBackupCreateOptions struct {
Label string `json:"label"`
Expand Down
17 changes: 17 additions & 0 deletions test/integration/databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integration
import (
"context"
"testing"
"time"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/linode/linodego"
Expand Down Expand Up @@ -88,3 +89,19 @@ func TestDatabase_List(t *testing.T) {
t.Error("database not in database list")
}
}

func waitForDatabaseUpdated(t *testing.T, client *linodego.Client, dbID int,
dbType linodego.DatabaseEngineType, minStart *time.Time) {
_, err := client.WaitForEventFinished(context.Background(), dbID, linodego.EntityDatabase,
linodego.ActionDatabaseUpdate, *minStart, 1200)
if err != nil {
t.Fatalf("failed to wait for database update: %s", err)
}

// Sometimes the event has finished but the status hasn't caught up
err = client.WaitForDatabaseStatus(context.Background(), dbID, dbType,
linodego.DatabaseStatusActive, 120)
if err != nil {
t.Fatalf("failed to wait for database active: %s", err)
}
}
Loading

0 comments on commit 67c6105

Please sign in to comment.