Repository: digitalocean/doctl
Pull request #1653 (2025-02-04 15:16:48)

add Created field to images command
In this PR we are adding the field `Created` to doctl images command. This is useful for us to manage our images/snapshots available for the autoscale group. Once this field is available in godo and DO API.

loosla: :wave: Hey Bruno, 
Thanks for an awesome change :rocket: 
Let's fix the integration tests and it should be good to go.

You can run integration tests with 
`doctl$ make test_integration`

The changes like this
![Screenshot from 2025-02-04 14-26-30](https://github.com/user-attachments/assets/091af7f4-a7fa-434b-aca5-d051f370436d)
are needed in the files:
integration/droplet_backups_test.go
integration/droplet_snapshots_test.go
integration/image_create_test.go
integration/image_get_test.go
integration/image_list_application_test.go
integration/image_list_test.go

Feel free to add 
`"created_at": "2020-07-28T16:47:44Z" `in a response in integration/droplet_backups_test.go and integration/droplet_snapshots_test.go. Here is the example.
![Screenshot from 2025-02-04 14-30-13](https://github.com/user-attachments/assets/8fde3109-6642-449d-9030-ed5e2d644bb9)



bramalho: Hello @loosla
I apologize for that, I missed that part from the contributing guidelines.
I don't know if the spacing is correct, but the tests should pass now. Let us know if you have any other improvements
bramalho: no problem, that was fun, when can we expect the next release with this field?
we are working with the new autoscale pools and this is one key element for our automations

Patch:
diff --git a/commands/displayers/image.go b/commands/displayers/image.go
index d1740e1c..781132aa 100644
--- a/commands/displayers/image.go
+++ b/commands/displayers/image.go
@@ -31,14 +31,14 @@ func (gi *Image) JSON(out io.Writer) error {
 
 func (gi *Image) Cols() []string {
 	return []string{
-		"ID", "Name", "Type", "Distribution", "Slug", "Public", "MinDisk",
+		"ID", "Name", "Type", "Distribution", "Slug", "Public", "MinDisk", "Created",
 	}
 }
 
 func (gi *Image) ColMap() map[string]string {
 	return map[string]string{
 		"ID": "ID", "Name": "Name", "Type": "Type", "Distribution": "Distribution",
-		"Slug": "Slug", "Public": "Public", "MinDisk": "Min Disk",
+		"Slug": "Slug", "Public": "Public", "MinDisk": "Min Disk", "Created": "Created",
 	}
 }
 
@@ -53,7 +53,7 @@ func (gi *Image) KV() []map[string]any {
 
 		o := map[string]any{
 			"ID": i.ID, "Name": i.Name, "Type": i.Type, "Distribution": i.Distribution,
-			"Slug": i.Slug, "Public": publicStatus, "MinDisk": i.MinDiskSize,
+			"Slug": i.Slug, "Public": publicStatus, "MinDisk": i.MinDiskSize, "Created": i.Created,
 		}
 
 		out = append(out, o)
diff --git a/commands/images.go b/commands/images.go
index 495ea1dc..b9c7bce2 100644
--- a/commands/images.go
+++ b/commands/images.go
@@ -54,7 +54,7 @@ Currently, there are five types of images: snapshots, backups, custom images, di
 	cmdImagesList := CmdBuilder(cmd, RunImagesList, "list", "List images on your account", `Lists all private images on your account. To list public images, use the `+"`"+`--public`+"`"+` flag. This command returns the following information about each image:`+imageDetail, Writer,
 		aliasOpt("ls"), displayerType(&displayers.Image{}))
 	AddBoolFlag(cmdImagesList, doctl.ArgImagePublic, "", false, "Lists public images")
-	cmdImagesList.Example = `The following example lists all private images on your account and uses the ` + "`" + `--format` + "`" + ` flag to return only the ID, distribution, and slug for each image: doctl compute image list --format ID,Distribution,Slug`
+	cmdImagesList.Example = `The following example lists all private images on your account and uses the ` + "`" + `--format` + "`" + ` flag to return only the ID, distribution, slug and created for each image: doctl compute image list --format ID,Distribution,Slug,Created`
 
 	cmdImagesListDistribution := CmdBuilder(cmd, RunImagesListDistribution,
 		"list-distribution", "List available distribution images", `Lists the distribution images available from DigitalOcean. This command returns the following information about each image:`+imageDetail, Writer,


Test patch:
diff --git a/integration/droplet_backups_test.go b/integration/droplet_backups_test.go
index 3bb08d0b..c447503b 100644
--- a/integration/droplet_backups_test.go
+++ b/integration/droplet_backups_test.go
@@ -68,8 +68,8 @@ var _ = suite("compute/droplet/backups", func(t *testing.T, when spec.G, it spec
 
 const (
 	dropletBackupsOutput = `
-ID      Name     Type        Distribution    Slug      Public    Min Disk
-4444    magic    snapshot    Fedora          slimey    false     25
+ID      Name     Type        Distribution    Slug      Public    Min Disk    Created
+4444    magic    snapshot    Fedora          slimey    false     25          2018-09-20T19:28:00Z
 `
 	dropletBackupsResponse = `
 {"backups": [
@@ -79,7 +79,8 @@ ID      Name     Type        Distribution    Slug      Public    Min Disk
      "distribution": "Fedora",
      "type": "snapshot",
      "slug": "slimey",
-     "min_disk_size": 25
+     "min_disk_size": 25,
+     "created_at": "2018-09-20T19:28:00Z"
     }
   ]
 }`
diff --git a/integration/droplet_snapshots_test.go b/integration/droplet_snapshots_test.go
index 2a3ee2cc..6a7a9226 100644
--- a/integration/droplet_snapshots_test.go
+++ b/integration/droplet_snapshots_test.go
@@ -68,9 +68,9 @@ var _ = suite("compute/droplet/snapshots", func(t *testing.T, when spec.G, it sp
 
 const (
 	dropletSnapshotsOutput = `
-ID      Name           Type        Distribution    Slug      Public    Min Disk
-4444    magic          snapshot    Fedora          slimey    false     25
-2222    other-magic    snapshot    Ubuntu          slimey    false     25
+ID      Name           Type        Distribution    Slug      Public    Min Disk    Created
+4444    magic          snapshot    Fedora          slimey    false     25          2018-09-20T19:28:00Z
+2222    other-magic    snapshot    Ubuntu          slimey    false     25          2018-09-20T19:28:00Z
 `
 	dropletSnapshotsResponse = `
 {"snapshots": [
@@ -80,7 +80,8 @@ ID      Name           Type        Distribution    Slug      Public    Min Disk
     "distribution": "Fedora",
     "type": "snapshot",
     "slug": "slimey",
-    "min_disk_size": 25
+    "min_disk_size": 25,
+    "created_at": "2018-09-20T19:28:00Z"
   },
   {
     "id": 2222,
@@ -88,7 +89,8 @@ ID      Name           Type        Distribution    Slug      Public    Min Disk
     "distribution": "Ubuntu",
     "type": "snapshot",
     "slug": "slimey",
-    "min_disk_size": 25
+    "min_disk_size": 25,
+    "created_at": "2018-09-20T19:28:00Z"
   }
 ]}
 `
diff --git a/integration/image_create_test.go b/integration/image_create_test.go
index 9c8e8583..ec58c765 100644
--- a/integration/image_create_test.go
+++ b/integration/image_create_test.go
@@ -149,6 +149,6 @@ const imageCreateResponse = `{
   }`
 
 const imageCreateOutput = `
-ID          Name                    Type      Distribution    Slug    Public    Min Disk
-38413969    ubuntu-18.04-minimal    custom    Ubuntu                  false     0
+ID          Name                    Type      Distribution    Slug    Public    Min Disk    Created
+38413969    ubuntu-18.04-minimal    custom    Ubuntu                  false     0           2018-09-20T19:28:00Z
 `
diff --git a/integration/image_get_test.go b/integration/image_get_test.go
index 4891d7eb..b4127d48 100644
--- a/integration/image_get_test.go
+++ b/integration/image_get_test.go
@@ -71,8 +71,9 @@ var _ = suite("compute/image/get", func(t *testing.T, when spec.G, it spec.S) {
 
 const (
 	imageGetOutput = `
-ID         Name         Type    Distribution    Slug                Public    Min Disk
-6918990    14.04 x64            Ubuntu          ubuntu-16-04-x64    true      20`
+ID         Name         Type    Distribution    Slug                Public    Min Disk    Created
+6918990    14.04 x64            Ubuntu          ubuntu-16-04-x64    true      20          2014-10-17T20:24:33Z
+`
 	imageGetResponse = `{
   "image": {
     "id": 6918990,
diff --git a/integration/image_list_application_test.go b/integration/image_list_application_test.go
index 089cc791..119f04f3 100644
--- a/integration/image_list_application_test.go
+++ b/integration/image_list_application_test.go
@@ -73,10 +73,10 @@ var _ = suite("compute/image/list-application", func(t *testing.T, when spec.G,
 
 const (
 	imageListApplicationOutput = `
-ID         Name                                        Type    Distribution    Slug             Public    Min Disk
-6376601    Ruby on Rails on 14.04 (Nginx + Unicorn)            Ubuntu          ruby-on-rails    true      20
-6376602    Ruby on Rails on 14.04 (Nginx + Unicorn)            Ubuntu          ruby-on-rails    false     20
-	`
+ID         Name                                        Type    Distribution    Slug             Public    Min Disk    Created
+6376601    Ruby on Rails on 14.04 (Nginx + Unicorn)            Ubuntu          ruby-on-rails    true      20          2014-09-26T20:20:24Z
+6376602    Ruby on Rails on 14.04 (Nginx + Unicorn)            Ubuntu          ruby-on-rails    false     20          2014-09-26T20:20:24Z
+`
 	imageListApplicationResponse = `{
   "images": [
     {
diff --git a/integration/image_list_test.go b/integration/image_list_test.go
index 295e0b7c..4998845a 100644
--- a/integration/image_list_test.go
+++ b/integration/image_list_test.go
@@ -151,12 +151,12 @@ var _ = suite("compute/image/list", func(t *testing.T, when spec.G, it spec.S) {
 
 const (
 	imageListPrivateOutput = `
-ID         Name                                        Type    Distribution    Slug             Public    Min Disk
-6376602    Ruby on Rails on 14.04 (Nginx + Unicorn)            Ubuntu          ruby-on-rails    false     20
-	`
+ID         Name                                        Type    Distribution    Slug             Public    Min Disk    Created
+6376602    Ruby on Rails on 14.04 (Nginx + Unicorn)            Ubuntu          ruby-on-rails    false     20          2014-09-26T20:20:24Z
+`
 	imageListNoticeWithHeader = `
 Notice: Listing private images. Use '--public' to include all images.
-ID    Name    Type    Distribution    Slug    Public    Min Disk
+ID    Name    Type    Distribution    Slug    Public    Min Disk    Created
 `
 	imageListNotice = `
 Notice: Listing private images. Use '--public' to include all images.