|
| 1 | +//go:build linux || freebsd |
| 2 | + |
| 3 | +package integration |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "regexp" |
| 8 | + "strings" |
| 9 | + |
| 10 | + "github.com/containers/podman/v5/cmd/podman/registry" |
| 11 | + . "github.com/onsi/ginkgo/v2" |
| 12 | + . "github.com/onsi/gomega" |
| 13 | +) |
| 14 | + |
| 15 | +var _ = Describe("Podman buildx inspect", func() { |
| 16 | + It("podman-remote buildx inspect", func() { |
| 17 | + if !registry.IsRemote() { |
| 18 | + Skip("This test is only applicable for remote podman") |
| 19 | + } |
| 20 | + |
| 21 | + session := podmanTest.PodmanExitCleanly("buildx", "inspect") |
| 22 | + output := session.OutputToString() |
| 23 | + |
| 24 | + infoSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.OS}}/{{.Host.Arch}}") |
| 25 | + expectedNativePlatform := strings.TrimSpace(infoSession.OutputToString()) |
| 26 | + |
| 27 | + Expect(output).To(MatchRegexp(`Platforms:\s+.*\b` + regexp.QuoteMeta(expectedNativePlatform) + `\b`)) |
| 28 | + }) |
| 29 | + |
| 30 | + It("podman-remote buildx inspect --bootstrap", func() { |
| 31 | + if !registry.IsRemote() { |
| 32 | + Skip("This test is only applicable for remote podman") |
| 33 | + } |
| 34 | + |
| 35 | + session := podmanTest.PodmanExitCleanly("buildx", "inspect", "--bootstrap") |
| 36 | + output := session.OutputToString() |
| 37 | + |
| 38 | + infoSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.OS}}/{{.Host.Arch}}") |
| 39 | + expectedNativePlatform := strings.TrimSpace(infoSession.OutputToString()) |
| 40 | + |
| 41 | + Expect(output).To(MatchRegexp(`Platforms:\s+.*\b` + regexp.QuoteMeta(expectedNativePlatform) + `\b`)) |
| 42 | + }) |
| 43 | + |
| 44 | + It("podman buildx inspect", func() { |
| 45 | + if registry.IsRemote() { |
| 46 | + Skip("This test is only applicable for local podman") |
| 47 | + } |
| 48 | + |
| 49 | + session := podmanTest.PodmanExitCleanly("buildx", "inspect") |
| 50 | + stdErr := session.ErrorToString() |
| 51 | + Expect(stdErr).ToNot(MatchRegexp(`(?i)error starting|fail|fatal|panic`), "stderr should not contain critical error keywords, got: %s", stdErr) |
| 52 | + |
| 53 | + buildxOutput := session.OutputToString() |
| 54 | + |
| 55 | + nativeInfoSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.OS}}/{{.Host.Arch}}") |
| 56 | + expectedNativePlatform := strings.TrimSpace(nativeInfoSession.OutputToString()) |
| 57 | + Expect(expectedNativePlatform).ToNot(BeEmpty()) |
| 58 | + |
| 59 | + hostOSSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.OS}}") |
| 60 | + backendHostOS := strings.TrimSpace(hostOSSession.OutputToString()) |
| 61 | + Expect(backendHostOS).ToNot(BeEmpty()) |
| 62 | + |
| 63 | + emulatedArchsNamesSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.EmulatedArchitectures}}") |
| 64 | + emulatedArchsOutputString := strings.TrimSpace(emulatedArchsNamesSession.OutputToString()) |
| 65 | + |
| 66 | + var emulatedArchNames []string |
| 67 | + if strings.HasPrefix(emulatedArchsOutputString, "[") && strings.HasSuffix(emulatedArchsOutputString, "]") { |
| 68 | + content := strings.Trim(emulatedArchsOutputString, "[]") |
| 69 | + if content != "" { |
| 70 | + emulatedArchNames = strings.Fields(content) |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + allExpectedPlatformsSet := make(map[string]bool) |
| 75 | + allExpectedPlatformsSlice := []string{} |
| 76 | + |
| 77 | + if expectedNativePlatform != "" && expectedNativePlatform != "unknown/unknown" { |
| 78 | + allExpectedPlatformsSlice = append(allExpectedPlatformsSlice, expectedNativePlatform) |
| 79 | + allExpectedPlatformsSet[expectedNativePlatform] = true |
| 80 | + } |
| 81 | + |
| 82 | + for _, archName := range emulatedArchNames { |
| 83 | + formattedEmuPlatform := archName |
| 84 | + if !allExpectedPlatformsSet[formattedEmuPlatform] { |
| 85 | + allExpectedPlatformsSlice = append(allExpectedPlatformsSlice, formattedEmuPlatform) |
| 86 | + allExpectedPlatformsSet[formattedEmuPlatform] = true |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + if len(allExpectedPlatformsSlice) == 0 { |
| 91 | + allExpectedPlatformsSlice = append(allExpectedPlatformsSlice, "unknown/unknown") |
| 92 | + } |
| 93 | + |
| 94 | + platformsLineRegex := regexp.MustCompile(`Platforms:\s+(.*)`) |
| 95 | + matches := platformsLineRegex.FindStringSubmatch(buildxOutput) |
| 96 | + Expect(matches).ToNot(BeNil()) |
| 97 | + Expect(len(matches)).To(BeNumerically(">", 1)) |
| 98 | + actualPlatformsListedString := strings.TrimSpace(matches[1]) |
| 99 | + |
| 100 | + for _, expectedPlatform := range allExpectedPlatformsSlice { |
| 101 | + if expectedPlatform == "unknown/unknown" && len(allExpectedPlatformsSlice) > 1 { |
| 102 | + continue |
| 103 | + } |
| 104 | + Expect(actualPlatformsListedString).To(ContainSubstring(expectedPlatform)) |
| 105 | + |
| 106 | + actualPlatformParts := strings.Split(actualPlatformsListedString, ", ") |
| 107 | + var cleanActualListedPlatforms []string |
| 108 | + for _, p := range actualPlatformParts { |
| 109 | + trimmedP := strings.TrimSpace(p) |
| 110 | + if trimmedP != "" { |
| 111 | + cleanActualListedPlatforms = append(cleanActualListedPlatforms, trimmedP) |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + Expect(cleanActualListedPlatforms).To(HaveLen(len(allExpectedPlatformsSlice)), fmt.Sprintf("Number of listed platforms should match. Got: '%s' (%d platforms), Expected: '%v' (%d platforms)", |
| 116 | + actualPlatformsListedString, len(cleanActualListedPlatforms), allExpectedPlatformsSlice, len(allExpectedPlatformsSlice))) |
| 117 | + |
| 118 | + if expectedNativePlatform != "" && expectedNativePlatform != "unknown/unknown" { |
| 119 | + if len(allExpectedPlatformsSlice) == 1 && allExpectedPlatformsSlice[0] == "unknown/unknown" { |
| 120 | + } else { |
| 121 | + Expect(actualPlatformsListedString).NotTo(Equal("unknown/unknown")) |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + }) |
| 126 | + |
| 127 | + It("podman buildx inspect --bootstrap", func() { |
| 128 | + if registry.IsRemote() { |
| 129 | + Skip("This test is only applicable for local podman") |
| 130 | + } |
| 131 | + |
| 132 | + session := podmanTest.PodmanExitCleanly("buildx", "inspect", "--bootstrap") |
| 133 | + stdErr := session.ErrorToString() |
| 134 | + Expect(stdErr).ToNot(MatchRegexp(`(?i)error starting|fail|fatal|panic`), "stderr should not contain critical error keywords, got: %s", stdErr) |
| 135 | + |
| 136 | + buildxOutput := session.OutputToString() |
| 137 | + |
| 138 | + nativeInfoSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.OS}}/{{.Host.Arch}}") |
| 139 | + expectedNativePlatform := strings.TrimSpace(nativeInfoSession.OutputToString()) |
| 140 | + Expect(expectedNativePlatform).ToNot(BeEmpty()) |
| 141 | + |
| 142 | + hostOSSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.OS}}") |
| 143 | + backendHostOS := strings.TrimSpace(hostOSSession.OutputToString()) |
| 144 | + Expect(backendHostOS).ToNot(BeEmpty()) |
| 145 | + |
| 146 | + emulatedArchsNamesSession := podmanTest.PodmanExitCleanly("info", "--format", "{{.Host.EmulatedArchitectures}}") |
| 147 | + emulatedArchsOutputString := strings.TrimSpace(emulatedArchsNamesSession.OutputToString()) |
| 148 | + |
| 149 | + var emulatedArchNames []string |
| 150 | + if strings.HasPrefix(emulatedArchsOutputString, "[") && strings.HasSuffix(emulatedArchsOutputString, "]") { |
| 151 | + content := strings.Trim(emulatedArchsOutputString, "[]") |
| 152 | + if content != "" { |
| 153 | + emulatedArchNames = strings.Fields(content) |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + allExpectedPlatformsSet := make(map[string]bool) |
| 158 | + allExpectedPlatformsSlice := []string{} |
| 159 | + |
| 160 | + if expectedNativePlatform != "" && expectedNativePlatform != "unknown/unknown" { |
| 161 | + allExpectedPlatformsSlice = append(allExpectedPlatformsSlice, expectedNativePlatform) |
| 162 | + allExpectedPlatformsSet[expectedNativePlatform] = true |
| 163 | + } |
| 164 | + |
| 165 | + for _, archName := range emulatedArchNames { |
| 166 | + formattedEmuPlatform := archName |
| 167 | + if !allExpectedPlatformsSet[formattedEmuPlatform] { |
| 168 | + allExpectedPlatformsSlice = append(allExpectedPlatformsSlice, formattedEmuPlatform) |
| 169 | + allExpectedPlatformsSet[formattedEmuPlatform] = true |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + if len(allExpectedPlatformsSlice) == 0 { |
| 174 | + allExpectedPlatformsSlice = append(allExpectedPlatformsSlice, "unknown/unknown") |
| 175 | + } |
| 176 | + |
| 177 | + platformsLineRegex := regexp.MustCompile(`Platforms:\s+(.*)`) |
| 178 | + matches := platformsLineRegex.FindStringSubmatch(buildxOutput) |
| 179 | + Expect(matches).ToNot(BeNil()) |
| 180 | + Expect(len(matches)).To(BeNumerically(">", 1)) |
| 181 | + actualPlatformsListedString := strings.TrimSpace(matches[1]) |
| 182 | + |
| 183 | + for _, expectedPlatform := range allExpectedPlatformsSlice { |
| 184 | + if expectedPlatform == "unknown/unknown" && len(allExpectedPlatformsSlice) > 1 { |
| 185 | + continue |
| 186 | + } |
| 187 | + Expect(actualPlatformsListedString).To(ContainSubstring(expectedPlatform)) |
| 188 | + |
| 189 | + actualPlatformParts := strings.Split(actualPlatformsListedString, ", ") |
| 190 | + var cleanActualListedPlatforms []string |
| 191 | + for _, p := range actualPlatformParts { |
| 192 | + trimmedP := strings.TrimSpace(p) |
| 193 | + if trimmedP != "" { |
| 194 | + cleanActualListedPlatforms = append(cleanActualListedPlatforms, trimmedP) |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + Expect(cleanActualListedPlatforms).To(HaveLen(len(allExpectedPlatformsSlice)), fmt.Sprintf("Number of listed platforms should match. Got: '%s' (%d platforms), Expected: '%v' (%d platforms)", |
| 199 | + actualPlatformsListedString, len(cleanActualListedPlatforms), allExpectedPlatformsSlice, len(allExpectedPlatformsSlice))) |
| 200 | + |
| 201 | + if expectedNativePlatform != "" && expectedNativePlatform != "unknown/unknown" { |
| 202 | + if len(allExpectedPlatformsSlice) == 1 && allExpectedPlatformsSlice[0] == "unknown/unknown" { |
| 203 | + } else { |
| 204 | + Expect(actualPlatformsListedString).NotTo(Equal("unknown/unknown")) |
| 205 | + } |
| 206 | + } |
| 207 | + } |
| 208 | + }) |
| 209 | +}) |
0 commit comments