github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/ociinstaller/imageref_test.go (about) 1 package ociinstaller 2 3 import ( 4 "testing" 5 ) 6 7 func TestFriendlyImageRef(t *testing.T) { 8 cases := map[string]string{ 9 "hub.steampipe.io/plugins/turbot/aws@latest": "aws", 10 "turbot/aws@latest": "aws", 11 "aws@latest": "aws", 12 "hub.steampipe.io/plugins/turbot/aws@1.0.0": "aws@1.0.0", 13 "hub.steampipe.io/plugins/otherOrg/aws@latest": "otherOrg/aws", 14 "otherOrg/aws@latest": "otherOrg/aws", 15 "hub.steampipe.io/plugins/otherOrg/aws@1.0.0": "otherOrg/aws@1.0.0", 16 "otherOrg/aws@1.0.0": "otherOrg/aws@1.0.0", 17 "differentRegistry.com/otherOrg/aws@latest": "differentRegistry.com/otherOrg/aws@latest", 18 "differentRegistry.com/otherOrg/aws@1.0.0": "differentRegistry.com/otherOrg/aws@1.0.0", 19 } 20 21 for testCase, want := range cases { 22 t.Run(testCase, func(t *testing.T) { 23 r := NewSteampipeImageRef(testCase) 24 25 if got := r.GetFriendlyName(); got != want { 26 t.Errorf("TestFriendlyImageRef failed for case '%s': expected %s, got %s", testCase, want, got) 27 } 28 }) 29 } 30 31 } 32 33 func TestActualImageRef(t *testing.T) { 34 cases := map[string]string{ 35 "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0.0": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0.0", 36 "ghcr.io/turbot/steampipe/plugins/turbot/aws@sha256:766389c9dd892132c7e7b9124f446b9599a80863d466cd1d333a167dedf2c2b1": "ghcr.io/turbot/steampipe/plugins/turbot/aws@sha256:766389c9dd892132c7e7b9124f446b9599a80863d466cd1d333a167dedf2c2b1", 37 "aws": "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest", 38 "aws:1": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1", 39 "turbot/aws:1": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1", 40 "turbot/aws:1.0": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0", 41 "turbot/aws:1.1.1": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.1.1", 42 "turbot/aws": "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest", 43 "mycompany/my-plugin": "ghcr.io/turbot/steampipe/plugins/mycompany/my-plugin:latest", 44 "mycompany/my-plugin:some-random_tag": "ghcr.io/turbot/steampipe/plugins/mycompany/my-plugin:some-random_tag", 45 "dockerhub.org/myimage:mytag": "dockerhub.org/myimage:mytag", 46 "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest": "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest", 47 "hub.steampipe.io/plugins/turbot/aws:latest": "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest", 48 "hub.steampipe.io/plugins/someoneelse/myimage:mytag": "ghcr.io/turbot/steampipe/plugins/someoneelse/myimage:mytag", 49 50 "ghcr.io/turbot/steampipe/plugins/turbot/aws@1.0.0": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0.0", 51 "aws@1": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1", 52 "turbot/aws@1": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1", 53 "turbot/aws@1.0": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0", 54 "turbot/aws@1.1.1": "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.1.1", 55 "mycompany/my-plugin@some-random_tag": "ghcr.io/turbot/steampipe/plugins/mycompany/my-plugin:some-random_tag", 56 "dockerhub.org/myimage@mytag": "dockerhub.org/myimage:mytag", 57 "ghcr.io/turbot/steampipe/plugins/turbot/aws@latest": "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest", 58 "hub.steampipe.io/plugins/turbot/aws@latest": "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest", 59 "hub.steampipe.io/plugins/someoneelse/myimage@mytag": "ghcr.io/turbot/steampipe/plugins/someoneelse/myimage:mytag", 60 } 61 62 for testCase, want := range cases { 63 64 t.Run(testCase, func(t *testing.T) { 65 r := NewSteampipeImageRef(testCase) 66 67 if got := r.ActualImageRef(); got != want { 68 t.Errorf("ActualImageRef failed for case '%s': expected %s, got %s", testCase, want, got) 69 } 70 }) 71 } 72 73 } 74 75 func TestDisplayImageRef(t *testing.T) { 76 cases := map[string]string{ 77 "ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0.0": "hub.steampipe.io/plugins/turbot/aws@1.0.0", 78 "ghcr.io/turbot/steampipe/plugins/turbot/aws@sha256:766389c9dd892132c7e7b9124f446b9599a80863d466cd1d333a167dedf2c2b1": "hub.steampipe.io/plugins/turbot/aws@sha256-766389c9dd892132c7e7b9124f446b9599a80863d466cd1d333a167dedf2c2b1", 79 "aws": "hub.steampipe.io/plugins/turbot/aws@latest", 80 "aws:1": "hub.steampipe.io/plugins/turbot/aws@1", 81 "turbot/aws:1": "hub.steampipe.io/plugins/turbot/aws@1", 82 "turbot/aws:1.0": "hub.steampipe.io/plugins/turbot/aws@1.0", 83 "turbot/aws:1.1.1": "hub.steampipe.io/plugins/turbot/aws@1.1.1", 84 "turbot/aws": "hub.steampipe.io/plugins/turbot/aws@latest", 85 "mycompany/my-plugin": "hub.steampipe.io/plugins/mycompany/my-plugin@latest", 86 "mycompany/my-plugin:some-random_tag": "hub.steampipe.io/plugins/mycompany/my-plugin@some-random_tag", 87 "dockerhub.org/myimage:mytag": "dockerhub.org/myimage@mytag", 88 "ghcr.io/turbot/steampipe/plugins/turbot/aws:latest": "hub.steampipe.io/plugins/turbot/aws@latest", 89 "hub.steampipe.io/plugins/turbot/aws:latest": "hub.steampipe.io/plugins/turbot/aws@latest", 90 "hub.steampipe.io/plugins/someoneelse/myimage:mytag": "hub.steampipe.io/plugins/someoneelse/myimage@mytag", 91 92 "ghcr.io/turbot/steampipe/plugins/turbot/aws@1.0.0": "hub.steampipe.io/plugins/turbot/aws@1.0.0", 93 "aws@1": "hub.steampipe.io/plugins/turbot/aws@1", 94 "turbot/aws@1": "hub.steampipe.io/plugins/turbot/aws@1", 95 "turbot/aws@1.0": "hub.steampipe.io/plugins/turbot/aws@1.0", 96 "turbot/aws@1.1.1": "hub.steampipe.io/plugins/turbot/aws@1.1.1", 97 "mycompany/my-plugin@some-random_tag": "hub.steampipe.io/plugins/mycompany/my-plugin@some-random_tag", 98 "dockerhub.org/myimage@mytag": "dockerhub.org/myimage@mytag", 99 "ghcr.io/turbot/steampipe/plugins/turbot/aws@latest": "hub.steampipe.io/plugins/turbot/aws@latest", 100 "hub.steampipe.io/plugins/turbot/aws@latest": "hub.steampipe.io/plugins/turbot/aws@latest", 101 "hub.steampipe.io/plugins/someoneelse/myimage@mytag": "hub.steampipe.io/plugins/someoneelse/myimage@mytag", 102 103 "aws@v1": "hub.steampipe.io/plugins/turbot/aws@1", 104 "turbot/aws@v1": "hub.steampipe.io/plugins/turbot/aws@1", 105 "turbot/aws@v1.0": "hub.steampipe.io/plugins/turbot/aws@1.0", 106 "turbot/aws@v1.1.1": "hub.steampipe.io/plugins/turbot/aws@1.1.1", 107 } 108 109 for testCase, want := range cases { 110 111 t.Run(testCase, func(t *testing.T) { 112 r := NewSteampipeImageRef(testCase) 113 114 if got := r.DisplayImageRef(); got != want { 115 t.Errorf("DisplayImageRef failed for case '%s': expected %s, got %s", testCase, want, got) 116 } 117 }) 118 } 119 120 } 121 122 func TestGetOrgNameAndConstraint(t *testing.T) { 123 cases := map[string][3]string{ 124 "hub.steampipe.io/plugins/turbot/aws@latest": {"turbot", "aws", "latest"}, 125 "turbot/aws@latest": {"turbot", "aws", "latest"}, 126 "aws@latest": {"turbot", "aws", "latest"}, 127 "hub.steampipe.io/plugins/turbot/aws@1.0.0": {"turbot", "aws", "1.0.0"}, 128 "hub.steampipe.io/plugins/otherOrg/aws@latest": {"otherOrg", "aws", "latest"}, 129 "otherOrg/aws@latest": {"otherOrg", "aws", "latest"}, 130 "hub.steampipe.io/plugins/otherOrg/aws@1.0.0": {"otherOrg", "aws", "1.0.0"}, 131 "otherOrg/aws@1.0.0": {"otherOrg", "aws", "1.0.0"}, 132 "example.com/otherOrg/aws@latest": {"example.com/otherOrg", "aws", "latest"}, 133 "example.com/otherOrg/aws@1.0.0": {"example.com/otherOrg", "aws", "1.0.0"}, 134 } 135 136 for testCase, want := range cases { 137 t.Run(testCase, func(t *testing.T) { 138 r := NewSteampipeImageRef(testCase) 139 org, name, constraint := r.GetOrgNameAndConstraint() 140 got := [3]string{org, name, constraint} 141 if got != want { 142 t.Errorf("TestGetOrgNameAndSuffix failed for case '%s': expected %s, got %s", testCase, want, got) 143 } 144 }) 145 } 146 147 } 148 149 func TestIsFromSteampipeHub(t *testing.T) { 150 cases := map[string]bool{ 151 "hub.steampipe.io/plugins/turbot/aws@latest": true, 152 "turbot/aws@latest": true, 153 "aws@latest": true, 154 "hub.steampipe.io/plugins/turbot/aws@1.0.0": true, 155 "hub.steampipe.io/plugins/otherOrg/aws@latest": true, 156 "otherOrg/aws@latest": true, 157 "hub.steampipe.io/plugins/otherOrg/aws@1.0.0": true, 158 "otherOrg/aws@1.0.0": true, 159 "example.com/otherOrg/aws@latest": false, 160 "example.com/otherOrg/aws@1.0.0": false, 161 } 162 163 for testCase, want := range cases { 164 t.Run(testCase, func(t *testing.T) { 165 r := NewSteampipeImageRef(testCase) 166 got := r.IsFromSteampipeHub() 167 if got != want { 168 t.Errorf("TestIsFromSteampipeHub failed for case '%s': expected %t, got %t", testCase, want, got) 169 } 170 }) 171 } 172 173 }