require "spec_helper"

describe Fog::Brightbox::Compute::ImageSelector do
  subject { Fog::Brightbox::Compute::ImageSelector }

  describe "#latest_ubuntu" do
    it do
      image_list = [
        { "id" => "img-kppxh", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-kppxh", "name" => "ubuntu-xenial-16.04-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:16.04:amd64/20211001/disk1.img, Release: release", "source" => "tmp54tt71pg", "arch" => "x86_64", "created_at" => "2021-10-02T06:57:09.000Z", "owner" => "acc-kg71m", "official" => true, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 394, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-bugr2", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-bugr2", "name" => "ubuntu-xenial-16.04-i386-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:16.04:i386/20211001/disk1.img, Release: release", "source" => "tmplj717rjf", "arch" => "i686", "created_at" => "2021-10-02T06:58:18.000Z", "owner" => "acc-kg71m", "official" => true, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 385, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-6vfpp", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-6vfpp", "name" => "ubuntu-xenial-daily-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:16.04:amd64/20211001/disk1.img, Release: daily", "source" => "tmp3aj5trto", "arch" => "x86_64", "created_at" => "2021-10-02T06:58:57.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 394, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-x08p6", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-x08p6", "name" => "ubuntu-bionic-18.04-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:18.04:amd64/20220523/disk1.img, Release: release", "source" => "tmpcyevpow5", "arch" => "x86_64", "created_at" => "2022-05-24T06:57:15.000Z", "owner" => "acc-kg71m", "official" => true, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 480, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-jrbnn", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-jrbnn", "name" => "ubuntu-bionic-18.04-i386-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:18.04:i386/20220523/disk1.img, Release: release", "source" => "tmpw502837r", "arch" => "i686", "created_at" => "2022-05-24T06:57:44.000Z", "owner" => "acc-kg71m", "official" => true, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 450, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-1cbbg", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-1cbbg", "name" => "ubuntu-focal-daily-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:20.04:amd64/20220530/disk1.img, Release: daily", "source" => "tmpa2iezlb7", "arch" => "x86_64", "created_at" => "2022-06-01T07:06:08.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 685, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-cjc8m", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-cjc8m", "name" => "ubuntu-focal-20.04-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:20.04:amd64/20220530/disk1.img, Release: release", "source" => "tmppadp2ka9", "arch" => "x86_64", "created_at" => "2022-06-02T06:57:21.000Z", "owner" => "acc-kg71m", "official" => true, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 685, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-yes2q", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-yes2q", "name" => "ubuntu-bionic-daily-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:18.04:amd64/20220530/disk1.img, Release: daily", "source" => "tmp7b0ty_cz", "arch" => "x86_64", "created_at" => "2022-06-02T06:59:06.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 480, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-44xv2", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-44xv2", "name" => "ubuntu-bionic-daily-i386-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:18.04:i386/20220530/disk1.img, Release: daily", "source" => "tmpcsk_ejc9", "arch" => "i686", "created_at" => "2022-06-02T06:59:33.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 450, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-axy3r", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-axy3r", "name" => "ubuntu-impish-daily-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:21.10:amd64/20220604/disk1.img, Release: daily", "source" => "tmpq4xcgkhd", "arch" => "x86_64", "created_at" => "2022-06-05T06:57:52.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 699, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-5sf6z", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-5sf6z", "name" => "ubuntu-jammy-daily-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:22.04:amd64/20220604/disk1.img, Release: daily", "source" => "tmp6lwsv5cb", "arch" => "x86_64", "created_at" => "2022-06-05T06:58:33.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 709, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-vuptu", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-vuptu", "name" => "ubuntu-kinetic-daily-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:22.10:amd64/20220605/disk1.img, Release: daily", "source" => "tmpj_k3e6u1", "arch" => "x86_64", "created_at" => "2022-06-06T06:57:58.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 752, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-tqaxd", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-tqaxd", "name" => "ubuntu-impish-21.10-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:21.10:amd64/20220604/disk1.img, Release: release", "source" => "tmp_xphnxch", "arch" => "x86_64", "created_at" => "2022-06-07T06:57:33.000Z", "owner" => "acc-kg71m", "official" => true, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 699, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-7d1e3", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-7d1e3", "name" => "ubuntu-jammy-22.04-amd64-server", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:22.04:amd64/20220604/disk1.img, Release: release", "source" => "tmp11_42l44", "arch" => "x86_64", "created_at" => "2022-06-07T06:58:16.000Z", "owner" => "acc-kg71m", "official" => true, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 709, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-kg2oa", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-kg2oa", "name" => "ubuntu-bionic-18.04-amd64-minimal", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:18.04:amd64/20220607/disk1.img, Release: minimal release", "source" => "tmpd7d5lvyb", "arch" => "x86_64", "created_at" => "2022-06-08T07:01:21.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 258, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-sdofr", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-sdofr", "name" => "ubuntu-focal-20.04-amd64-minimal", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:20.04:amd64/20220607/disk1.img, Release: minimal release", "source" => "tmpl6wvuqu9", "arch" => "x86_64", "created_at" => "2022-06-08T07:01:49.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 330, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-7wwg7", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-7wwg7", "name" => "ubuntu-impish-21.10-amd64-minimal", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:21.10:amd64/20220607/disk1.img, Release: minimal release", "source" => "tmpfkqj3pjo", "arch" => "x86_64", "created_at" => "2022-06-08T07:02:13.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 328, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil },
        { "id" => "img-ielp9", "resource_type" => "image", "url" => "https://api.gb1s.brightbox.com/1.0/images/img-ielp9", "name" => "ubuntu-jammy-22.04-amd64-minimal", "username" => "ubuntu", "status" => "available", "locked" => false, "description" => "ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:22.04:amd64/20220607/disk1.img, Release: minimal release", "source" => "tmpd0ctsx1v", "arch" => "x86_64", "created_at" => "2022-06-08T07:02:38.000Z", "owner" => "acc-yw7i0", "official" => false, "public" => true, "compatibility_mode" => false, "source_type" => "upload", "source_trigger" => "manual", "disk_size" => 353, "virtual_size" => 2252, "min_ram" => nil, "ancestor" => nil }
      ]

      selector = subject.new(image_list)

      assert_equal "img-7d1e3", selector.latest_ubuntu
    end
  end
end
