forked from defenseunicorns/pepr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add cli test to validate multiple manifest generation paths res…
…ult in comparable output (defenseunicorns#1642) ## Description Adds a new `npm run test:int` (int == "integration") script to invoke a new style of test -- integration tests -- where "integration" means something like "wider in scope than unit tests" but "not requiring a full K8s cluster" (general idea is to have a nice place for non-k8s-required tests to land (e.g. client-side `pepr` CLI commands, like init / build). ## Related Issue Fixes defenseunicorns#1654 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [x] Other (security config, docs update, etc) ## Checklist before merging - [x] Unit, [Journey](https://github.com/defenseunicorns/pepr/tree/main/journey), [E2E Tests](https://github.com/defenseunicorns/pepr-excellent-examples), [docs](https://github.com/defenseunicorns/pepr/tree/main/docs), [adr](https://github.com/defenseunicorns/pepr/tree/main/adr) added or updated as needed - [x] [Contributor Guide Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request) followed --------- Co-authored-by: Sam Mayer <[email protected]>
- Loading branch information
1 parent
d4eef2b
commit 3dbf0f2
Showing
24 changed files
with
1,358 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
testroot/ | ||
.npm/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
|
||
import { beforeAll, describe, expect, it } from "@jest/globals"; | ||
import * as path from "node:path"; | ||
import * as fs from "node:fs/promises"; | ||
import { Workdir } from "../helpers/workdir"; | ||
import * as time from "../helpers/time"; | ||
import * as pepr from "../helpers/pepr"; | ||
|
||
const FILE = path.basename(__filename); | ||
const HERE = __dirname; | ||
|
||
describe("build", () => { | ||
const workdir = new Workdir(`${FILE}`, `${HERE}/../testroot/cli`); | ||
|
||
beforeAll(async () => { | ||
await workdir.recreate(); | ||
}); | ||
|
||
describe("builds a module", () => { | ||
const id = FILE.split(".").at(1); | ||
const testModule = `${workdir.path()}/${id}`; | ||
|
||
beforeAll(async () => { | ||
await fs.rm(testModule, { recursive: true, force: true }); | ||
const argz = [ | ||
`--name ${id}`, | ||
`--description ${id}`, | ||
`--errorBehavior reject`, | ||
"--confirm", | ||
"--skip-post-init", | ||
].join(" "); | ||
await pepr.cli(workdir.path(), { cmd: `pepr init ${argz}` }); | ||
await pepr.tgzifyModule(testModule); | ||
await pepr.cli(testModule, { cmd: `npm install` }); | ||
}, time.toMs("2m")); | ||
|
||
describe("using default build options", () => { | ||
it( | ||
"builds", | ||
async () => { | ||
const build = await pepr.cli(testModule, { cmd: `pepr build` }); | ||
expect(build.exitcode).toBe(0); | ||
expect(build.stderr.join("").trim()).toBe(""); | ||
expect(build.stdout.join("").trim()).toContain("K8s resource for the module saved"); | ||
}, | ||
time.toMs("1m"), | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
|
||
import { beforeAll, describe, expect, it } from "@jest/globals"; | ||
import * as path from "node:path"; | ||
import { Workdir } from "../helpers/workdir"; | ||
import * as pepr from "../helpers/pepr"; | ||
import * as time from "../helpers/time"; | ||
|
||
const FILE = path.basename(__filename); | ||
const HERE = __dirname; | ||
|
||
describe("build", () => { | ||
const workdir = new Workdir(`${FILE}`, `${HERE}/../testroot/cli`); | ||
|
||
beforeAll(async () => { | ||
await workdir.recreate(); | ||
}); | ||
|
||
it( | ||
"gives command line help", | ||
async () => { | ||
const argz = "--help"; | ||
const result = await pepr.cli(workdir.path(), { cmd: `pepr build ${argz}` }); | ||
expect(result.exitcode).toBe(0); | ||
expect(result.stderr.join("").trim()).toBe(""); | ||
expect(result.stdout.at(0)).toMatch("Usage: pepr build"); | ||
}, | ||
time.toMs("30s"), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
|
||
import { beforeAll, describe, expect, it } from "@jest/globals"; | ||
import * as path from "node:path"; | ||
import * as fs from "node:fs/promises"; | ||
import { existsSync } from "node:fs"; | ||
import { Workdir } from "../helpers/workdir"; | ||
import * as time from "../helpers/time"; | ||
import * as pepr from "../helpers/pepr"; | ||
import * as resource from "../helpers/resource"; | ||
|
||
const FILE = path.basename(__filename); | ||
const HERE = __dirname; | ||
|
||
describe("build", () => { | ||
const workdir = new Workdir(`${FILE}`, `${HERE}/../testroot/cli`); | ||
|
||
beforeAll(async () => { | ||
await workdir.recreate(); | ||
}); | ||
|
||
describe("builds a module", () => { | ||
const id = FILE.split(".").at(1); | ||
const testModule = `${workdir.path()}/${id}`; | ||
|
||
beforeAll(async () => { | ||
await fs.rm(testModule, { recursive: true, force: true }); | ||
const argz = [ | ||
`--name ${id}`, | ||
`--description ${id}`, | ||
`--errorBehavior reject`, | ||
"--confirm", | ||
"--skip-post-init", | ||
].join(" "); | ||
await pepr.cli(workdir.path(), { cmd: `pepr init ${argz}` }); | ||
await pepr.tgzifyModule(testModule); | ||
await pepr.cli(testModule, { cmd: `npm install` }); | ||
}, time.toMs("2m")); | ||
|
||
describe("for use as a library", () => { | ||
let packageJson; | ||
let uuid: string; | ||
|
||
it( | ||
"builds", | ||
async () => { | ||
const argz = [`--no-embed`].join(" "); | ||
const build = await pepr.cli(testModule, { cmd: `pepr build ${argz}` }); | ||
expect(build.exitcode).toBe(0); | ||
expect(build.stderr.join("").trim()).toContain("Error: Cannot find module"); | ||
expect(build.stdout.join("").trim()).toContain(""); | ||
|
||
packageJson = await resource.fromFile(`${testModule}/package.json`); | ||
uuid = packageJson.pepr.uuid; | ||
}, | ||
time.toMs("1m"), | ||
); | ||
|
||
it( | ||
"outputs appropriate configuration", | ||
async () => { | ||
const missing = [ | ||
`${testModule}/dist/pepr-${uuid}.js`, | ||
`${testModule}/dist/pepr-${uuid}.js.map`, | ||
`${testModule}/dist/pepr-${uuid}.js.LEGAL.txt`, | ||
`${testModule}/dist/pepr-module-${uuid}.yaml`, | ||
`${testModule}/dist/zarf.yaml`, | ||
`${testModule}/dist/${uuid}-chart/`, | ||
]; | ||
for (const path of missing) { | ||
expect(existsSync(path)).toBe(false); | ||
} | ||
|
||
const found = [ | ||
`${testModule}/dist/pepr.js`, | ||
`${testModule}/dist/pepr.js.map`, | ||
`${testModule}/dist/pepr.js.LEGAL.txt`, | ||
]; | ||
for (const path of found) { | ||
expect(existsSync(path)).toBe(true); | ||
} | ||
}, | ||
time.toMs("1m"), | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.