Skip to content

Commit

Permalink
chore(ci): fix and improve e2e test runner
Browse files Browse the repository at this point in the history
This hoists the e2e tests to a separate package, out of the core
package. Additionally I made some improvements to the interface and
the log output in particular.
  • Loading branch information
edvald authored and thsig committed Feb 17, 2022
1 parent 916f9a8 commit 14efb9a
Show file tree
Hide file tree
Showing 28 changed files with 421 additions and 308 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ jobs:
- run:
name: Run e2e test
command: |
cd core
yarn run e2e-project --project=<<parameters.project>> --showlog=true --env=<<parameters.environment>>
yarn e2e-project --project=<<parameters.project>> --showlog=true --env=<<parameters.environment>>
- run:
name: Cleanup
command: kubectl delete --wait=false $(kubectl get ns -o name | grep $CIRCLE_BUILD_NUM) || true
Expand Down
2 changes: 0 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"lodash": "^4.17.20",
"minimist": "^1.2.5",
"mocha": "^8.1.1",
"mocha-logger": "^1.0.6",
"patch-package": "^6.4.7",
"pkg": "4.5.1",
"postinstall-postinstall": "^2.1.0",
Expand All @@ -58,7 +57,6 @@
"build": "tsc --build . --verbose && yarn run add-version-files && yarn run generate-docs",
"check-package-lock": "git diff-index --quiet HEAD -- yarn.lock || (echo 'yarn.lock is dirty!' && exit 1)",
"clean": "shx rm -rf build dist",
"dev": "tsc --build . -w --preserveWatchOutput",
"fix-format": "prettier --write \"{src,test}/**/*.ts\"",
"generate-docs": "node ./build/src/generate-docs.js",
"lint": "tslint -p .",
Expand Down
12 changes: 0 additions & 12 deletions core/.mocharc.e2e.yml

This file was deleted.

