Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Add workflow to run unit tests for Pepr module
Browse files Browse the repository at this point in the history
Refactor getRepositoryNames() in Pepr module to handle images with digest ref
Add test case to unit tests to validate handling of images with digest
  • Loading branch information
Lucas Rodriguez committed Oct 13, 2023
1 parent 0918ef1 commit d1bc1df
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/test-aws-init-package.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: Test AWS Init Package
on:
push:
branches:
- main
pull_request:
branches:
- main
paths-ignore:
- "**.md"
- "**.jpg"
- "**.png"
- "**.gif"
- "**.svg"
- "adr/**"
- "docs/**"
- "CODEOWNERS"

workflow_dispatch:
inputs:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/test-pepr-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test Pepr Module
on:
pull_request:
paths-ignore:
- "**.md"
- "**.jpg"
- "**.png"
- "**.gif"
- "**.svg"
- "adr/**"
- "docs/**"
- "CODEOWNERS"

permissions:
contents: read

# Abort prior jobs in the same workflow / PR
concurrency:
group: pepr-module-${{ github.ref }}
cancel-in-progress: true

jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

- name: Setup NodeJS
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 18
cache: "npm"
cache-dependency-path: "package-lock.json"

- name: Install Node dependencies
run: npm ci

- name: Run unit tests for Pepr module
run: make test-module
5 changes: 5 additions & 0 deletions capabilities/lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ describe("getRepositoryNames", () => {
input: "registry1.dso.mil/defenseunicorns/zarf/agent:latest",
expected: "defenseunicorns/zarf/agent",
},
{
input:
"defenseunicorns/zarf-game@sha256:f78e442f0f3eb3e9459b5ae6b1a8fda62f8dfe818112e7d130a4e8ae72b3cbff",
expected: "defenseunicorns/zarf-game",
},
];

testCases.forEach(({ input, expected }) => {
Expand Down
4 changes: 3 additions & 1 deletion capabilities/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export function getRepositoryNames(images: string[]): string[] {
}

const repoNames = images.map((image: string) => {
if (image.includes(":")) {
if (image.includes(":") && !image.includes("@sha256")) {
image = image.split(":")[0];
} else if (image.includes("@sha256")) {
image = image.split("@sha256")[0];
}

const firstSlashIndex = image.indexOf("/");
Expand Down

0 comments on commit d1bc1df

Please sign in to comment.