Skip to content

Commit

Permalink
chore(test): perform basic tests on all tested example projects
Browse files Browse the repository at this point in the history
This also makes `--project` a required param, instead of the optional
`--only` flag, which made more sense prior to running the tests via
Garden.
  • Loading branch information
edvald committed Jul 9, 2019
1 parent 3a8a0e0 commit 8c4f86e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 138 deletions.
17 changes: 7 additions & 10 deletions garden-service/test/integ-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as execa from "execa"
import * as Bluebird from "bluebird"
import * as mlog from "mocha-logger"
import { remove } from "fs-extra"
import { get, intersection } from "lodash"
Expand All @@ -14,14 +13,12 @@ import { systemMetadataNamespace } from "../src/plugins/kubernetes/system"

export const parsedArgs = parseArgs(process.argv.slice(2))

export async function removeExampleDotGardenDirs() {
await Bluebird.map(Object.values(getExampleProjects()), async (projectRoot) => {
try {
await remove(resolve(projectRoot, DEFAULT_GARDEN_DIR_NAME))
} catch (error) {
// No .garden directory found in projectRoot, so there's nothing to do here.
}
})
export async function removeExampleDotGardenDir(projectRoot: string) {
try {
await remove(resolve(projectRoot, DEFAULT_GARDEN_DIR_NAME))
} catch (error) {
// No .garden directory found in projectRoot, so there's nothing to do here.
}
}

export async function deleteExampleNamespaces(projectNames?: string[]) {
Expand Down Expand Up @@ -59,7 +56,7 @@ export async function getAllNamespacesKubectl() {

export async function deleteNamespacesKubectl(namespaces: string[]) {
if (namespaces.length > 0) {
await execa("kubectl", ["delete", "ns", ...namespaces])
await execa("kubectl", ["delete", "--wait=false", "ns", ...namespaces])
}
}

Expand Down
2 changes: 1 addition & 1 deletion garden-service/test/integ/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ The `integ-full` script supports the following options:

For example:
```
npm run integ-full -- --binPath=/some/path/garden-bin --only=tasks
npm run integ-full -- --binPath=/some/path/garden-bin --project=tasks
```
14 changes: 7 additions & 7 deletions garden-service/test/integ/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ name: integ-tests
type: exec
tests:
- name: demo-project
command: [npm, run, integ-full, --, --only=demo-project, --showlog=true, --env=testing]
command: [npm, run, integ-full, --, --project=demo-project, --showlog=true, --env=testing]
- name: tasks # Tests for tasks are currently being skipped
command: [npm, run, integ-full, --, --only=tasks, --showlog=true, --env=testing]
command: [npm, run, integ-full, --, --project=tasks, --showlog=true, --env=testing]
- name: hot-reload # Tests for hot-reload are currently being skipped
command: [npm, run, integ-full, --, --only=hot-reload, --showlog=true, --env=testing]
command: [npm, run, integ-full, --, --project=hot-reload, --showlog=true, --env=testing]
- name: project-variables
command: [npm, run, integ-full, --, --only=project-variables, --showlog=true, --env=testing]
command: [npm, run, integ-full, --, --project=project-variables, --showlog=true, --env=testing]
- name: vote-helm
command: [npm, run, integ-full, --, --only=vote-helm, --showlog=true, --env=testing]
command: [npm, run, integ-full, --, --project=vote-helm, --showlog=true, --env=testing]
- name: vote
command: [npm, run, integ-full, --, --only=vote, --showlog=true, --env=testing]
command: [npm, run, integ-full, --, --project=vote, --showlog=true, --env=testing]
- name: remote-sources
command: [npm, run, integ-full, --, --only=remote-sources, --showlog=true, --env=testing]
command: [npm, run, integ-full, --, --project=remote-sources, --showlog=true, --env=testing]
17 changes: 12 additions & 5 deletions garden-service/test/integ/integ-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@ of the one at ${chalk.blue("[garden-root]/bin/garden")}.
${chalk.green("--env")}: The environment to run the test in. \
E.g. ${chalk.blue("local")} or ${chalk.blue("testing")}.
${chalk.green("--only")}: Runs only the test sequence indicated. \
${chalk.green("--project")}: Specify the project to run (required). \
E.g. ${chalk.blue("demo-project")} or ${chalk.blue("vote-helm")}.
Example: ./garden-service/bin/integ-full.ts --binPath=/path/to/garden --only=demo-project
Example: ./garden-service/bin/integ-full.ts --binPath=/path/to/garden --project=demo-project
`

async function run() {
const project = parsedArgs.project

if (!project) {
throw new Error(`Must specify project name with --project parameter`)
}

// Abort if examples dir is dirty to prevent changes being checked out
const projectDir = resolve(examplesDir, project)
try {
await execa("git", ["diff-index", "--quiet", "HEAD", examplesDir])
await execa("git", ["diff-index", "--quiet", "HEAD", projectDir])
} catch (_error) {
throw new InternalError("Examples directory is dirty. Aborting.", {})
throw new InternalError(`${project} example directory is dirty. Aborting.`, {})
}

if (parsedArgs["h"]) {
Expand All @@ -46,7 +53,7 @@ async function run() {

const mochaOpts = ["--opts", "test/mocha.integ.opts"]

for (const opt of ["binPath", "only", "env"]) {
for (const opt of ["binPath", "project", "env"]) {
if (parsedArgs[opt]) {
mochaOpts.push(`--${opt}`, parsedArgs[opt])
}
Expand Down
Loading

0 comments on commit 8c4f86e

Please sign in to comment.