Skip to content

Commit

Permalink
fix(config): ignore empty docs in garden.yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jul 22, 2019
1 parent 4dbdc15 commit d66cf5d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions garden-service/src/config/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export async function loadConfig(projectRoot: string, path: string): Promise<Gar
throw new ConfigurationError(`Could not parse ${basename(absPath)} in directory ${path} as valid YAML`, err)
}

// Ignore empty resources
rawSpecs = rawSpecs.filter(Boolean)

const resources: GardenResource[] = flatten(rawSpecs.map(s => prepareResources(s, path, projectRoot)))

const projectSpecs = resources.filter(s => s.kind === "Project")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
kind: Project
name: foo
---
13 changes: 13 additions & 0 deletions garden-service/test/unit/src/config/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from "chai"
import { loadConfig, findProjectConfig } from "../../../../src/config/base"
import { resolve } from "path"
import { dataDir, expectError, getDataDir } from "../../../helpers"
import { DEFAULT_API_VERSION } from "../../../../src/constants"

const projectPathA = resolve(dataDir, "test-project-a")
const modulePathA = resolve(projectPathA, "module-a")
Expand Down Expand Up @@ -316,6 +317,18 @@ describe("loadConfig", () => {
expect(parsed).to.eql([])
})

it("should ignore empty documents in multi-doc YAML", async () => {
const path = resolve(dataDir, "test-projects", "empty-doc")
const parsed = await loadConfig(path, path)
expect(parsed).to.eql([
{
apiVersion: DEFAULT_API_VERSION,
kind: "Project",
name: "foo",
path,
},
])
})
})

describe("findProjectConfig", async () => {
Expand Down

0 comments on commit d66cf5d

Please sign in to comment.