3 changes: 0 additions & 3 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@
"is-subset": "^0.1.1",
"md5": "^2.2.1",
"mocha": "^9.2.0",
"mocha-logger": "^1.0.6",
"nock": "^12.0.3",
"node-pre-gyp": "^0.14.0",
"nodetree": "0.0.3",
Expand Down Expand Up @@ -260,8 +259,6 @@
"integ-local": "GARDEN_INTEG_TEST_MODE=local GARDEN_SKIP_TESTS=\"cluster-docker remote-only\" yarn _integ",
"integ-minikube": "GARDEN_INTEG_TEST_MODE=local GARDEN_SKIP_TESTS=\"cluster-docker kaniko remote-only\" yarn _integ",
"integ-remote": "GARDEN_INTEG_TEST_MODE=remote GARDEN_SKIP_TESTS=local-only yarn _integ",
"e2e": "cd test/e2e && ../../../bin/garden test",
"e2e-project": "node build/test/e2e/e2e-project.js",
"test": "mocha"
},
"pkg": {
Expand Down
19 changes: 17 additions & 2 deletions core/src/logger/log-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import logSymbols from "log-symbols"
import nodeEmoji from "node-emoji"
import { cloneDeep, merge, round } from "lodash"

import { LogLevel, LogNode } from "./logger"
import { LogLevel, logLevelMap, LogNode } from "./logger"
import { Omit } from "../util/util"
import { getChildEntries, findParentEntry } from "./util"
import { getChildEntries, findParentEntry, getAllSections } from "./util"
import { GardenError } from "../exceptions"
import { CreateNodeParams, Logger, PlaceholderOpts } from "./logger"
import uniqid from "uniqid"
Expand Down Expand Up @@ -359,6 +359,21 @@ export class LogEntry implements LogNode {
return getChildEntries(this)
}

/**
* Get the log level of the entry as a string.
*/
getStringLevel(): string {
return logLevelMap[this.level]
}

/**
* Get the full list of sections including all parent entries.
*/
getAllSections(): string[] {
const msg = this.getLatestMessage()
return msg ? getAllSections(this, msg) : []
}

/**
* Dumps the log entry and all child entries as a string, optionally filtering the entries with `filter`.
* For example, to dump all the logs of level info or higher:
Expand Down
14 changes: 8 additions & 6 deletions core/src/logger/renderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import hasAnsi = require("has-ansi")
import { LogEntry, LogEntryMessage } from "./log-entry"
import { JsonLogEntry } from "./writers/json-terminal-writer"
import { highlightYaml, PickFromUnion, safeDumpYaml } from "../util/util"
import { printEmoji, formatGardenErrorWithDetail } from "./util"
import { printEmoji, formatGardenErrorWithDetail, getAllSections } from "./util"
import { LoggerType, Logger } from "./logger"

type RenderFn = (entry: LogEntry) => string
Expand Down Expand Up @@ -216,14 +216,16 @@ export function basicRender(entry: LogEntry, logger: Logger): string | null {

// TODO: Include individual message states with timestamp
export function formatForJson(entry: LogEntry): JsonLogEntry {
const { section, data } = entry.getLatestMessage()
const msg = entry.getLatestMessage()
const metadata = entry.getMetadata()
const msg = chainMessages(entry.getMessages() || [])
const messages = chainMessages(entry.getMessages() || [])
return {
msg: cleanForJSON(msg),
data,
msg: cleanForJSON(messages),
data: msg.data,
metadata,
section: cleanForJSON(section),
section: cleanForJSON(msg.section),
timestamp: getTimestamp(entry),
level: entry.getStringLevel(),
allSections: getAllSections(entry, msg).map(cleanForJSON),
}
}
17 changes: 16 additions & 1 deletion core/src/logger/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import chalk, { Chalk } from "chalk"
import CircularJSON from "circular-json"
import { LogLevel } from "./logger"
import { Logger } from "./logger"
import { LogEntry, LogEntryParams, EmojiName } from "./log-entry"
import { LogEntry, LogEntryParams, EmojiName, LogEntryMessage } from "./log-entry"
import { deepMap, deepFilter, safeDumpYaml } from "../util/util"
import { padEnd, isEmpty, isPlainObject } from "lodash"
import { dedent } from "../util/string"
Expand Down Expand Up @@ -63,6 +63,21 @@ export function findParentEntry(entry: LogEntry, predicate: ProcessNode<LogEntry
return predicate(entry) ? entry : entry.parent ? findParentEntry(entry.parent, predicate) : null
}

export function getAllSections(entry: LogEntry, msg: LogEntryMessage) {
const sections: string[] = []
let parent = entry.parent

while (parent) {
const s = parent.getLatestMessage().section
s && sections.push(s)
parent = parent.parent
}

msg.section && sections.push(msg.section)

return sections
}

export function findLogEntry(node: Logger | LogEntry, predicate: ProcessNode<LogEntry>): LogEntry | void {
let found: LogEntry | undefined
traverseChildren<LogEntry>(node, (entry) => {
Expand Down
2 changes: 2 additions & 0 deletions core/src/logger/writers/json-terminal-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface JsonLogEntry {
data?: any
section?: string
metadata?: LogEntryMetadata
level: string
allSections?: string[]
}

export class JsonTerminalWriter extends Writer {
Expand Down
19 changes: 0 additions & 19 deletions core/test/e2e/README.md

This file was deleted.

56 changes: 0 additions & 56 deletions core/test/e2e/garden.yml

This file was deleted.

76 changes: 0 additions & 76 deletions core/test/e2e/src/e2e-helpers.ts

This file was deleted.

13 changes: 2 additions & 11 deletions core/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import td from "testdouble"
import Bluebird = require("bluebird")
import { resolve, join, relative } from "path"
import { extend, intersection, pick } from "lodash"
import { remove, readdirSync, existsSync, copy, mkdirp, pathExists, truncate, ensureDir } from "fs-extra"
import { remove, copy, mkdirp, pathExists, truncate, ensureDir } from "fs-extra"
import execa = require("execa")

import { containerModuleSpecSchema, containerTestSchema, containerTaskSchema } from "../src/plugins/container/config"
Expand All @@ -24,7 +24,7 @@ import {
} from "../src/types/plugin/plugin"
import { Garden, GardenOpts } from "../src/garden"
import { ModuleConfig } from "../src/config/module"
import { mapValues, fromPairs } from "lodash"
import { mapValues } from "lodash"
import { ModuleVersion } from "../src/vcs/vcs"
import { GARDEN_CORE_ROOT, LOCAL_CONFIG_FILENAME, DEFAULT_API_VERSION, gardenEnv } from "../src/constants"
import { LogEntry } from "../src/logger/log-entry"
Expand Down Expand Up @@ -55,7 +55,6 @@ export { TempDirectory, makeTempDir } from "../src/util/fs"
export { TestGarden, TestError, TestEventBus, expectError } from "../src/util/testing"

export const dataDir = resolve(GARDEN_CORE_ROOT, "test", "data")
export const examplesDir = resolve(GARDEN_CORE_ROOT, "..", "examples")
export const testNow = new Date()
export const testModuleVersionString = "v-1234512345"
export const testModuleVersion: ModuleVersion = {
Expand Down Expand Up @@ -440,14 +439,6 @@ export const cleanProject = async (gardenDirPath: string) => {
return remove(gardenDirPath)
}

export function getExampleProjects() {
const names = readdirSync(examplesDir).filter((n) => {
const basePath = join(examplesDir, n)
return existsSync(join(basePath, "garden.yml")) || existsSync(join(basePath, "garden.yaml"))
})
return fromPairs(names.map((n) => [n, join(examplesDir, n)]))
}

export function withDefaultGlobalOpts<T extends object>(opts: T) {
return <ParameterValues<GlobalOptions> & T>extend(
mapValues(globalOptions, (opt) => opt.defaultValue),
Expand Down
6 changes: 6 additions & 0 deletions core/test/unit/src/logger/renderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ describe("renderers", () => {
})
expect(formatForJson(entry)).to.eql({
msg: "hello",
level: "info",
timestamp: now.toISOString(),
section: "c",
allSections: ["c"],
data: { foo: "bar" },
metadata: { task: taskMetadata },
})
Expand All @@ -267,8 +269,10 @@ describe("renderers", () => {
entry.setState({ msg: "world", append: true })
expect(formatForJson(entry)).to.eql({
msg: "hello - world",
level: "info",
timestamp: now.toISOString(),
section: "",
allSections: [],
data: undefined,
metadata: undefined,
})
Expand All @@ -278,7 +282,9 @@ describe("renderers", () => {
const entry = logger.placeholder()
expect(formatForJson(entry)).to.eql({
msg: "",
level: "info",
section: "",
allSections: [],
data: undefined,
metadata: undefined,
timestamp: now.toISOString(),
Expand Down
Loading

0 comments on commit 14efb9a

Please sign in to comment.