Skip to content

Commit

Permalink
test: add delay between applying policies and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Oct 24, 2023
1 parent e5eb0f4 commit 8855608
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/src/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe(`All (dir: ${mainDir})`, () => {

it('creates resource (valid) with no warnings when policy defined for namespace', async () => {
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-sample-1.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-2.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-2.yaml`, 500);

const output = await run(`cd "${mainDir}" && kubectl -n default apply -f examples/pod-valid.yaml`);

Expand All @@ -52,7 +52,7 @@ describe(`All (dir: ${mainDir})`, () => {

it('creates resource (misconfigured) with warnings when policy defined for namespace', async () => {
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-sample-2.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-3.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-3.yaml`, 500);

const output = await run(`cd "${mainDir}" && kubectl -n nstest1 apply -f examples/pod-warning.yaml`);

Expand All @@ -66,7 +66,7 @@ describe(`All (dir: ${mainDir})`, () => {

it('creates resource (valid) with no warnings when policy defined globally', async () => {
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-sample-1.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-1.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-1.yaml`, 500);

const output = await run(`cd "${mainDir}" && kubectl -n default apply -f examples/pod-valid.yaml`);

Expand All @@ -77,7 +77,7 @@ describe(`All (dir: ${mainDir})`, () => {

it('creates resource (misconfigured) with warnings when policy defined globally', async () => {
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-sample-1.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-1.yaml`);
await run(`cd "${mainDir}" && kubectl apply -f examples/policy-binding-sample-1.yaml`, 500);

const output = await run(`cd "${mainDir}" && kubectl -n nstest2 apply -f examples/pod-errors.yaml`);

Expand All @@ -93,13 +93,17 @@ describe(`All (dir: ${mainDir})`, () => {
});
});

const run = async (command: string): Promise<string> => {
const run = async (command: string, timeoutMs?: number): Promise<string> => {
return new Promise((resolve, reject) => {
shell.exec(command, {async: true, silent: true}, (code, stdout, stderr) => {
shell.exec(command, {async: true, silent: true}, async (code, stdout, stderr) => {

VERBOSE && console.log('stdout', stdout);
VERBOSE && console.log('stderr', stderr);

if (timeoutMs) {
await sleep(timeoutMs);
}

if (code !== 0) {
reject(stderr);
} else {
Expand Down

0 comments on commit 8855608

Please sign in to comment.