github.com/jenkins-x/jx/v2@v2.1.155/pkg/cloud/gke/images_test.go (about)

     1  // +build unit
     2  
     3  package gke
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  var sampleOutput = `[
    13    {
    14      "digest": "sha256:2d36cccfd865cc4e958a5fb4ae6e039669f96c1ada3f6b4e4340c530e517bed1",
    15      "tags": [
    16        "0.0.0-SNAPSHOT-PR-308-3"
    17      ],
    18      "timestamp": {
    19        "datetime": "2019-03-09 21:06:09+00:00",
    20        "day": 9,
    21        "hour": 21,
    22        "microsecond": 0,
    23        "minute": 6,
    24        "month": 3,
    25        "second": 9,
    26        "year": 2019
    27      }
    28    },
    29    {
    30      "digest": "sha256:6e5c2f6591b5843e645d49f920149b0e8a9de387845521e59bec6f113f8dd058",
    31      "tags": [
    32        "0.1.279"
    33      ],
    34      "timestamp": {
    35        "datetime": "2019-03-09 22:34:47+00:00",
    36        "day": 9,
    37        "hour": 22,
    38        "microsecond": 0,
    39        "minute": 34,
    40        "month": 3,
    41        "second": 47,
    42        "year": 2019
    43      }
    44    },
    45    {
    46      "digest": "sha256:1b6cbdf1cac7071936be650d94777039b521cf9ccc0774b383cd79c6ee56f27c",
    47      "tags": [
    48        "0.0.0-SNAPSHOT-PR-293-2"
    49      ],
    50      "timestamp": {
    51        "datetime": "2019-03-09 19:47:37+00:00",
    52        "day": 9,
    53        "hour": 19,
    54        "microsecond": 0,
    55        "minute": 47,
    56        "month": 3,
    57        "second": 37,
    58        "year": 2019
    59      }
    60    },
    61    {
    62      "digest": "sha256:ae45eb93df37b4ac9fe9ebe42af044e89f74c25f0ceac8592885d61df590f730",
    63      "tags": [
    64        "0.0.0-SNAPSHOT-tekton-pipelines-2"
    65      ],
    66      "timestamp": {
    67        "datetime": "2019-03-09 19:33:03+00:00",
    68        "day": 9,
    69        "hour": 19,
    70        "microsecond": 0,
    71        "minute": 33,
    72        "month": 3,
    73        "second": 3,
    74        "year": 2019
    75      }
    76    },
    77    {
    78      "digest": "sha256:aff95ef03f6dc1472a3a79bdae42f9831d1e1b6a64f0a2ffb62d9b91d3913613",
    79      "tags": [
    80        "0.1.278"
    81      ],
    82      "timestamp": {
    83        "datetime": "2019-03-09 22:04:53+00:00",
    84        "day": 9,
    85        "hour": 22,
    86        "microsecond": 0,
    87        "minute": 4,
    88        "month": 3,
    89        "second": 53,
    90        "year": 2019
    91      }
    92    },
    93    {
    94      "digest": "sha256:9863c2227f0106002b94a7d67fe3b6ff809dd72a74877be466208299bb805a97",
    95      "tags": [
    96        "0.0.0-SNAPSHOT-PR-293-1"
    97      ],
    98      "timestamp": {
    99        "datetime": "2019-03-09 15:38:46+00:00",
   100        "day": 9,
   101        "hour": 15,
   102        "microsecond": 0,
   103        "minute": 38,
   104        "month": 3,
   105        "second": 46,
   106        "year": 2019
   107      }
   108    }
   109  ]`
   110  
   111  func TestFindLatestImageTag(t *testing.T) {
   112  	t.Parallel()
   113  
   114  	version, err := FindLatestImageTag(sampleOutput)
   115  	require.NoError(t, err, "finding latest image from input")
   116  
   117  	t.Logf("found latest image version: %s\n", version)
   118  
   119  	assert.Equal(t, "0.1.279", version, "finding latest image version")
   120  
   121  }