Skip to content

Commit

Permalink
fix(images) architecture filtering on image selection needs to deal w…
Browse files Browse the repository at this point in the history
…ith non-aliased architectures, adding test for this

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Apr 29, 2024
1 parent abd176c commit 77f27b3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/util/architectures.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getArchitectureAliases } from "./architectures";

describe("getArchitectureAliases", () => {
it("resolves s390x", () => {
const result = getArchitectureAliases(["s390x"]);

expect(result.length).toBe(1);
expect(result.includes("s390x")).toBe(true);
});

it("resolves amd64", () => {
const result = getArchitectureAliases(["x86_64"]);

expect(result.length).toBe(3);
expect(result.includes("amd64")).toBe(true);
expect(result.includes("generic_64")).toBe(true);
expect(result.includes("x86_64")).toBe(true);
});

it("resolves riscv64", () => {
const result = getArchitectureAliases(["riscv64"]);

expect(result.length).toBe(1);
expect(result.includes("riscv64")).toBe(true);
});

it("resolves unknown architecture", () => {
const result = getArchitectureAliases(["unknown-arch"]);

expect(result.length).toBe(1);
expect(result.includes("unknown-arch")).toBe(true);
});
});
11 changes: 6 additions & 5 deletions src/util/architectures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ const ARCHITECTURE_ALIASES: Record<string, string[]> = {

export const getArchitectureAliases = (names: string[]): string[] => {
const aliases: string[] = [];
const nameKeys = Object.keys(ARCHITECTURE_NAMES);

names.map((value) => {
const key = Object.keys(ARCHITECTURE_NAMES).find(
(key) => ARCHITECTURE_NAMES[key] === value,
);
if (key) {
aliases.push(...ARCHITECTURE_ALIASES[key]);
const nameKey = nameKeys.find((key) => ARCHITECTURE_NAMES[key] === value);
if (nameKey && nameKey in ARCHITECTURE_ALIASES) {
aliases.push(...ARCHITECTURE_ALIASES[nameKey]);
}
aliases.push(value);
});
return aliases;
};

0 comments on commit 77f27b3

Please sign in to comment.