|
17 | 17 | package platforms
|
18 | 18 |
|
19 | 19 | import (
|
| 20 | + "sort" |
20 | 21 | "testing"
|
| 22 | + |
| 23 | + specs "github.com/opencontainers/image-spec/specs-go/v1" |
21 | 24 | )
|
22 | 25 |
|
23 | 26 | // Test the platform compatibility of the different
|
@@ -82,3 +85,75 @@ func Test_PlatformCompat(t *testing.T) {
|
82 | 85 | }
|
83 | 86 | }
|
84 | 87 | }
|
| 88 | + |
| 89 | +func Test_PlatformOrder(t *testing.T) { |
| 90 | + linuxPlatform := specs.Platform{ |
| 91 | + Architecture: "amd64", |
| 92 | + OS: "linux", |
| 93 | + OSVersion: "", |
| 94 | + OSFeatures: nil, |
| 95 | + Variant: "", |
| 96 | + } |
| 97 | + ws2022Platform := specs.Platform{ |
| 98 | + Architecture: "amd64", |
| 99 | + OS: "windows", |
| 100 | + OSVersion: "10.0.20348.3091", |
| 101 | + OSFeatures: nil, |
| 102 | + Variant: "", |
| 103 | + } |
| 104 | + ws2025Platform := specs.Platform{ |
| 105 | + Architecture: "amd64", |
| 106 | + OS: "windows", |
| 107 | + OSVersion: "10.0.26100.2894", |
| 108 | + OSFeatures: nil, |
| 109 | + Variant: "", |
| 110 | + } |
| 111 | + ws2025Rev3000Platform := specs.Platform{ |
| 112 | + Architecture: "amd64", |
| 113 | + OS: "windows", |
| 114 | + OSVersion: "10.0.26100.3000", |
| 115 | + OSFeatures: nil, |
| 116 | + Variant: "", |
| 117 | + } |
| 118 | + |
| 119 | + tt := []struct { |
| 120 | + name string |
| 121 | + hostPlatform specs.Platform |
| 122 | + platforms []specs.Platform |
| 123 | + wantPlatform specs.Platform |
| 124 | + }{ |
| 125 | + { |
| 126 | + name: "Windows Server 2022 should select 2022", |
| 127 | + hostPlatform: ws2022Platform, |
| 128 | + platforms: []specs.Platform{linuxPlatform, ws2022Platform, ws2025Platform}, |
| 129 | + wantPlatform: ws2022Platform, |
| 130 | + }, |
| 131 | + { |
| 132 | + name: "Windows Server 2025 should select 2025", |
| 133 | + hostPlatform: ws2025Platform, |
| 134 | + platforms: []specs.Platform{linuxPlatform, ws2022Platform, ws2025Platform}, |
| 135 | + wantPlatform: ws2025Platform, |
| 136 | + }, |
| 137 | + { |
| 138 | + name: "Windows Server 2025 should select 2025 latest rev", |
| 139 | + hostPlatform: ws2025Platform, |
| 140 | + platforms: []specs.Platform{linuxPlatform, ws2022Platform, ws2025Rev3000Platform}, |
| 141 | + wantPlatform: ws2025Rev3000Platform, |
| 142 | + }, |
| 143 | + } |
| 144 | + |
| 145 | + for _, tc := range tt { |
| 146 | + t.Run(tc.name, func(t *testing.T) { |
| 147 | + comparer := &windowsMatchComparer{Matcher: NewMatcher(tc.hostPlatform)} |
| 148 | + |
| 149 | + sort.SliceStable(tc.platforms, func(i, j int) bool { |
| 150 | + return comparer.Less(tc.platforms[i], tc.platforms[j]) |
| 151 | + }) |
| 152 | + |
| 153 | + if tc.platforms[0].OS != tc.wantPlatform.OS || tc.platforms[0].OSVersion != tc.wantPlatform.OSVersion { |
| 154 | + t.Errorf("Platform mismatch, want %q/%q, got %q/%q", tc.wantPlatform.OS, tc.wantPlatform.OSVersion, tc.platforms[0].OS, tc.platforms[0].OSVersion) |
| 155 | + } |
| 156 | + }) |
| 157 | + } |
| 158 | + |
| 159 | +} |
0 commit comments