Skip to content

Commit

Permalink
Add deleted property to image (#172)
Browse files Browse the repository at this point in the history
* Add deleted property to image

Signed-off-by: Lukas Kämmerling <[email protected]>

* Fix ApplyTo

Signed-off-by: Lukas Kämmerling <[email protected]>
  • Loading branch information
LKaemmerling authored Jun 2, 2021
1 parent 7cb8abc commit 469e57d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hcloud/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ type Image struct {
Protection ImageProtection
Deprecated time.Time // The zero value denotes the image is not deprecated.
Labels map[string]string
Deleted time.Time
}

// IsDeprecated returns whether the image is deprecated.
func (image *Image) IsDeprecated() bool {
return !image.Deprecated.IsZero()
}

// IsDeleted returns whether the image is deleted.
func (image *Image) IsDeleted() bool {
return !image.Deleted.IsZero()
}

// ImageProtection represents the protection level of an image.
type ImageProtection struct {
Delete bool
Expand Down
1 change: 1 addition & 0 deletions hcloud/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func ImageFromSchema(s schema.Image) *Image {
Delete: s.Protection.Delete,
},
Deprecated: s.Deprecated,
Deleted: s.Deleted,
}
if s.Name != nil {
i.Name = *s.Name
Expand Down
1 change: 1 addition & 0 deletions hcloud/schema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Image struct {
RapidDeploy bool `json:"rapid_deploy"`
Protection ImageProtection `json:"protection"`
Deprecated time.Time `json:"deprecated"`
Deleted time.Time `json:"deleted"`
Labels map[string]string `json:"labels"`
}

Expand Down
4 changes: 4 additions & 0 deletions hcloud/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ func TestImageFromSchema(t *testing.T) {
"delete": true
},
"deprecated": "2018-02-28T00:00:00+00:00",
"deleted": "2016-01-30T23:55:01+00:00",
"labels": {
"key": "value",
"key2": "value2"
Expand Down Expand Up @@ -961,6 +962,9 @@ func TestImageFromSchema(t *testing.T) {
if !image.Created.Equal(time.Date(2016, 1, 30, 23, 55, 1, 0, time.UTC)) {
t.Errorf("unexpected Created: %v", image.Created)
}
if !image.Deleted.Equal(time.Date(2016, 1, 30, 23, 55, 1, 0, time.UTC)) {
t.Errorf("unexpected Deleted: %v", image.Deleted)
}
if image.CreatedFrom == nil || image.CreatedFrom.ID != 1 || image.CreatedFrom.Name != "my-server1" {
t.Errorf("unexpected CreatedFrom: %v", image.CreatedFrom)
}
Expand Down

0 comments on commit 469e57d

Please sign in to comment.